/home66/gary/public_html/cloudy/c08_branch/source/input.cpp

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

Generated on Mon Feb 16 12:01:17 2009 for cloudy by  doxygen 1.4.7