00001
00002
00003
00004
00005
00006
00007
00008 #include "cddefines.h"
00009 #include "trace.h"
00010 #include "input.h"
00011
00012 t_input input;
00013
00014
00015
00016
00017
00018 bool lgInputComment( const char *chLine )
00019 {
00020 bool lgReturn;
00021
00022 DEBUG_ENTRY( "lgInputComment()" );
00023
00024
00025 if( chLine[0] == 0 )
00026 TotalInsanity();
00027
00028
00029 if( chLine[0] == '#' || chLine[0] == '*' || chLine[0] == '%' || chLine[0] == ' ' )
00030 {
00031 lgReturn = true;
00032 }
00033 else if( strncmp(chLine,"//", 2 ) == 0 )
00034 {
00035 lgReturn = true;
00036 }
00037
00038 else if( chLine[0] == 'C' || chLine[0] == 'c' )
00039 {
00040
00041
00042
00043
00044 if( chLine[1] == '\n' || chLine[1] == ' ' || chLine[1] == '\r' )
00045 {
00046 lgReturn = true;
00047 }
00048 else
00049 {
00050 lgReturn = false;
00051 }
00052 }
00053 else
00054 {
00055 lgReturn = false;
00056 }
00057
00058
00059 return lgReturn;
00060 }
00061
00062
00063 void t_input::init(void)
00064 {
00065
00066 DEBUG_ENTRY( "t_input::init()" );
00067
00068
00069
00070
00071 if( iReadWay > 0 )
00072 {
00073
00074 nRead = -1;
00075 }
00076 else if( iReadWay < 0 )
00077 {
00078
00079
00080 nReadSv = nRead;
00081
00082
00083 nRead = NKRD;
00084 }
00085
00086 return;
00087 }
00088
00089 void t_input::echo( FILE *ipOUT)
00090 {
00091 char chCard[INPUT_LINE_LENGTH];
00092
00093
00094 init();
00095
00096 bool lgEOF = false;
00097 while( !lgEOF )
00098 {
00099 readarray(chCard,&lgEOF);
00100 if( !lgEOF )
00101 {
00102 char chCAPS[INPUT_LINE_LENGTH];
00103 strcpy( chCAPS , chCard );
00104 caps( chCAPS );
00105
00106 if( !nMatch( "HIDE" , chCAPS ) )
00107 fprintf( ipOUT, "%s\n", chCard );
00108 }
00109 }
00110
00111 }
00112
00113
00114 void t_input::readarray(char *chCard,
00115 bool *lgEOF)
00116 {
00117 long int last;
00118
00119 DEBUG_ENTRY( "t_input::readarray()" );
00120
00121 if( iReadWay > 0 )
00122 {
00123
00124
00125
00126 ++nRead;
00127
00128
00129
00130
00131
00132 if( nRead > nSave )
00133 {
00134 *lgEOF = true;
00135 }
00136 else
00137 {
00138
00139 strcpy( chCard, chCardSav[nRead] );
00140
00141 *lgEOF = false;
00142 }
00143 }
00144 else
00145 {
00146
00147
00148
00149 nRead -= 1;
00150
00151
00152 last = NKRD - nSaveIni;
00153
00154
00155 if( nRead < last )
00156 {
00157
00158 iReadWay = 1;
00159
00160
00161 nRead = nReadSv+1;
00162 }
00163
00164
00165 if( iReadWay == 1 && nRead > nSave )
00166 {
00167 *lgEOF = true;
00168 }
00169 else
00170 {
00171 strcpy( chCard, chCardSav[nRead] );
00172
00173
00174 *lgEOF = false;
00175 }
00176 }
00177
00178
00179
00180 if( trace.lgTrace )
00181 {
00182 fprintf( ioQQQ, "t_input::readarray returns=%s=\n",chCard );
00183 }
00184
00185 return;
00186 }
00187
00189 void input_readvector(const char* chFile,
00190 double vector[],
00191 long n,
00192 bool* lgEOF)
00193 {
00194 DEBUG_ENTRY( "input_readvector()" );
00195
00196 fstream ioDATA;
00197 open_data( ioDATA, chFile, mode_r, AS_LOCAL_ONLY );
00198
00199 for( long i=0; i < n; ++i )
00200 ioDATA >> vector[i];
00201
00202 *lgEOF = !ioDATA.good();
00203 return;
00204 }