/* routine to read in master list of emission line wavelengths and ids, for * generating loc grids, * someday add cdGetNLRLineList */ #include #include "cddefines.h" #include "pressure.h" #include "path.h" #include "cddrive.h" char ** cdGetchLabel ; long int *cdGetnWL; long int cdGetBLRLineList( void ) { long int i , nLines; FILE *ioData ; char chLine[1000] , chFilename[134] ; # ifdef DEBUG_FUN fputs( "<+>cdGetBLRLineList()\n", debug_fp ); # endif /* first check that cdInit has been called, since we may have to write * error output */ if( !lgcdInitCalled ) { fprintf(stderr," cdInit must be called before cdGetchLabel.\n"); exit(1); } if( lgDataPathSet == TRUE ) { /*path set, so look only there */ strcpy( chFilename , chDataPath ); strcat( chFilename , "blrLineList.dat" ); } else { /* path not set, check local space only */ strcpy( chFilename , "blrLineList.dat" ); } if( ( ioData = fopen( chFilename , "r" ) ) == NULL ) { fprintf( ioQQQ, " cdGetBLRLineList could not open Line_List.dat\n" ); if( lgDataPathSet == TRUE ) fprintf( ioQQQ, " even tried path\n" ); if( lgDataPathSet == TRUE ) { fprintf( ioQQQ, " cdGetBLRLineList could not open level1.dat\n"); fprintf( ioQQQ, " path is ==%s==\n",chDataPath ); fprintf( ioQQQ, " final path is ==%s==\n",chFilename ); } puts( "[Stop in cdGetBLRLineList]" ); exit(-1); } /* count how many lines are in the file, ignoring all lines * starting with '#' */ nLines = 0; while( fgets( chLine , sizeof(chLine) , ioData ) != NULL ) { /* we want to count the lines that do not start with # * since these contain data */ if( chLine[0] != '#') ++nLines; } if( (cdGetnWL = ((long *)malloc( (size_t)(nLines+1)*sizeof(long )))) == NULL ) { fprintf(ioQQQ," cdGetBLRLineList could not malloc cdGetnWL\n"); puts( "[Stop in cdGetBLRLineList]" ); exit(1); } /* create 1-d array of string labels */ if( (cdGetchLabel = ((char **)malloc( (size_t)(nLines+1)*sizeof(char *)))) == NULL ) { fprintf(ioQQQ," cdGetBLRLineList could not malloc *cdGetchLabel\n"); puts( "[Stop in cdGetBLRLineList]" ); exit(1); } /* now rewind the file so we can read it a second time*/ if( fseek( ioData , 0 , SEEK_SET ) != 0 ) { fprintf( ioQQQ, " cdGetBLRLineList could not rewind level1.dat.\n"); puts( "[Stop in cdGetBLRLineList]" ); exit(-1); } /* level 1 lines extend from 1 through nLines+1 of this array * the dummy line is in the 0th position */ /* this starts at 1 not 0 since zero is reserved for the * dummy line */ i = 0; while( fgets( chLine , sizeof(chLine) , ioData ) != NULL ) { long iWL; /* skip lines that begin with # */ if( chLine[0] == '#') continue; /* create, get, and save, the line label */ cdGetchLabel[i] = (char*)malloc(5*sizeof(char)); strncpy( cdGetchLabel[i] , chLine , 4); cdGetchLabel[i][4] = 0; /* get and save the wavelength */ sscanf( chLine+4, "%li", &iWL ); cdGetnWL[i] = iWL; ++i; } # ifdef DEBUG_FUN fputs( " <->cdGetBLRLineList()\n", debug_fp ); # endif /* return number of lines we found */ return nLines; }