/* (void) pass2(Line *ttl) ; pass2() makes a pass through the data and, for each numeric variable, determines the appropriate type. pass2() assumes vars[].vt is already 'b' for all numeric variables and 's' for all string variables. At the conclusion, vars[i].vt contains: 'b' variable is byte 'i' variable is int 'l' variable is long 'f' variable is float 's' variable is string Copyright (c) 1992 by CRC */ #include "creatdct.h" /* Forward references */ static void p2_update_types() ; static char newtype() ; static char vtype() ; void pass2(ttl) Line *ttl ; { Line line ; (void) getnbline(&line) ; do { p2_update_types(&line) ; } while(getdtaline(&line) != EndOfFile) ; } /* ----------------------------------------------------------------------- */ static void p2_update_types(l) Line *l ; { int i ; int col, endcol ; char c ; double z ; extend_line(l, maxlinelength) ; for (i=0;is[endcol] ; l->s[endcol] = '\0' ; if (sscanf(&(l->s[col]),"%lf",&z)==1) { vars[i].vt = newtype(vars[i].vt,z) ; } l->s[endcol] = c ; } } } static char newtype(oldtype, z) char oldtype ; double z ; { char nt ; if (oldtype==TYPE_FLOAT) return(oldtype) ; nt = vtype(z) ; return(nt>=oldtype ? nt : oldtype) ; } static char vtype(z) double z ; { long longz ; double newz ; if (z>=MIN_LONG && z<=MAX_LONG) { longz = (long) z ; newz = (double) longz ; if (newz==z) { if (z>=MIN_BYTE && z<=MAX_BYTE) return(TYPE_BYTE) ; if (z>=MIN_INT && z<=MAX_INT) return(TYPE_INT) ; return(TYPE_LONG) ; } } return(TYPE_FLOAT) ; }