/*FFmtRead scan input line for free format number */ #include "cddefines.h" #include "ffmtread.h" /******************************************************************** * start of nxtchr, used only by FFmtRead * ********************************************************************/ void nxtchr(char *chr, long int *ichr, long int ipnt, char *chCard, long int last, int *lgEOL) { # ifdef DEBUG_FUN fputs( "<+>nxtchr()\n", debug_fp ); # endif /* read character chCard(IPNT:IPNT), return charac as CHR, octal as ICHR * return lgEOL=.TRUE. if END reached * */ *chr = chCard[ipnt - 1]; *ichr = (*chr); /* * check for end of line, either last as passed to FFmtRead, * or (most likely) the end of line character */ if( ipnt >= last || *chr=='\0' ) { *lgEOL = TRUE; } else { *lgEOL = FALSE; } # ifdef DEBUG_FUN fputs( " <->nxtchr()\n", debug_fp ); # endif return; } /******************************************************************** * start of FFmtRead * ********************************************************************/ double FFmtRead(char *chCard, long int *ipnt, long int last, int *lgEOL) { int lgNFound, lgNumber; char chr; long int ichr, l1, l2; double FFmtRead_v, expn, sign, value; # ifdef DEBUG_FUN fputs( "<+>FFmtRead()\n", debug_fp ); # endif /* FFmtRead= first number encountered after column IPNT in card image */ /* ipnt is pointer to position within array, must be in range 1 to * longest possible line image */ assert(*ipnt > 0 ); assert( *ipnt < 132 ); l1 = '0'; l2 = '9'; L_999: ; lgNumber = FALSE; lgNFound = FALSE; sign = 1.; value = 0.; FFmtRead_v = 0.; /* have we hit the end of line? */ nxtchr(&chr,&ichr,*ipnt,chCard,last,lgEOL); if( *lgEOL ) { # ifdef DEBUG_FUN fputs( " <->FFmtRead()\n", debug_fp ); # endif return( FFmtRead_v ); } /************************************************* * find start of number * *************************************************/ L_4: if( chr == '.' ) goto L_5; if( (ichr >= l1) && (ichr <= l2) ) goto L_1; *ipnt += 1; nxtchr(&chr,&ichr,*ipnt,chCard,last,lgEOL); if( *lgEOL ) { # ifdef DEBUG_FUN fputs( " <->FFmtRead()\n", debug_fp ); # endif return( FFmtRead_v ); } goto L_4; /************************************************* * found start of number, check if neg * *************************************************/ L_1: if( chCard[*ipnt - 2] == '-' ) sign = -1.; lgNFound = TRUE; /************************************************* * find numerical value * *************************************************/ L_6: value = 10.*value + (float)(labs(ichr-l1)); lgNumber = TRUE; L_7: *ipnt += 1; nxtchr(&chr,&ichr,*ipnt,chCard,last,lgEOL); if( *lgEOL ) { FFmtRead_v = value*sign; /* will be encountered on next call */ *lgEOL = FALSE; # ifdef DEBUG_FUN fputs( " <->FFmtRead()\n", debug_fp ); # endif return( FFmtRead_v ); } if( chr == ',' ) goto L_7; if( (ichr >= l1) && (ichr <= l2) ) goto L_6; /***************************************************/ if( chCard[*ipnt - 1] != '.' ) { FFmtRead_v = value*sign; # ifdef DEBUG_FUN fputs( " <->FFmtRead()\n", debug_fp ); # endif return( FFmtRead_v ); } /* decimal point encountered */ L_5: expn = 1.; if( chCard[*ipnt - 2] == '-' ) sign = -1.; /*****************************************************/ L_3: *ipnt += 1; nxtchr(&chr,&ichr,*ipnt,chCard,last,lgEOL); if( chr == ',' ) goto L_3; if( (*lgEOL || ichr < l1) || ichr > l2 ) { /* following fails if no number found (only . on line) */ if( !lgNFound ) goto L_999; FFmtRead_v = value*sign; if( lgNumber ) *lgEOL = FALSE; # ifdef DEBUG_FUN fputs( " <->FFmtRead()\n", debug_fp ); # endif return( FFmtRead_v ); } expn *= 0.1; lgNFound = TRUE; lgNumber = TRUE; value += expn*(float)(ichr-l1); goto L_3; /*****************************************************/ }