Skip to content

Commit ee7489c

Browse files
committed
Fix to #227
Changes as follows: - Added a message to aux.c.parseInput() when a moldat file is not found in the local directory and is sought in the LAMDA database instead. - Added a sanity check of the first line of the moldat file in tcpsocket.c.openSocket(). This is to trap the situation in which the user has requested a file which is available neither locally nor in LAMDA. What happens in this situation is that a file is created, but it just contains html reporting '404 - file not found'. There may be a more graceful way to trap such cases. - Added a similar check for local moldat files to aux.c.parseInput(). - Added a call to readDummyCollPart() in molinit.c.readMolData() to keep file reading in sync in the case where !(par->collPartIds==NULL || cpFound) (thanks T Lunttila).
1 parent c40e00d commit ee7489c

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This file is part of LIME, the versatile line modeling engine
33
#
44
# Copyright (C) 2006-2014 Christian Brinch
5-
# Copyright (C) 2015-2016 The LIME development team
5+
# Copyright (C) 2015-2017 The LIME development team
66

77
##
88
## Make sure to put the correct paths.

src/aux.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ The parameters visible to the user have now been strictly confined to members of
130130
/* Check if files exist. */
131131
for(id=0;id<par->nSpecies;id++){
132132
if((fp=fopen(par->moldatfile[id], "r"))==NULL) {
133+
sprintf(message, "Moldat file %s not found locally - fetching it from LAMDA", par->moldatfile[id]);
134+
printMessage(message);
133135
openSocket(par->moldatfile[id]);
134136
} else {
137+
checkFirstLineMolDat(fp, par->moldatfile[id]);
135138
fclose(fp);
136139
}
137140
}

src/lime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
#include "dims.h"
4545

46-
#define VERSION "1.7.2"
46+
#define VERSION "1.7.3"
4747
#define DEFAULT_NTHREADS 1
4848
#ifndef NTHREADS /* Value passed from the LIME script */
4949
#define NTHREADS DEFAULT_NTHREADS
@@ -319,6 +319,7 @@ void calcInterpCoeffs_lin(configInfo*, struct grid*);
319319
void calcMolCMBs(configInfo*, molData*);
320320
void calcSourceFn(double, const configInfo*, double*, double*);
321321
void calcTableEntries(const int, const int);
322+
void checkFirstLineMolDat(FILE *fp, char *moldatfile);
322323
void checkGridDensities(configInfo*, struct grid*);
323324
void checkUserDensWeights(configInfo*);
324325
void delaunay(const int, struct grid*, const unsigned long, const _Bool, const _Bool, struct cell**, unsigned long*);

src/molinit.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ double planckfunc(const double freq, const double temp){
5555
return bb;
5656
}
5757

58+
/*....................................................................*/
59+
void
60+
checkFirstLineMolDat(FILE *fp, char *moldatfile){
61+
const int sizeI=200;
62+
char string[sizeI],message[80];
63+
char *expectedLine="!MOLECULE";
64+
65+
fgets(string, sizeI, fp);
66+
67+
if(strncmp(string, expectedLine, strlen(expectedLine))!=0){
68+
if(!silent){
69+
sprintf(message, "Bad format first line of moldat file %s.", moldatfile);
70+
bail_out(message);
71+
}
72+
exit(1);
73+
}
74+
}
75+
5876
/*....................................................................*/
5977
void readMolData(configInfo *par, molData *md, int **allUniqueCollPartIds, int *numCollPartsFound){
6078
/* NOTE! allUniqueCollPartIds is malloc'd in the present function, but not freed. The calling program must free it elsewhere.
@@ -63,7 +81,7 @@ void readMolData(configInfo *par, molData *md, int **allUniqueCollPartIds, int *
6381
double dummy;
6482
_Bool cpFound,previousCpFound;
6583
const int sizeI=200;
66-
char string[sizeI], partstr[90];
84+
char string[sizeI],partstr[90];
6785
FILE *fp;
6886

6987
*allUniqueCollPartIds = malloc(sizeof(**allUniqueCollPartIds)*MAX_N_COLL_PART);
@@ -226,8 +244,9 @@ void readMolData(configInfo *par, molData *md, int **allUniqueCollPartIds, int *
226244
fscanf(fp,"\n");
227245
}
228246
} /* End if(par->lte_only) */
229-
230247
k++;
248+
}else{ /* read and discard to keep the file reading in sync */
249+
readDummyCollPart(fp, sizeI);
231250
} /* End if CP found in par->collPartIds. */
232251
} /* End loop over collision partners this molecule. */
233252
numPartsAcceptedThisMol = k;

src/tcpsocket.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ openSocket(char *moldatfile){
2323
char *get;
2424
char *s,*t;
2525
char buf[2];
26+
char message[80];
2627
char *host = "home.strw.leidenuniv.nl";
2728
char *ip="132.229.214.164";
2829
char *page = "~moldata/datafiles/";
@@ -91,7 +92,10 @@ openSocket(char *moldatfile){
9192

9293
memset(buf, 0, sizeof(buf));
9394
if((fp=fopen(moldatfile, "w"))==NULL) {
94-
if(!silent) bail_out("Failed to write moldata!");
95+
if(!silent){
96+
sprintf(message, "Failed to write moldat file %s.", moldatfile);
97+
bail_out(message);
98+
}
9599
exit(1);
96100
}
97101

@@ -106,4 +110,16 @@ openSocket(char *moldatfile){
106110
free(remote);
107111
close(sock);
108112
fclose(fp);
113+
114+
/* Rough sanity check:
115+
*/
116+
if((fp=fopen(moldatfile, "r"))==NULL) {
117+
if(!silent){
118+
sprintf(message, "Error opening moldat file %s.", moldatfile);
119+
bail_out(message);
120+
}
121+
exit(1);
122+
}
123+
checkFirstLineMolDat(fp, moldatfile);
124+
fclose(fp);
109125
}

0 commit comments

Comments
 (0)