head 2.9; access ; symbols ; locks ; strict; comment @ * @; 2.9 date 98.08.24.13.45.52; author bobh; state Exp; branches ; next 2.8; 2.8 date 98.03.17.11.11.38; author bobh; state Exp; branches ; next 2.7; 2.7 date 97.09.09.09.52.45; author bobh; state Exp; branches ; next 2.6; 2.6 date 96.05.30.15.07.55; author bobh; state Exp; branches ; next 2.5; 2.5 date 94.12.15.10.59.38; author hebo; state Exp; branches ; next 2.4; 2.4 date 94.01.21.14.36.15; author hebo; state Exp; branches ; next 2.1; 2.1 date 94.01.17.11.07.40; author hebo; state Exp; branches ; next 2.0; 2.0 date 92.08.31.15.35.51; author hebo; state Exp; branches ; next 1.2; 1.2 date 92.05.12.18.19.29; author hebo; state Exp; branches ; next 1.1; 1.1 date 92.03.16.15.42.31; author hebo; state Rel; branches ; next 1.0; 1.0 date 92.02.25.10.46.59; author hebo; state Rel; branches ; next ; desc @File handling routines for extract.c @ 2.9 log @Archiving sources after M2/M3 & Eqpac deployments of 1998 @ text @/****************************************************************************/ /* Copyright 1991-1997 MBARI */ /****************************************************************************/ /* $Header: file.c,v 2.8 98/03/17 11:11:38 bobh Exp $ */ /* Summary : File Handling Routines for `extract` */ /* Filename : file.c */ /* Author : Robert Herlien (rah) */ /* Project : OASIS Mooring */ /* $Revision: 2.8 $ */ /* Created : 02/05/91 */ /****************************************************************************/ /* Modification History: */ /* 05feb92 rah - created */ /* $Log: file.c,v $ * Revision 2.8 98/03/17 11:11:38 11:11:38 bobh (Bob Herlien) * Archiving sources prior to porting to DOS/Windows * * Revision 2.7 97/09/09 09:52:45 09:52:45 bobh (Bob Herlien) * Archiving various changes * * Revision 2.6 96/05/30 15:07:55 15:07:55 bobh (Bob Herlien) * Update for version in use during 1995-6 deployment * * Revision 2.5 94/12/15 10:59:38 10:59:38 hebo (Bob Herlien) * Accumulated minor changes, mainly due to move to tsunami * * Revision 2.4 94/01/21 14:36:15 14:36:15 hebo (Bob Herlien) * Added support for date ranges in cfg file * * Revision 2.1 94/01/17 11:07:40 11:07:40 hebo (Bob Herlien) * Misc changes * * Revision 2.0 92/08/31 15:35:51 15:35:51 hebo (Bob Herlien) * Auguest 1992 Deployment. Changed to allow multiple sensors of same type. * * Revision 1.2 92/05/12 18:19:29 18:19:29 hebo (Bob Herlien) * Added spectroradiometer decoding (spec.c) * * Revision 1.1 92/03/16 15:42:31 15:42:31 hebo (Bob Herlien) * Ignore leading blanks on "begin" line * * Revision 1.0 92/02/25 10:46:59 10:46:59 hebo (Bob Herlien) * Initial revision */ /****************************************************************************/ #include /* Standard I/O */ #include /* MBARI type definitions */ #include /* MBARI constants */ #include /* OASIS controller definitions */ #include /* Time */ #include /* for isspace() */ #include /* for strcmp() */ #include /* variable argument lists */ #include /* memory allocation */ #define LINEBUFSIZE 512 /* Size of line buffer */ #define BNAMESIZE 128 /* Size of file base name */ #define NAMESIZE 256 /* Space allocated for file names */ #define BASE_DIR "/oasis/" #define CFG_DIR "/oasis/cfg" #define HDR_DIR "/oasis/cfg" #define OASIS_CHAN 2 /* Analog chan num for OASIS stuff */ #define DEC(c) (((c) - ' ') & 0x3f) /* uudecode macro */ typedef struct /************************************/ { /* FilePtr struct - File Ptr and name*/ FILE *fp; /* File pointer */ Int ftime; /* Time that name of file represents*/ /* as in yyddd (year, julday) */ char *fname; /* File base name */ } FilePtr; /************************************/ typedef struct /************************************/ { /* CalStruct - Funcs to read cal files*/ char *cs_name; /* Keyword in cfg file */ Status (*cs_func)(); /* Function to read cal file */ Void *cs_parm; /* Ptr parm to pass to cs_func */ MBool cs_got_dated_cal; /* Boolean - parsed a dated cal line*/ } CalStruct; /************************************/ /********************************/ /* External Functions */ /********************************/ Extern Status read_atlas_cal( char *name, AtlasCal *cp ); Extern Status read_ctd_cal( char *name, CTDCal *ccp ); Extern Status read_no3_cal( char *name, No3Cal *no3cp ); Extern Status read_spec_cal( char *name, SpecCal *scp ); Extern Status read_satlantic_cal( char *name, SatlanticCal *scp ); /********************************/ /* External Data */ /********************************/ Extern Int itime; /* Integer year/day as yyddd */ /********************************/ /* Forward Declarations */ /********************************/ Status store_dirname( char *name, char *where ); Status store_fname( char *name, char **where ); Status analog_cal( char *parm, Analog *cp, char *tail ); Status setInt( char *value, Int *where ); Status read_gf_cal( char *name, GndFltCal *gfp ); /********************************/ /* Global Data */ /********************************/ Global char can_name[BNAMESIZE]; /* Name of OASIS can */ Global AtlasCal atlas_cal; /* ATLAS calibration */ Global Analog analog[ANALOG_CHANS]; /* Analog calibration */ Global CTDCal ctd_cal[NUM_CTDS]; /* Structs to hold CTD calibrations */ Global No3Cal no3_cal[NUM_NO3S]; /* Structs to hold NO3 calibrations */ Global SpecCal spec_cal[NUM_SPECS]; /* Structs to hold Spect calibrations*/ Global SatlanticCal satlantic_cal; /* Struct to hold Satlantic cal */ Global GndFltCal gfCal[MAX_GF_CALS]; /* Gnd fault board cals */ Global Int oasisAnalogChan = OASIS_CHAN; /********************************/ /* Module Local Data */ /********************************/ MLocal double dfiletime; /* Time portion of data file name */ /* E.g. m1a.93001.01 => 93001.01 */ MLocal char base_dir[NAMESIZE]; /* Name of base dir for output data */ MLocal char hdr_dir[NAMESIZE]; /* Name of directory for headers */ MLocal char cfg_file[NAMESIZE]; /* Name of OASIS configuration file */ MLocal char linebuf[LINEBUFSIZE]; /* Place to scan line input */ MLocal char keywd_buf[NAMESIZE]; /* String buffer for keyword compare*/ MLocal char name_buf[NAMESIZE]; /* String buffer for name parameter */ MLocal FilePtr files[] = /* File ptrs and names for outputs */ { {NULLF, 0, "error"}, {NULLF, 0, ""}, {NULLF, 0, "atlas"}, {NULLF, 0, "oasis"}, {NULLF, 0, "par"}, {NULLF, 0, "ctd"}, {NULLF, 0, "spectro"}, {NULLF, 0, "adcp"}, {NULLF, 0, "gps"}, {NULLF, 0, "modem"}, {NULLF, 0, "pco2"}, {NULLF, 0, "ctd2"}, {NULLF, 0, "ctd"}, {NULLF, 0, "spectro10"}, {NULLF, 0, "spectro20"}, {NULLF, 0, "nitrate"}, {NULLF, 0, "nitrate2"}, {NULLF, 0, "specprr"}, {NULLF, 0, "satlantic"}, {NULLF, 0, "gps"}, {NULLF, 0, "nrl"}, {NULLF, 0, "oxygen"}, {NULLF, 0, "fluor"}, {NULLF, 0, "transmiss"}, {NULLF, 0, "no3"}, {NULLF, 0, "no3.2"}, {NULLF, 0, "ac9"}, {NULLF, 0, "pump"}, {NULLF, 0, "pump"}, {NULLF, 0, "shutter0"}, {NULLF, 0, "shutter1"}, {NULLF, 0, "specprr.volts"}, {NULLF, 0, "metsys"}, {NULLF, 0, "tstring"}, {NULLF, 0, "gf"} }; MLocal CalStruct cals[] = /* File funcs and names for calibr */ { { "errors", store_fname, (Void *)&(files[ERRORF].fname), FALSE }, { "data", store_dirname, (Void *)base_dir, FALSE }, { "header", store_dirname, (Void *)hdr_dir, FALSE }, { "analog", analog_cal, (Void *)analog, FALSE }, { "oasis_chan", setInt, (Void *)&oasisAnalogChan, FALSE }, { "atlas", read_atlas_cal, (Void *)&atlas_cal, FALSE }, { "ctd", read_ctd_cal, (Void *)&ctd_cal[CTD_CAL], FALSE }, { "ctd2", read_ctd_cal, (Void *)&ctd_cal[CTD2_CAL], FALSE }, { "ctd3", read_ctd_cal, (Void *)&ctd_cal[CTD3_CAL], FALSE }, { "no3", read_no3_cal, (Void *)&no3_cal[NO3_CAL], FALSE }, { "no3.2", read_no3_cal, (Void *)&no3_cal[NO3_CAL2], FALSE }, { "spectro", read_spec_cal, (Void *)&spec_cal[SPECTRO_CAL], FALSE }, { "spectro10", read_spec_cal, (Void *)&spec_cal[SPECTRO2_CAL], FALSE }, { "spectro20", read_spec_cal, (Void *)&spec_cal[SPECTRO3_CAL], FALSE }, { "satlantic", read_satlantic_cal, (Void *)&satlantic_cal, FALSE }, { "specprr", read_spec_cal, (Void *)&spec_cal[SPECPRR_CAL], FALSE }, { "gndflt", read_gf_cal, (Void *)gfCal, FALSE } }; /************************************************************************/ /* Function : get_begin_line */ /* Purpose : Look for "begin" line in uuencode file */ /* Inputs : FILE pointer */ /* Outputs : Log number n from "begin 644 oasis.n". */ /************************************************************************/ Int32 get_begin_line( FILE *fd ) { Int unused, lognum; while ( fgets(linebuf, sizeof(linebuf), fd) != NULL ) { if (sscanf(linebuf," begin %d oasis.%d", &unused, &lognum) >= 2) return( lognum ); } return( ERROR ); } /* get_begin_line() */ /************************************************************************/ /* Function : openDataFile */ /* Purpose : Open data file */ /* Inputs : Name of file */ /* Outputs : FILE pointer */ /************************************************************************/ FILE *openDataFile( char *name ) { FILE *fd; if ( (fd = fopen(name, "rb")) == (FILE *)NULL ) printf("Cannot open %s\n", name); return( fd ); } /* openDataFile() */ /************************************************************************/ /* Function : uudecode */ /* Purpose : Decode a group of 3 binary bytes from 4 input characters*/ /* Inputs : Ptr to input chars, ptr to output, number of bytes */ /* Outputs : None */ /************************************************************************/ Void uudecode( char *in, Byte *out, Int len ) { Byte *p; p = out; if ( len >= 1 ) *p++ = (DEC(*in) << 2) | (DEC(in[1]) >> 4); if ( len >= 2 ) *p++ = (DEC(in[1]) << 4) | (DEC(in[2]) >> 2); if ( len >= 3 ) *p = (DEC(in[2]) << 6) | (DEC(in[3])); } /* uudecode() */ /************************************************************************/ /* Function : tohex */ /* Purpose : Convert an ASCII character to hex equivalent */ /* Inputs : ASCII character, radix */ /* Outputs : Hex number, or ERROR if not valid hex digit */ /************************************************************************/ Int32 tohex( char c ) { Reg Int32 rtn; if ( isdigit(c) ) rtn = c - '0'; else if ( isxdigit(c) ) rtn = _toupper(c) - 'A' + 10; else return( ERROR ); return( (rtn < 16) ? rtn : ERROR ); } /* tohex() */ /************************************************************************/ /* Function : getByte */ /* Purpose : Get one byte from first two ASCII chars in buffer */ /* Inputs : Pointer to buffer ptr */ /* Outputs : Value of 0 - 255, or ERROR */ /* Comment : Points buffer ptr to next char after converted input */ /************************************************************************/ Int32 getByte( char **p ) { Reg Int32 low, high; while ( isspace(**p) ) /* Delete leading blanks */ (*p)++; if ( ((high = tohex(*(*p)++)) == ERROR) || ((low = tohex(*(*p)++)) == ERROR) ) return( ERROR ); return( (high << 4) + low ); } /* getByte() */ /************************************************************************/ /* Function : getDataLine */ /* Purpose : Read and decode one line from data file */ /* Inputs : Buffer for resulting data, size of buffer, FILE ptr */ /* Outputs : Number characters read, 0 if error, or EOF */ /************************************************************************/ Int32 getDataLine( Byte *buf, Int len, FILE *fd, FileType ftype ) { Int32 uulen, i; char *src; Byte *dst; char *p; Int32 val; if ( fgets(linebuf, sizeof(linebuf), fd) == NULL ) return( EOF ); for ( p = linebuf; *p; p++ ) if ( (*p == '\n') || (*p == '\r') ) *p = '\0'; src = linebuf; dst = buf; switch( ftype ) { case FT_UUENCODE: if (strncmp(linebuf, "end", 3) == 0) return( UUEND ); uulen = DEC(*src); src++; if ( (Int)strlen(linebuf) != (((uulen + 2)/3 * 4) + 1) ) return( 0 ); for ( i = uulen; i > 0; i -= 3 ) { uudecode( src, dst, i ); src += 4; dst += 3; } return( uulen ); case FT_HEX: for ( i = val = 0; (i < len) && ((val = getByte(&src)) != ERROR); i++ ) *dst++ = (Byte)val; return( i ); } return( 0 ); } /* getDataLine() */ /************************************************************************/ /* Function : readDataFile */ /* Purpose : Read and decode len bytes from data file */ /* Inputs : Buffer for resulting data, bytes to read, FILE ptr */ /* Outputs : Number characters read, ERROR if error, or EOF */ /* Comment : OASIS records should always begin and end at new line */ /* This function calls uugetline() for the appropriate */ /* number of bytes, and returns ERROR if size wrong */ /************************************************************************/ Int32 readDataFile( Byte *buf, Int len, FILE *fd, FileType ftype ) { Int32 i, left; Byte *p; for ( p = buf, left = len; left > 0; ) { if ( (i = getDataLine(p, left, fd, ftype)) <= 0 ) return( i ); left -= i; p += i; if ( left < 0 ) return( ERROR ); } return( len ); } /* readDataFile() */ /************************************************************************/ /* Function : get_sensor_file */ /* Purpose : Get file pointer for given sensor */ /* Inputs : Sensor */ /* Outputs : None */ /************************************************************************/ FILE * get_sensor_file( Int sensor ) { FILE *fp, *hdrp; Int c; if ( (fp = files[sensor].fp) != NULLF ) { if ( files[sensor].ftime == itime ) return( fp ); fclose( fp ); } if ( files[sensor].fname[0] == '/' ) sprintf( linebuf, "%s/%05d", files[sensor].fname, itime ); else sprintf( linebuf, "%s/%s/%05d", base_dir, files[sensor].fname, itime ); if ( (fp = fopen(linebuf,"a")) == NULLF ) { if ( sensor == ERRORF ) fp = stderr; files[sensor].fp = fp; fprintf( files[ERRORF].fp, "Cannot open %s\n", linebuf ); return( fp ); } files[sensor].fp = fp; files[sensor].ftime = itime; sprintf( linebuf, "%s/%s.hdr", hdr_dir, files[sensor].fname ); if ( (hdrp = fopen(linebuf,"r")) != NULLF ) { if ( ftell(fp) == 0 ) while ( (c = fgetc(hdrp)) != EOF ) fputc(c, fp); fclose( hdrp ); } return( fp ); } /* get_sensor_file() */ /************************************************************************/ /* Function : close_sensor_files */ /* Purpose : Close all output files for sensors */ /* Inputs : None */ /* Outputs : None */ /************************************************************************/ Void close_sensor_files( Void ) { Int i; for ( i = ATLAS; i < SENSORS; i++ ) if ( files[i].fp != NULLF ) { fclose( files[i].fp ); files[i].fp = NULLF; } } /* close_sensor_files() */ /************************************************************************/ /* Function : print_error */ /* Purpose : Print error message to error file */ /* Inputs : Format string, arguments as in printf */ /* Outputs : None */ /************************************************************************/ Void print_error( char *fmt, ... ) { va_list ap; /* Argument pointer */ FILE *fp; /* Error file pointer */ va_start( ap, fmt ); if ( (fp = get_sensor_file(ERRORF)) == NULLF ) fp = stderr; vfprintf( fp, fmt, ap ); va_end( ap ); } /* print_error() */ /************************************************************************/ /* Function : print_sensor */ /* Purpose : Print to sensor file */ /* Inputs : Sensor, format string, arguments as in printf */ /* Outputs : None */ /************************************************************************/ Void print_sensor( Int sensor, char *fmt, ... ) { va_list ap; /* Argument pointer */ FILE *fp; /* Error file pointer */ va_start( ap, fmt ); if ( (fp = get_sensor_file(sensor)) != NULLF ) vfprintf( fp, fmt, ap ); va_end( ap ); } /* print_sensor() */ /************************************************************************/ /* Function : store_dirname */ /* Purpose : Store a directory name in local static data */ /* Inputs : Where to store name, name to store */ /* Outputs : OK */ /************************************************************************/ Status store_dirname( char *name, char *where ) { strncpy( where, name, BNAMESIZE ); return( OK ); } /* store_dirname() */ /************************************************************************/ /* Function : store_fname */ /* Purpose : Allocate space and store a file name */ /* Inputs : Name to store, where to put new pointer */ /* Outputs : OK or ERROR */ /************************************************************************/ Status store_fname( char *name, char **where ) { Reg char *p; if ( (p = (char *)malloc(strlen(name) + 1)) == NULL ) return( ERROR ); strcpy( p, name ); *where = p; return( OK ); } /* store_fname() */ /************************************************************************/ /* Function : analog_cal */ /* Purpose : Read analog calibration directly from cfg file */ /* Inputs : Dummy parameter, ptr to analog cal struct, ptr to tail */ /* of cfg file line */ /* Outputs : OK */ /************************************************************************/ Status analog_cal( char *parm, Analog *cp, char *tail ) { char unitname[UNITNAMELEN]; Int channel, i; double a, b, c, d; if ( (i = sscanf(tail, " %d %lf %lf %lf %lf %s", &channel, &a, &b, &c, &d, unitname)) >= 3 ) { analog[channel].a = a; analog[channel].b = b; analog[channel].c = c; analog[channel].d = d; if ( i >= 6 ) strncpy( analog[channel].units, unitname, UNITNAMELEN ); } return( OK ); } /* analog_cal() */ /************************************************************************/ /* Function : setInt */ /* Purpose : Store an integer */ /* Inputs : ASCII value, place to store it */ /* Outputs : OK */ /************************************************************************/ Status setInt( char *value, Int *where ) { sscanf( value, " %d", where ); return( OK ); } /* setInt() */ /************************************************************************/ /* Function : get_can_name */ /* Purpose : Get name of OASIS can, set base & hdr directory names */ /* Inputs : Name of data file */ /* Outputs : Ptr to Global variable can_name */ /* Side Effects: Fills in can_name with name of OASIS can */ /* Sets base and header directory names */ /* Sets Global variable dfiletime */ /* Sets name of OASIS data file, if necessary */ /************************************************************************/ Void get_can_name( char *dataname ) { Reg char *p, *q; Reg Nat32 i; if ( (p = strrchr(dataname, '/')) != NULL ) p++; #ifdef WIN32 else if ( (p = strrchr(dataname, '\\')) != NULL ) p++; #endif else p = dataname; if ( (q = strchr(p, '.')) != NULL ) i = q - p; else i = strlen(p); strncpy( can_name, p, i ); can_name[i] = '\0'; sprintf( base_dir, "%s/%s", BASE_DIR, can_name ); sprintf( hdr_dir, "%s/%s", HDR_DIR, can_name ); /* Now get data file name as a floating point number */ /* E.g., /dir/m1a.93001.01 -> (double)93001.01 */ for ( i = 0, q = p + strlen(p); (q != p) && (i < 2); ) if ( *--q == '.' ) /* Look for 2nd '.' from end*/ i++; if ( *q == '.' ) q++; if ( sscanf(q, "%lg", &dfiletime) < 1 ) dfiletime = 0.0; } /* get_can_name() */ /************************************************************************/ /* Function : read_cfg */ /* Purpose : Read OASIS configuration file */ /* Inputs : Ptr to cfg file name ptr */ /* Outputs : OK or ERROR */ /************************************************************************/ Status read_cfg( char **cfgname ) { Reg FILE *fp; Reg Nat32 i; Nat32 n; Reg char *p; double starttime, endtime; MBool dated; memset( (void *)ctd_cal, sizeof(ctd_cal), 0 ); memset( (void *)no3_cal, sizeof(no3_cal), 0 ); memset( (void *)spec_cal, sizeof(spec_cal), 0 ); memset( (void *)analog, sizeof(analog), 0 ); if ( *cfgname == NULL ) { sprintf( cfg_file, "%s/%s.cfg", CFG_DIR, can_name ); *cfgname = cfg_file; } if ( (fp = fopen(*cfgname, "rb")) == (FILE *)NULL ) return( ERROR ); memset( (void *)&analog, 0, ANALOG_CHANS * sizeof(Analog) ); for ( i = 0; i < (sizeof(cals)/sizeof(CalStruct)); i++ ) cals[i].cs_got_dated_cal = FALSE; while ( fgets(linebuf, sizeof(linebuf), fp) != NULL ) { /* Read one line of input*/ p = linebuf; dated = FALSE; if ((i = sscanf(linebuf, " %lg - %lg%n", &starttime, &endtime, &n)) == 2) { p += n; dated = TRUE; } if ( sscanf(p, " %s%n %s", keywd_buf, &n, name_buf) == 2 ) for ( i = 0; i < (sizeof(cals)/sizeof(CalStruct)); i++ ) if ( strcasecmp(keywd_buf, cals[i].cs_name) == 0 ) if ( (dated && (dfiletime > starttime - .005) && (dfiletime < endtime + .005)) || (!dated && (!cals[i].cs_got_dated_cal)) ) { if ( (*cals[i].cs_func)(name_buf, cals[i].cs_parm, p+n) != OK ) printf("Can't read calibration file %s\n", name_buf); else if ( dated ) cals[i].cs_got_dated_cal = TRUE; break; } } fclose( fp ); return( OK ); } /* read_cfg() */ /************************************************************************/ /* Function : getIntelword */ /* Purpose : Get a word in Intel format from data stream */ /* Inputs : Ptr to data stream */ /* Outputs : Word */ /************************************************************************/ Nat16 getIntelword( Byte *p ) { Nat16 rtn; rtn = (Nat16)(*p); rtn += (Nat16)(p[1] << 8); return( rtn ); } /* getIntelword() */ /************************************************************************/ /* Function : getIntellong */ /* Purpose : Get a longword in Intel format from data stream */ /* Inputs : Ptr to data stream */ /* Outputs : Long */ /************************************************************************/ Nat32 getIntellong( Byte *p ) { Nat32 rtn; rtn = (Nat32)getIntelword(p); rtn += ((Nat32)getIntelword(&p[2]) << 16); return( rtn ); } /* getIntellong() */ /************************************************************************/ /* Function : getMotword */ /* Purpose : Get a word in Motorola format from data stream */ /* Inputs : Ptr to data stream */ /* Outputs : Word */ /************************************************************************/ Nat16 getMotword( Byte *p ) { Nat16 rtn; rtn = (Nat16)(*p << 8); rtn += (Nat16)(p[1]); return( rtn ); } /* getMotword() */ /************************************************************************/ /* Function : getMotlong */ /* Purpose : Get a longword in Motorola format from data stream */ /* Inputs : Ptr to data stream */ /* Outputs : Long */ /************************************************************************/ Nat32 getMotlong( Byte *p ) { Nat32 rtn; rtn = ((Nat32)getMotword(p) << 16); rtn += (Nat32)getMotword(&p[2]); return( rtn ); } /* getMotlong() */ /************************************************************************/ /* Function : getHdrWord */ /* Purpose : Get a word of Header data, format depends on file type */ /* Inputs : Ptr to data stream, FileType */ /* Outputs : Word */ /************************************************************************/ Nat16 getHdrWord( Byte *p, FileType ftype ) { return( (ftype == FT_HEX) ? getMotword(p) : getIntelword(p) ); } /* getHdrWord() */ /************************************************************************/ /* Function : getHdrLong */ /* Purpose : Get a longword of Header data, format depends on file type*/ /* Inputs : Ptr to data stream, FileType */ /* Outputs : Long */ /************************************************************************/ Nat32 getHdrLong( Byte *p, FileType ftype ) { return( (ftype == FT_HEX) ? getMotlong(p) : getIntellong(p) ); } /* getHdrLong() */ @ 2.8 log @Archiving sources prior to porting to DOS/Windows @ text @d4 1 a4 1 /* $Header: file.c,v 2.7 97/09/09 09:52:45 bobh Exp $ */ d9 1 a9 1 /* $Revision: 2.7 $ */ d15 3 d48 2 a49 2 #include /* MBARI type definitions */ #include /* MBARI constants */ d55 1 d110 2 a111 1 Status setInt32( char *value, Int32 *where ); d125 2 a126 1 Global Int32 oasisAnalogChan = OASIS_CHAN; a140 1 MLocal char *oasis_m1b_name = "oasis.m1b"; d153 2 a154 1 {NULLF, 0, "shutter1"}, {NULLF, 0, "specprr.volts"} d162 1 a162 1 { "oasis_chan", setInt32, (Void *)&oasisAnalogChan, FALSE }, d173 2 a174 1 { "specprr", read_spec_cal, (Void *)&spec_cal[SPECPRR_CAL], FALSE } d295 1 a295 1 /* Outputs : Number characters read, ERROR if error, or EOF */ d325 1 a325 1 return( ERROR ); d343 1 a343 1 return( ERROR ); d561 1 a561 1 /* Function : setInt32 */ d567 1 a567 1 setInt32( char *value, Int32 *where ) d572 1 a572 1 } /* setInt32() */ d591 7 a597 1 if ( (p = strrchr(dataname, '/')) == NULL ) a598 2 else p++; d608 2 a609 10 if ( strncmp(can_name, "m1", 2) == 0 ) { sprintf( base_dir, "%s/m1", BASE_DIR ); sprintf( hdr_dir, "%s/m1", HDR_DIR ); } else { sprintf( base_dir, "%s/%s", BASE_DIR, can_name ); sprintf( hdr_dir, "%s/%s", HDR_DIR, can_name ); } a610 3 if ( strcmp(can_name, "m1b") == 0 ) files[OASIS_CAN].fname = oasis_m1b_name; d743 1 a743 1 Nat32 rtn; @ 2.7 log @Archiving various changes @ text @d4 1 a4 1 /* $Header: file.c,v 2.6 96/05/30 15:07:55 bobh Exp $ */ d9 1 a9 1 /* $Revision: 2.6 $ */ d15 3 @ 2.6 log @Update for version in use during 1995-6 deployment @ text @d2 1 a2 1 /* Copyright 1991 MBARI */ d4 1 a4 1 /* $Header: file.c,v 2.5 94/12/15 10:59:38 hebo Exp $ */ d9 1 a9 1 /* $Revision: 2.5 $ */ d15 3 d48 1 a48 2 #include /* Needed for varargs */ #include /* variable argument lists */ a49 1 #define UUBUFSIZE 512 /* Size of uu decode buffer */ d51 1 a51 1 #define BNAMESIZE 64 /* Size of file base name */ d53 1 a53 1 #define BASE_DIR "/oasis" d56 1 d58 1 a58 1 #define DEC(c) (((c) - ' ') & 0x3f) /* uudecode macro */ d60 1 d64 2 a65 2 Int ftime; /* Time that .ext of file represents*/ /* as in file.yyddd (year, julday)*/ a93 7 Extern AtlasCal atlas_cal; /* ATLAS calibration */ Extern Analog analog[]; /* Analog calibration */ Extern CTDCal ctd_cal[NUM_CTDS]; /* Structs to hold CTD calibrations */ Extern No3Cal no3_cal[NUM_NO3S]; /* Structs to hold NO3 calibrations */ Extern SpecCal spec_cal[NUM_SPECS]; /* Structs to hold Spect calibrations*/ Extern SatlanticCal satlantic_cal; /* Struct to hold Satlantic cal */ Extern char *rcdfile; /* Name of record file */ d103 1 d111 7 a125 2 MLocal Byte uubuf[UUBUFSIZE]; /* Buffer for raw uuencoded data */ MLocal char cfg_file[NAMESIZE]; /* Name of OASIS configuration file */ d128 2 a129 1 MLocal char line_buf[LINEBUFSIZE]; /* Place to scan line input */ d143 3 a145 1 {NULLF, 0, "no3"}, {NULLF, 0, "no3.2"} a151 1 { "record", store_fname, (Void *)&rcdfile, FALSE }, d153 1 d163 2 a164 2 { "specprr", read_spec_cal, (Void *)&spec_cal[SPECPRR_CAL], FALSE }, { "satlantic", read_satlantic_cal, (Void *)&satlantic_cal, FALSE } d177 1 a177 1 Int32 unused, lognum; d179 1 a179 1 while ( fgets((char *)uubuf, sizeof(uubuf), fd) != NULL ) d181 1 a181 1 if ( sscanf((char *)uubuf, " begin %d oasis.%d", &unused, &lognum) >= 2) d191 2 a192 2 /* Function : uuopen */ /* Purpose : Open a uuencoded file, check its "begin" line */ d197 1 a197 1 *uuopen( char *name ) d206 1 a206 1 } /* uuopen() */ d216 1 a216 1 uudecode( Byte *in, Byte *out, Int len ) d220 1 a220 1 p =out; d235 49 a283 2 /* Function : uugetline */ /* Purpose : Read and decode one line from a uuencoded file */ d285 1 a285 1 /* Outputs : Number characters read, UUERROR if error, or EOF */ d288 1 a288 1 uugetline( Byte *buf, Int len, FILE *fd ) d290 5 a294 3 Int uulen, i; Byte *p, *q; char *p1; d296 1 a296 1 if ( fgets((char *)uubuf, sizeof(uubuf), fd) == NULL ) a297 2 if (strncmp((char *)uubuf, "end", 3) == 0) return( UUEND ); d299 17 a315 7 uulen = DEC(uubuf[0]); if ( (p1 = strchr((char *)uubuf, '\n')) != NULL ) *p1 = '\0'; if ( (p1 = strchr((char *)uubuf, '\r')) != NULL ) *p1 = '\0'; if ( strlen((char *)uubuf) != (((uulen + 2)/3 * 4) + 1) ) return( UUERROR ); d317 14 a330 7 p = &uubuf[1]; q = buf; for ( i = uulen; i > 0; i -= 3 ) { uudecode( p, q, i ); p += 4; q += 3; d333 1 a333 1 return( uulen ); d335 1 a335 1 } /* uugetline() */ d339 4 a342 4 /* Function : uuread */ /* Purpose : Read and decode len bytes from a uuencoded file */ /* Inputs : Buffer for resulting data, size of buffer, FILE ptr */ /* Outputs : Number characters read, UUERROR if error, or EOF */ d345 1 a345 1 /* number of bytes, and returns UUERROR if size wrong */ d347 2 a348 2 Int uuread( Byte *buf, Int len, FILE *fd ) d350 1 a350 1 Int i, left; d355 1 a355 1 if ( (i = uugetline(p, left, fd)) <= 0 ) d360 1 a360 1 return( UUERROR ); d365 1 a365 1 } /* uuread() */ a378 1 Boolean exists; d388 1 a388 1 sprintf( line_buf, "%s/%05d", files[sensor].fname, itime ); d390 1 a390 1 sprintf( line_buf, "%s/%s/%05d", base_dir, files[sensor].fname, itime ); d392 1 a392 1 if ( (fp = fopen(line_buf,"a")) == NULLF ) d397 1 a397 1 fprintf( files[ERRORF].fp, "Cannot open %s\n", line_buf ); d404 1 a404 1 sprintf( line_buf, "%s/%s.hdr", hdr_dir, files[sensor].fname ); d406 1 a406 1 if ( (hdrp = fopen(line_buf,"r")) != NULLF ) d458 2 d480 2 d551 15 d634 1 a634 1 Reg Int32 i; d640 5 d659 1 a659 1 while ( fgets(line_buf, sizeof(line_buf), fp) != NULL ) d661 1 a661 1 p = line_buf; d664 1 a664 1 if ((i = sscanf(line_buf, " %lg - %lg%n", &starttime, &endtime, &n)) d693 100 @ 2.5 log @Accumulated minor changes, mainly due to move to tsunami @ text @d4 1 a4 1 /* $Header: file.c,v 2.4 94/01/21 14:36:15 hebo Exp $ */ d9 1 a9 1 /* $Revision: 2.4 $ */ d15 3 d81 1 d83 1 d94 1 d96 1 d137 4 a140 1 {NULLF, 0, "nitrate"}, {NULLF, 0, "nitrate2"}, {NULLF, 0, "specprr"} d153 2 d158 2 a159 1 { "specprr", read_spec_cal, (Void *)&spec_cal[SPECPRR_CAL], FALSE } d167 1 a167 1 /* Outputs : TRUE if got begin line, else FALSE */ d169 1 a169 1 MBool d172 1 a172 1 Reg char *p; d174 1 a174 3 p = (char *)uubuf; while ( fgets(p, sizeof(uubuf), fd) != NULL ) d176 2 a177 4 while ( isspace(*p) ) p++; if (strncmp(p, "begin ", 6) == 0) return( TRUE ); d180 1 a180 1 return( FALSE ); a197 4 else if( get_begin_line(fd) ) return( fd ); else printf("No begin line in %s\n", name); d199 1 a199 1 return( (FILE *)NULL ); d235 1 a235 1 Int d245 1 a245 1 return( get_begin_line(fd) ? 0 : EOF ); @ 2.4 log @Added support for date ranges in cfg file @ text @d4 1 a4 1 /* $Header: file.c,v 2.1 94/01/17 11:07:40 hebo Exp $ */ d9 1 a9 1 /* $Revision: 2.1 $ */ d15 3 d46 1 d49 3 a51 3 #define BASE_DIR "/usr/local/oasis" #define CFG_DIR "/usr/local/oasis/cfg" #define HDR_DIR "/usr/local/oasis/cfg" d60 1 a60 1 char fname[BNAMESIZE]; /* File base name */ d90 1 d98 1 d103 7 d113 2 d119 1 a119 1 MLocal char line_buf[NAMESIZE]; /* Place to scan line input */ d122 1 d134 1 a134 1 { { "errors", store_dirname, (Void *)files[ERRORF].fname, FALSE }, d137 1 d151 26 a185 1 char *p; d189 2 a191 9 { p = (char *)uubuf; while ( fgets(p, sizeof(uubuf), fd) != NULL ) { while ( isspace(*p) ) p++; if (strncmp(p, "begin ", 6) == 0) return( fd ); } d193 1 a193 1 } d240 1 a240 1 return( EOF ); d424 20 d474 8 a481 8 /* Function : set_cfgfile_name */ /* Purpose : Set name of cfg file and base and header directory names*/ /* Inputs : Ptr to cfg file name ptr, name of data file, place to */ /* store file name as float */ /* Outputs : None */ /* Comments : If *cfgname (user-passed cfg file) is NULL, looks at */ /* data file name to attempt correct configuration */ /* If that fails, default cfg file is for m1a */ d484 1 a484 1 set_cfgfile_name( char **cfgname, char *dataname, double *dp ) d487 1 a487 1 Reg Int32 i; a488 3 sprintf( base_dir, "%s/m1", BASE_DIR ); sprintf( hdr_dir, "%s/m1", HDR_DIR ); d494 4 a497 12 if ( *cfgname == NULL ) { if ( (q = strchr(p, '.')) == NULL ) sprintf( cfg_file, "%s/m1a.cfg", CFG_DIR ); else { sprintf( cfg_file, "%s/", CFG_DIR ); strncat( cfg_file, p, q - p ); strcat( cfg_file, ".cfg" ); } *cfgname = cfg_file; } d499 2 a500 2 if ( strncmp(p, "m1b", 3) == 0 ) strcpy( files[OASIS_CAN].fname, "oasis.m1b" ); d502 1 a502 1 if ( strncmp(p, "m2", 2) == 0 ) d504 2 a505 2 sprintf( base_dir, "%s/m2", BASE_DIR ); sprintf( hdr_dir, "%s/m2", HDR_DIR ); d507 1 a507 2 if ( strncmp(p, "drifter", 7) == 0 ) d509 2 a510 2 sprintf( base_dir, "%s/drifter", BASE_DIR ); sprintf( hdr_dir, "%s/drifter", HDR_DIR ); d513 2 a514 2 /* Now get data file name as a floating point number */ /* E.g., /dir/m1a.93001.01 -> (double)93001.01 */ d516 3 d526 2 a527 2 if ( sscanf(q, "%lg", dp) < 1 ) *dp = 0.0; d529 1 a529 1 } /* set_cfgfile_name() */ d535 1 a535 1 /* Inputs : Ptr to cfg file name ptr, name of data file */ d539 1 a539 1 read_cfg( char **cfgname, char *dataname ) d545 1 a545 1 double dfiletime, starttime, endtime; d548 5 a552 1 set_cfgfile_name( cfgname, dataname, &dfiletime ); @ 2.1 log @Misc changes @ text @d4 1 a4 1 /* $Header: file.c,v 2.0 92/08/31 15:35:51 hebo Exp $ */ d9 1 a9 1 /* $Revision: 2.0 $ */ d15 3 d43 1 a43 1 #define BNAMESIZE 32 /* Size of file base name */ d59 7 d67 1 d69 9 d82 1 d89 8 a101 3 MLocal char atlas_file[NAMESIZE]; /* Name of ATLAS calibration file */ MLocal char ctd_file[NAMESIZE]; /* Name of CTD calibration file */ MLocal char spec_file[NAMESIZE]; /* Name of Spectro calibration file */ d104 3 a106 1 MLocal char tmp_buf[NAMESIZE]; /* Misc temporary buffer */ d117 14 a130 3 /********************************/ /* Forward Declaration */ /********************************/ a131 1 Void print_error( char *fmt, ... ); a132 1 d146 1 a146 1 print_error("Cannot open %s\n", name); d157 1 a157 1 print_error("No begin line in %s\n", name); d280 1 a280 1 sprintf( tmp_buf, "%s/%05d", files[sensor].fname, itime ); d282 1 a282 1 sprintf( tmp_buf, "%s/%s/%05d", base_dir, files[sensor].fname, itime ); d284 1 a284 1 if ( (fp = fopen(tmp_buf,"a")) == NULLF ) d289 1 a289 1 fprintf( files[ERRORF].fp, "Cannot open %s\n", tmp_buf ); d296 1 a296 1 sprintf( tmp_buf, "%s/%s.hdr", hdr_dir, files[sensor].fname ); d298 1 a298 1 if ( (hdrp = fopen(tmp_buf,"r")) != NULLF ) d374 4 a377 7 /* Function : read_cfg */ /* Purpose : Read OASIS configuration file */ /* Inputs : Ptr to cfg file name ptr, name of data file */ /* Outputs : OK or ERROR */ /* Comments : If *cfgname (user-passed cfg file) is NULL, looks at */ /* data file name to attempt correct configuration */ /* If that fails, default cfg file is for m1a */ d380 1 a380 1 read_cfg( char **cfgname, char *dataname ) d382 16 a397 2 FILE *fp; char *p, *q; a399 1 unsigned j; d402 32 d470 34 d509 4 a512 1 while ( fgets(tmp_buf, sizeof(tmp_buf), fp) != NULL ) d514 5 a518 2 if ( (i = sscanf(tmp_buf, " analog %d %lf %lf %lf %lf %s", &channel, &a, &b, &c, &d, unitname)) >= 3 ) d520 2 a521 6 analog[channel].a = a; analog[channel].b = b; analog[channel].c = c; analog[channel].d = d; if ( i >= 6 ) strncpy( analog[channel].units, unitname, UNITNAMELEN ); d523 16 a538 53 else if ( sscanf(tmp_buf, " errors %s", files[ERRORF].fname) == 1 ) ; else if ( sscanf(tmp_buf, " data %s", base_dir) == 1 ) ; else if ( sscanf(tmp_buf, " header %s", hdr_dir) == 1 ) ; else if ( sscanf(tmp_buf, " atlas %s", atlas_file) == 1 ) { if ( read_atlas_cal(atlas_file) != OK ) print_error("Can't read ATLAS calibration file %s\n", atlas_file); } else if ( sscanf(tmp_buf, " ctd2 %s", ctd_file) == 1 ) { if ( read_ctd_cal(ctd_file, &ctd_cal[1]) != OK ) print_error("Can't read 2nd CTD calibration file %s\n", ctd_file); } else if ( sscanf(tmp_buf, " ctd3 %s", ctd_file) == 1 ) { if ( read_ctd_cal(ctd_file, &ctd_cal[2]) != OK ) print_error("Can't read 3rd CTD calibration file %s\n", ctd_file); } else if ( sscanf(tmp_buf, " ctd %s", ctd_file) == 1 ) { if ( read_ctd_cal(ctd_file, &ctd_cal[0]) != OK ) print_error("Can't read CTD calibration file %s\n", ctd_file); } else if ( sscanf(tmp_buf, " spectro20 %s", spec_file) == 1 ) { if ( read_spec_cal(spec_file, &spec_cal[SPECTRO3_CAL]) != OK ) print_error("Can't read 20 meter Spectro calibration file \"%s\"\n", spec_file); } else if ( sscanf(tmp_buf, " spectro10 %s", spec_file) == 1 ) { if ( read_spec_cal(spec_file, &spec_cal[SPECTRO2_CAL]) != OK ) print_error("Can't read 10 meter Spectro calibration file \"%s\"\n", spec_file); } else if ( sscanf(tmp_buf, " spectro %s", spec_file) == 1 ) { if ( read_spec_cal(spec_file, &spec_cal[SPECTRO_CAL]) != OK ) print_error("Can't read Spectro calibration file \"%s\"\n", spec_file); } else if ( sscanf(tmp_buf, " specprr %s", spec_file) == 1 ) { if ( read_spec_cal(spec_file, &spec_cal[SPECPRR_CAL]) != OK ) print_error("Can't read SpecPRR calibration file \"%s\"\n", spec_file); } @ 2.0 log @Auguest 1992 Deployment. Changed to allow multiple sensors of same type. @ text @d4 1 a4 1 /* $Header: file.c,v 1.2 92/05/12 18:19:29 hebo Exp $ */ d9 1 a9 1 /* $Revision: 1.2 $ */ d15 3 d84 1 a84 1 {NULLF, 0, "modem"}, {NULLF, 0, "pco2"}, {NULLF, 0, "ctd20"}, d86 1 a86 1 {NULLF, 0, "nitrate"}, {NULLF, 0, "nitrate2"} d349 1 a349 1 char *p; d353 1 a353 1 double a, b; d365 2 a366 4 if ( strncmp(p, "m1b", 3) == 0 ) sprintf( cfg_file, "%s/m1b.cfg", CFG_DIR ); else if ( strncmp(p, "m2", 2) == 0 ) sprintf( cfg_file, "%s/m2.cfg", CFG_DIR ); d368 5 a372 1 sprintf( cfg_file, "%s/m1a.cfg", CFG_DIR ); d385 6 d398 2 a399 2 if ( (i = sscanf(tmp_buf, " analog %d %lf %lf %s", &channel, &a, &b, unitname)) >= 3 ) d403 3 a405 1 if ( i > 3 ) d420 1 a420 1 else if ( sscanf(tmp_buf, " ctd20 %s", ctd_file) == 1 ) d423 1 a423 1 print_error("Can't read 20 meter CTD calibration file %s\n", d426 1 a426 1 else if ( sscanf(tmp_buf, " ctdm2 %s", ctd_file) == 1 ) d429 1 a429 1 print_error("Can't read M2 CTD calibration file %s\n", d439 1 a439 1 if ( read_spec_cal(spec_file, &spec_cal[2]) != OK ) d445 1 a445 1 if ( read_spec_cal(spec_file, &spec_cal[1]) != OK ) d451 1 a451 1 if ( read_spec_cal(spec_file, &spec_cal[0]) != OK ) d453 6 @ 1.2 log @Added spectroradiometer decoding (spec.c) @ text @d4 1 a4 1 /* $Header: file.c,v 1.1 92/03/16 15:42:31 hebo Rel $ */ d9 1 a9 1 /* $Revision: 1.1 $ */ d15 3 d37 5 a41 1 #define NAMESIZE 32 /* Size of file base name */ d50 1 a50 1 char fname[NAMESIZE]; /* File base name */ a57 2 Extern time_t oasis_time; /* Time of OASIS data in time_t fmt */ Extern double dtime; /* Time of OASIS data in real format*/ d60 2 a61 5 Extern char atlas_file[]; /* Name of ATLAS calibration file */ Extern char ctd_file[]; /* Name of CTD calibration file */ Extern char spec_file[]; /* Name of Spectro calibration file */ Extern char base_dir[]; /* Name of base directory */ Extern char hdr_dir[]; /* Name of header directory */ d65 1 a65 1 /* Global Data */ d68 8 a75 2 Global Byte uubuf[UUBUFSIZE]; /* Buffer for raw uuencoded data */ Global char name[512]; /* Buffer to build output file name */ d77 1 a77 5 char *errtypes[] = { "Empty", "Time", "ATLAS", "OASIS analog", "PAR", "CTD", "Spectro", "ADCP", "GPS" }; FilePtr files[] = /* File ptrs and names for outputs */ d80 4 a83 1 {NULLF, 0, "spectro"}, {NULLF, 0, "adcp"}, {NULLF, 0, "gps"} d240 1 a240 1 sprintf( name, "%s/%05d", files[sensor].fname, itime ); d242 1 a242 1 sprintf( name, "%s/%s/%05d", base_dir, files[sensor].fname, itime ); d244 1 a244 1 if ( (fp = fopen(name,"a")) == NULLF ) d249 1 a249 1 fprintf( files[ERRORF].fp, "Cannot open %s\n", name ); d256 1 a256 1 sprintf( name, "%s/%s.hdr", hdr_dir, files[sensor].fname ); d258 1 a258 1 if ( (hdrp = fopen(name,"r")) != NULLF ) a333 43 /* Function : sensor_error */ /* Purpose : Print sensor error */ /* Inputs : Instrument type, Error type */ /* Outputs : None */ /************************************************************************/ Void sensor_error( Int sensor, Status err ) { Int n; if ( sensor >= SENSORS ) { print_error("Unknown Error type\n"); return; } n = (Int)((1440.0 * fmod(dtime, 1.0)) + 0.5); print_error("%2d:%02d %s Error", n / 60, n % 60, errtypes[sensor]); switch( err ) { case ERROR: print_error(" reported by OASIS.\n"); break; case SIZE_ERR: print_error(". Wrong size.\n"); break; case CHKSUM_ERR: print_error(". Checksum error.\n"); break; case FMT_ERR: print_error(". Bad data format.\n"); break; } } /* sensor_error() */ /************************************************************************/ d336 1 a336 1 /* Inputs : Name of file */ d338 3 d343 1 a343 1 read_cfg( char *name ) d346 1 a346 1 char buf[128]; d349 1 d352 29 a380 1 if ( (fp = fopen(name, "rb")) == (FILE *)NULL ) d383 3 a385 1 while ( fgets(buf, sizeof(buf), fp) != NULL ) d387 1 a387 1 if ( (i = sscanf(buf, " analog %d %lf %lf %s", d395 1 a395 1 else if ( sscanf(buf, " atlas %s", atlas_file) == 1 ) d397 1 a397 1 else if ( sscanf(buf, " ctd %s", ctd_file ) == 1 ) d399 1 a399 1 else if ( sscanf(buf, " spectro %s", spec_file) == 1) d401 41 a441 6 else if ( sscanf(buf, " errors %s", files[ERRORF].fname ) == 1 ) ; else if ( sscanf(buf, " data %s", base_dir) == 1 ) ; else if ( sscanf(buf, " header %s", hdr_dir) == 1 ) ; d445 1 @ 1.1 log @Ignore leading blanks on "begin" line @ text @d4 1 a4 1 /* $Header: file.c,v 1.0 92/02/25 10:46:59 hebo Rel $ */ d9 1 a9 1 /* $Revision: 1.0 $ */ d15 3 d57 1 d360 4 d400 2 @ 1.0 log @Initial revision @ text @d4 1 a4 1 /* $Header: file.c,v 1.1 92/02/25 10:45:33 hebo Exp $ */ d9 1 a9 1 /* $Revision: 1.1 $ */ d15 1 a15 1 * Revision 1.1 92/02/25 10:45:33 10:45:33 hebo (Bob Herlien) a16 1 * d25 1 d92 1 d98 6 a103 2 while ( fgets((char *)uubuf, sizeof(uubuf), fd) != NULL ) if (strncmp((char *)uubuf, "begin ", 6) == 0) d105 1 @