cloudy trunk
Loading...
Searching...
No Matches
cdgetlinelist.cpp
Go to the documentation of this file.
1/* This file is part of Cloudy and is copyright (C)1978-2013 by Gary J. Ferland and
2 * others. For conditions of distribution and use see copyright notice in license.txt */
3/*cdGetLineList routine to read in master list of emission line wavelengths and ids, for
4 * generating loc grids */
5#include "cddefines.h"
6#include "cddrive.h"
7#include "parser.h"
8
9/* return value is number of lines, -1 if file could not be opened */
10long int cdGetLineList(
11 /* chFile is optional filename, if void then use BLRLineList,
12 * if not void then use file specified */
13 const char chFile[],
14 /* array of null term strings giving line labels */
15 vector<char*>& chLabels,
16 /* a 1-d array of line wavelengths */
17 vector<realnum>& wl)
18{
19 DEBUG_ENTRY( "cdGetLineList()" );
20
21 /* first check that cdInit has been called, since we may have to write
22 * error output */
23 if( !lgcdInitCalled )
24 {
25 fprintf(stderr," cdInit must be called before cdGetLineList.\n");
27 }
28
29 /* use default filename LineList_BLR.dat if void string, else use file specified */
30 const char* chFilename = ( strlen(chFile) == 0 ) ? "LineList_BLR.dat" : chFile;
31
32 /* we will check local space first, then on path if not present */
33 FILE* ioData = open_data( chFilename, "r", AS_LOCAL_DATA_TRY );
34
35 if( ioData == NULL )
36 {
37 /* did not find file, return -1 */
38 return -1;
39 }
40
41 // make sure we are not leaking memory
42 ASSERT( chLabels.size() == 0 && wl.size() == 0 );
43
44 Parser p;
45 char chLine[FILENAME_PATH_LENGTH_2];
46
47 /* actually read and save the lines */
48 while( read_whole_line( chLine, (int)sizeof(chLine), ioData ) != NULL )
49 {
50 if( chLine[0] == '\n' )
51 break;
52
53 /* skip lines that begin with # */
54 if( chLine[0] == '#' )
55 continue;
56
57 p.setline(chLine);
58 char* label = new char[5];
59 realnum wavl;
60 p.getLineID(label, &wavl);
61 chLabels.push_back(label);
62 wl.push_back(wavl);
63 }
64
65 fclose( ioData );
66
67 /* return number of lines we found */
68 return chLabels.size();
69}
const int FILENAME_PATH_LENGTH_2
Definition cddefines.h:249
#define ASSERT(exp)
Definition cddefines.h:578
#define EXIT_FAILURE
Definition cddefines.h:140
#define cdEXIT(FAIL)
Definition cddefines.h:434
float realnum
Definition cddefines.h:103
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
Definition service.cpp:70
#define DEBUG_ENTRY(funcname)
Definition cddefines.h:684
bool lgcdInitCalled
Definition cdinit.cpp:34
long int cdGetLineList(const char chFile[], vector< char * > &chLabels, vector< realnum > &wl)
void setline(const char *const card)
Definition parser.h:69
void getLineID(char *LabelBuf, realnum *wave)
Definition parser.cpp:446
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
Definition cpu.cpp:625
@ AS_LOCAL_DATA_TRY
Definition cpu.h:207