int readStdLine(Project* project, char *line, DateTime day1, DateTime day2) // // Input: line = line of data from a standard rainfall data file // day1 = starting day of record of interest // day2 = ending day of record of interest // Output: returns -1 if past end of desired record, 0 if data line could // not be read successfully or 1 if line read successfully // Purpose: reads a line of data from a standard rainfall data file and // writes its data to the rain interface file. // { DateTime date1; DateTime date2; int year, month, day, hour, minute; float x; // --- parse data from input line if (!parseStdLine(project,line, &year, &month, &day, &hour, &minute, &x)) return 0; // --- see if date is within period of record requested date1 = datetime_encodeDate(year, month, day); if ( day1 != NO_DATE && date1 < day1 ) return 0; if ( day2 != NO_DATE && date1 > day2 ) return -1; // --- see if record is out of sequence date2 = date1 + datetime_encodeTime(hour, minute, 0); if ( date2 <= project->PreviousDate ) { report_writeErrorMsg(project,ERR_RAIN_FILE_SEQUENCE, project->Gage[project->GageIndex].fname); //(5.1.010) report_writeLine(project,line); return -1; } project->PreviousDate = date2; switch (project->RainType) { case RAINFALL_INTENSITY: x = x * project->Interval / 3600.0f; break; case CUMULATIVE_RAINFALL: if ( x >= project->RainAccum ) { x = x - project->RainAccum; project->RainAccum += x; } else project->RainAccum = x; break; } x *= (float)project->UnitsFactor; // --- save rainfall to binary interface file saveRainfall(project, date1, hour, minute, x, FALSE); return 1; }
int input_readData() // // Input: none // Output: returns error code // Purpose: reads input file to determine input parameters for each object. // { char line[MAXLINE+1]; // line from input data file char wLine[MAXLINE+1]; // working copy of input line char* comment; // ptr. to start of comment in input line int sect, newsect; // data sections int inperr, errsum; // error code & total error count int lineLength; // number of characters in input line int i; long lineCount = 0; // --- initialize working item count arrays // (final counts in Mobjects, Mnodes & Mlinks should // match those in Nobjects, Nnodes and Nlinks). if ( ErrorCode ) return ErrorCode; error_setInpError(0, ""); for (i = 0; i < MAX_OBJ_TYPES; i++) Mobjects[i] = 0; for (i = 0; i < MAX_NODE_TYPES; i++) Mnodes[i] = 0; for (i = 0; i < MAX_LINK_TYPES; i++) Mlinks[i] = 0; // --- initialize starting date for all time series for ( i = 0; i < Nobjects[TSERIES]; i++ ) { Tseries[i].lastDate = StartDate + StartTime; } // --- read each line from input file sect = 0; errsum = 0; rewind(Finp.file); while ( fgets(line, MAXLINE, Finp.file) != NULL ) { // --- make copy of line and scan for tokens lineCount++; strcpy(wLine, line); Ntokens = getTokens(wLine); // --- skip blank lines and comments if ( Ntokens == 0 ) continue; if ( *Tok[0] == ';' ) continue; // --- check if max. line length exceeded lineLength = strlen(line); if ( lineLength >= MAXLINE ) { // --- don't count comment if present comment = strchr(line, ';'); if ( comment ) lineLength = comment - line; // Pointer math here if ( lineLength >= MAXLINE ) { inperr = ERR_LINE_LENGTH; report_writeInputErrorMsg(inperr, sect, line, lineCount); errsum++; } } // --- check if at start of a new input section if (*Tok[0] == '[') { // --- match token against list of section keywords newsect = findmatch(Tok[0], SectWords); if (newsect >= 0) { // --- SPECIAL CASE FOR TRANSECTS // finish processing the last set of transect data if ( sect == s_TRANSECT ) transect_validate(Nobjects[TRANSECT]-1); // --- begin a new input section sect = newsect; continue; } else { inperr = error_setInpError(ERR_KEYWORD, Tok[0]); report_writeInputErrorMsg(inperr, sect, line, lineCount); errsum++; break; } } // --- otherwise parse tokens from input line else { inperr = parseLine(sect, line); if ( inperr > 0 ) { errsum++; if ( errsum > MAXERRS ) report_writeLine(FMT19); else report_writeInputErrorMsg(inperr, sect, line, lineCount); } } // --- stop if reach end of file or max. error count if (errsum > MAXERRS) break; } /* End of while */ // --- check for errors if (errsum > 0) ErrorCode = ERR_INPUT; return ErrorCode; }