00001 /* This file is part of Cloudy and is copyright (C)1978-2007 by Gary J. Ferland 00002 * For conditions of distribution and use see copyright notice in license.txt */ 00003 /* input_readarray read input commands from array where images are stored * 00004 * returns chCard, which will have <=80 characters before eol * 00005 * line image is up and low case */ 00006 /*input_init initial input_readarray array for storing line images at start of calculation */ 00007 /*lgInputComment - parse comment - check if argument is comment string */ 00008 #include "cddefines.h" 00009 #include "trace.h" 00010 #include "input.h" 00011 00012 /*lgInputComment - parse comment - check if argument is comment string, 00013 * either upper or lower case - 00014 * returns true if line is a comment, false if not 00015 * a comment is any line starting with "C ", *, %, //, or # */ 00016 bool lgInputComment( char *chLine ) 00017 { 00018 bool lgReturn; 00019 00020 DEBUG_ENTRY( "lgInputComment()" ); 00021 00022 /* should not call this routine with null line */ 00023 if( chLine[0] == 0 ) 00024 TotalInsanity(); 00025 00026 /* first case - the special characters that can start a line */ 00027 if( chLine[0] == '#' || chLine[0] == '*' || chLine[0] == '%' || 00028 chLine[0] == ' ' ) 00029 { 00030 lgReturn = true; 00031 } 00032 else if( strncmp(chLine,"//", 2 )==0 ) 00033 { 00034 lgReturn = true; 00035 } 00036 /* second case is line that starts with c */ 00037 else if( chLine[0]=='C' || chLine[0] == 'c' ) 00038 { 00039 /* line starts with C, could be a command or a comment, 00040 * if a comment then line is "C ", but there could be a newline '\n') 00041 * or carriage return (decimal 13) 00042 * in the [1] position 00043 * 13 is carriage return, happens on cygwin gcc */ 00044 if( (chLine[1]=='\n') || (chLine[1]==' ') || chLine[1]==13 ) 00045 { 00046 lgReturn = true; 00047 } 00048 else 00049 { 00050 lgReturn = false; 00051 } 00052 } 00053 else 00054 { 00055 lgReturn = false; 00056 } 00057 /*fprintf(ioQQQ,"DEBUG %c \n", TorF(lgReturn ) );*/ 00058 00059 DEBUG_EXIT( "lgInputComment()" ); 00060 00061 return lgReturn; 00062 } 00063 00064 /*input_init initial input_readarray array for storing line images at start of calculation */ 00065 void input_init(void) 00066 { 00067 00068 DEBUG_ENTRY( "input_init()" ); 00069 00070 /* this sub must be called before calling READAR to get line images 00071 * it simply sets the pointer to set up reading the images 00072 * */ 00073 if( input.iReadWay > 0 ) 00074 { 00075 /* this is usual case, read from the start of array, the commands */ 00076 input.nRead = -1; 00077 } 00078 else if( input.iReadWay < 0 ) 00079 { 00080 /* this is special case where we read from end of array, the ini file */ 00081 /* save the current counter so we can reset it when done */ 00082 input.nReadSv = input.nRead; 00083 00084 /* and set current counter to the bottom of the stack */ 00085 input.nRead = NKRD; 00086 } 00087 00088 DEBUG_EXIT( "input_init()" ); 00089 00090 return; 00091 } 00092 00093 /*input_readarray read input commands from array where images are stored * 00094 * returns chCard, which will have <=80 characters before eol */ 00095 void input_readarray(char *chCard, 00096 bool *lgEOF) 00097 { 00098 long int last; 00099 00100 DEBUG_ENTRY( "input_readarray()" ); 00101 00102 if( input.iReadWay > 0 ) 00103 { 00104 /* usual case, reading commands from start of array 00105 * nRead points to one plus the array element with the next line, it is 00106 * one on the first call, which references line[0] */ 00107 ++input.nRead; 00108 00109 /* nSave points to the last line array element that was saved, 00110 * so it is one less than the number of lines read. the last element 00111 * containing a line image is [input.nSave]. There is a -1 for 00112 * nRead to bring it onto the same c counting scale as nSave */ 00113 if( input.nRead > input.nSave ) 00114 { 00115 *lgEOF = true; 00116 } 00117 else 00118 { 00119 /* get the line image */ 00120 strcpy( chCard, input.chCardSav[input.nRead] ); 00121 00122 /* save copy of the original input card */ 00123 strcpy( input.chOrgCard, chCard ); 00124 00125 /* make copy of line and convert to all caps */ 00126 strcpy( input.chCARDCAPS , chCard ); 00127 caps( input.chCARDCAPS ); 00128 *lgEOF = false; 00129 } 00130 } 00131 else 00132 { 00133 /* this is special case of reading cloudy.ini file, 00134 * nRead was set to 1+last image in input_init, so first time 00135 * we get here it is very large. decrement counter from end of file */ 00136 input.nRead -= 1; 00137 00138 /* last one with real data is NKRD+1-nSaveIni */ 00139 last = NKRD - input.nSaveIni; 00140 00141 /* this read is eof eof */ 00142 if( input.nRead < last ) 00143 { 00144 /* reset counter so we read in the proper direction */ 00145 input.iReadWay = 1; 00146 /* pointer to next line to read. this is on the scale where nRead-1 00147 * is the actual array element */ 00148 input.nRead = input.nReadSv+1; 00149 } 00150 00151 /* check if we hit eof while reading in forward direction */ 00152 if( input.iReadWay == 1 && input.nRead > input.nSave ) 00153 { 00154 *lgEOF = true; 00155 } 00156 else 00157 { 00158 strcpy( chCard, input.chCardSav[input.nRead] ); 00159 00160 /* save copy of the original input card */ 00161 strcpy( input.chOrgCard, chCard ); 00162 00163 /* make copy of line and convert to all caps */ 00164 strcpy( input.chCARDCAPS , chCard ); 00165 caps( input.chCARDCAPS ); 00166 00167 /* did not hit eof */ 00168 *lgEOF = false; 00169 } 00170 } 00171 00172 /* if any "trace" appeared on a command line, then this flag was set 00173 * so print the input command before it is parsed */ 00174 if( trace.lgTraceInput ) 00175 { 00176 fprintf( ioQQQ, "input_readarray returns=%s=\n",chCard ); 00177 } 00178 00179 DEBUG_EXIT( "input_readarray()" ); 00180 00181 return; 00182 } 00183