cloudy  trunk
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
input.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 /* input_readarray read input commands from array where images are stored *
4  * returns chCard, which will have <=80 characters before eol *
5  * line image is up and low case */
6 /*input_init initial input_readarray array for storing line images at start of calculation */
7 /*lgInputComment - parse comment - check if argument is comment string */
8 #include "cddefines.h"
9 #include "trace.h"
10 #include "input.h"
11 
12 /*lgInputComment - parse comment - check if argument is comment string,
13  * either upper or lower case -
14  * returns true if line is a comment, false if not
15  * a comment is any line starting with "C ", *, %, //, or # */
16 bool lgInputComment( const char *chLine )
17 {
18  bool lgReturn;
19 
20  DEBUG_ENTRY( "lgInputComment()" );
21 
22  /* should not call this routine with null line */
23  if( chLine[0] == 0 )
24  TotalInsanity();
25 
26  /* first case - the special characters that can start a line */
27  if( chLine[0] == '#' || chLine[0] == '*' || chLine[0] == '%' || chLine[0] == ' ' )
28  {
29  lgReturn = true;
30  }
31  else if( strncmp(chLine,"//", 2 ) == 0 )
32  {
33  lgReturn = true;
34  }
35  /* second case is line that starts with c */
36  else if( chLine[0] == 'C' || chLine[0] == 'c' )
37  {
38  /* line starts with C, could be a command or a comment,
39  * if a comment then line is "C ", but there could be a newline '\n')
40  * or carriage return '\r' in the [1] position
41  * '\r' is carriage return, happens on cygwin gcc */
42  if( chLine[1] == '\n' || chLine[1] == ' ' || chLine[1] == '\r' )
43  {
44  lgReturn = true;
45  }
46  else
47  {
48  lgReturn = false;
49  }
50  }
51  else
52  {
53  lgReturn = false;
54  }
55  /*fprintf(ioQQQ,"DEBUG %c \n", TorF(lgReturn ) );*/
56 
57  return lgReturn;
58 }
59 
60 /*input_init initial input_readarray array for storing line images at start of calculation */
61 void input_init(void)
62 {
63 
64  DEBUG_ENTRY( "input_init()" );
65 
66  /* this sub must be called before calling READAR to get line images
67  * it simply sets the pointer to set up reading the images
68  * */
69  if( input.iReadWay > 0 )
70  {
71  /* this is usual case, read from the start of array, the commands */
72  input.nRead = -1;
73  }
74  else if( input.iReadWay < 0 )
75  {
76  /* this is special case where we read from end of array, the ini file */
77  /* save the current counter so we can reset it when done */
79 
80  /* and set current counter to the bottom of the stack */
81  input.nRead = NKRD;
82  }
83 
84  return;
85 }
86 
87 /*input_readarray read input commands from array where images are stored *
88  * returns chCard, which will have <=80 characters before eol */
89 void input_readarray(char *chCard,
90  bool *lgEOF)
91 {
92  long int last;
93 
94  DEBUG_ENTRY( "input_readarray()" );
95 
96  if( input.iReadWay > 0 )
97  {
98  /* usual case, reading commands from start of array
99  * nRead points to one plus the array element with the next line, it is
100  * one on the first call, which references line[0] */
101  ++input.nRead;
102 
103  /* nSave points to the last line array element that was saved,
104  * so it is one less than the number of lines read. the last element
105  * containing a line image is [input.nSave]. There is a -1 for
106  * nRead to bring it onto the same c counting scale as nSave */
107  if( input.nRead > input.nSave )
108  {
109  *lgEOF = true;
110  }
111  else
112  {
113  /* get the line image */
114  strcpy( chCard, input.chCardSav[input.nRead] );
115 
116  /* save copy of the original input card */
117  strcpy( input.chOrgCard, chCard );
118 
119  /* make copy of line and convert to all caps */
120  strcpy( input.chCARDCAPS , chCard );
121  caps( input.chCARDCAPS );
122  *lgEOF = false;
123  }
124  }
125  else
126  {
127  /* this is special case of reading cloudy.ini file,
128  * nRead was set to 1+last image in input_init, so first time
129  * we get here it is very large. decrement counter from end of file */
130  input.nRead -= 1;
131 
132  /* last one with real data is NKRD+1-nSaveIni */
133  last = NKRD - input.nSaveIni;
134 
135  /* this read is eof eof */
136  if( input.nRead < last )
137  {
138  /* reset counter so we read in the proper direction */
139  input.iReadWay = 1;
140  /* pointer to next line to read. this is on the scale where nRead-1
141  * is the actual array element */
142  input.nRead = input.nReadSv+1;
143  }
144 
145  /* check if we hit eof while reading in forward direction */
146  if( input.iReadWay == 1 && input.nRead > input.nSave )
147  {
148  *lgEOF = true;
149  }
150  else
151  {
152  strcpy( chCard, input.chCardSav[input.nRead] );
153 
154  /* save copy of the original input card */
155  strcpy( input.chOrgCard, chCard );
156 
157  /* make copy of line and convert to all caps */
158  strcpy( input.chCARDCAPS , chCard );
159  caps( input.chCARDCAPS );
160 
161  /* did not hit eof */
162  *lgEOF = false;
163  }
164  }
165 
166  /* if any "trace" appeared on a command line, then this flag was set
167  * so print the input command before it is parsed */
168  if( trace.lgTrace )
169  {
170  fprintf( ioQQQ, "input_readarray returns=%s=\n",chCard );
171  }
172 
173  return;
174 }

Generated for cloudy by doxygen 1.8.3.1