Skip to content

Commit

Permalink
Fix to #227
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
imckstewart committed May 8, 2017
1 parent c40e00d commit ee7489c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is part of LIME, the versatile line modeling engine
#
# Copyright (C) 2006-2014 Christian Brinch
# Copyright (C) 2015-2016 The LIME development team
# Copyright (C) 2015-2017 The LIME development team

##
## Make sure to put the correct paths.
Expand Down
3 changes: 3 additions & 0 deletions src/aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ The parameters visible to the user have now been strictly confined to members of
/* Check if files exist. */
for(id=0;id<par->nSpecies;id++){
if((fp=fopen(par->moldatfile[id], "r"))==NULL) {
sprintf(message, "Moldat file %s not found locally - fetching it from LAMDA", par->moldatfile[id]);
printMessage(message);
openSocket(par->moldatfile[id]);
} else {
checkFirstLineMolDat(fp, par->moldatfile[id]);
fclose(fp);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/lime.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#include "dims.h"

#define VERSION "1.7.2"
#define VERSION "1.7.3"
#define DEFAULT_NTHREADS 1
#ifndef NTHREADS /* Value passed from the LIME script */
#define NTHREADS DEFAULT_NTHREADS
Expand Down Expand Up @@ -319,6 +319,7 @@ void calcInterpCoeffs_lin(configInfo*, struct grid*);
void calcMolCMBs(configInfo*, molData*);
void calcSourceFn(double, const configInfo*, double*, double*);
void calcTableEntries(const int, const int);
void checkFirstLineMolDat(FILE *fp, char *moldatfile);
void checkGridDensities(configInfo*, struct grid*);
void checkUserDensWeights(configInfo*);
void delaunay(const int, struct grid*, const unsigned long, const _Bool, const _Bool, struct cell**, unsigned long*);
Expand Down
23 changes: 21 additions & 2 deletions src/molinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ double planckfunc(const double freq, const double temp){
return bb;
}

/*....................................................................*/
void
checkFirstLineMolDat(FILE *fp, char *moldatfile){
const int sizeI=200;
char string[sizeI],message[80];
char *expectedLine="!MOLECULE";

fgets(string, sizeI, fp);

if(strncmp(string, expectedLine, strlen(expectedLine))!=0){
if(!silent){
sprintf(message, "Bad format first line of moldat file %s.", moldatfile);
bail_out(message);
}
exit(1);
}
}

/*....................................................................*/
void readMolData(configInfo *par, molData *md, int **allUniqueCollPartIds, int *numCollPartsFound){
/* NOTE! allUniqueCollPartIds is malloc'd in the present function, but not freed. The calling program must free it elsewhere.
Expand All @@ -63,7 +81,7 @@ void readMolData(configInfo *par, molData *md, int **allUniqueCollPartIds, int *
double dummy;
_Bool cpFound,previousCpFound;
const int sizeI=200;
char string[sizeI], partstr[90];
char string[sizeI],partstr[90];
FILE *fp;

*allUniqueCollPartIds = malloc(sizeof(**allUniqueCollPartIds)*MAX_N_COLL_PART);
Expand Down Expand Up @@ -226,8 +244,9 @@ void readMolData(configInfo *par, molData *md, int **allUniqueCollPartIds, int *
fscanf(fp,"\n");
}
} /* End if(par->lte_only) */

k++;
}else{ /* read and discard to keep the file reading in sync */
readDummyCollPart(fp, sizeI);
} /* End if CP found in par->collPartIds. */
} /* End loop over collision partners this molecule. */
numPartsAcceptedThisMol = k;
Expand Down
18 changes: 17 additions & 1 deletion src/tcpsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ openSocket(char *moldatfile){
char *get;
char *s,*t;
char buf[2];
char message[80];
char *host = "home.strw.leidenuniv.nl";
char *ip="132.229.214.164";
char *page = "~moldata/datafiles/";
Expand Down Expand Up @@ -91,7 +92,10 @@ openSocket(char *moldatfile){

memset(buf, 0, sizeof(buf));
if((fp=fopen(moldatfile, "w"))==NULL) {
if(!silent) bail_out("Failed to write moldata!");
if(!silent){
sprintf(message, "Failed to write moldat file %s.", moldatfile);
bail_out(message);
}
exit(1);
}

Expand All @@ -106,4 +110,16 @@ openSocket(char *moldatfile){
free(remote);
close(sock);
fclose(fp);

/* Rough sanity check:
*/
if((fp=fopen(moldatfile, "r"))==NULL) {
if(!silent){
sprintf(message, "Error opening moldat file %s.", moldatfile);
bail_out(message);
}
exit(1);
}
checkFirstLineMolDat(fp, moldatfile);
fclose(fp);
}

0 comments on commit ee7489c

Please sign in to comment.