head 2.9; access ; symbols ; locks ; strict; comment @ * @; 2.9 date 98.08.24.13.45.50; author bobh; state Exp; branches ; next 2.8; 2.8 date 98.03.17.11.11.36; author bobh; state Exp; branches ; next 2.7; 2.7 date 97.09.09.09.51.40; author bobh; state Exp; branches ; next 2.6; 2.6 date 96.05.30.15.07.25; author bobh; state Exp; branches ; next 2.5; 2.5 date 94.12.15.10.58.59; author hebo; state Exp; branches ; next 2.4; 2.4 date 94.01.21.14.35.34; author hebo; state Exp; branches ; next 2.3; 2.3 date 94.01.17.11.09.31; author hebo; state Exp; branches ; next 2.2; 2.2 date 93.09.17.10.59.04; author hebo; state Exp; branches ; next 2.1; 2.1 date 92.09.04.13.38.18; author hebo; state Exp; branches ; next 2.0; 2.0 date 92.08.31.15.35.26; author hebo; state Exp; branches ; next 1.3; 1.3 date 92.06.15.09.07.23; author hebo; state Exp; branches ; next 1.2; 1.2 date 92.05.12.18.18.39; author hebo; state Exp; branches ; next 1.1; 1.1 date 92.03.16.15.42.08; author hebo; state Rel; branches ; next 1.0; 1.0 date 92.02.25.10.46.58; author hebo; state Rel; branches ; next ; desc @Program to decode an OASIS uuencoded binary file @ 2.9 log @Archiving sources after M2/M3 & Eqpac deployments of 1998 @ text @/****************************************************************************/ /* Copyright 1991 MBARI */ /****************************************************************************/ /* $Header: decode.c,v 2.8 98/03/17 11:11:36 bobh Exp $ */ /* Summary : Program to decode an OASIS binary file */ /* Filename : decode.c */ /* Author : Robert Herlien (rah) */ /* Project : OASIS Mooring */ /* $Revision: 2.8 $ */ /* Created : 12/05/91 */ /****************************************************************************/ /* Modification History: */ /* 05dec91 rah - created */ /* $Log: decode.c,v $ * Revision 2.8 98/03/17 11:11:36 11:11:36 bobh (Bob Herlien) * Archiving sources prior to porting to DOS/Windows * * Revision 2.7 97/09/09 09:51:40 09:51:40 bobh (Bob Herlien) * Archiving various changes * * Revision 2.6 96/05/30 15:07:25 15:07:25 bobh (Bob Herlien) * Update for version in use during 1995-6 deployment * * Revision 2.5 94/12/15 10:58:59 10:58:59 hebo (Bob Herlien) * Accumlated minor changes, mainly due to move to tsunami * * Revision 2.4 94/01/21 14:35:34 14:35:34 hebo (Bob Herlien) * Added support for date ranges in cfg file * * Revision 2.3 94/01/17 11:09:31 11:09:31 hebo (Bob Herlien) * Misc changes * * Revision 2.2 93/09/17 10:59:04 10:59:04 hebo (Bob Herlien) * Changed method of finding config file based on name of data file. * * Revision 2.1 92/09/04 13:38:18 13:38:18 hebo (Bob Herlien) * Read CTD pressure from calibration file if no CTD pressure sensor. * * Revision 2.0 92/08/31 15:35:26 15:35:26 hebo (Bob Herlien) * Auguest 1992 Deployment. Changed to allow multiple sensors of same type. * * Revision 1.3 92/06/15 09:07:23 09:07:23 hebo (Bob Herlien) * *** empty log message *** * * Revision 1.2 92/05/12 18:18:39 18:18:39 hebo (Bob Herlien) * Added spectroradiometer decoding (spec.c) * * Revision 1.1 92/03/16 15:42:08 15:42:08 hebo (Bob Herlien) * Ignore leading blanks on "begin" line * * Revision 1.0 92/02/25 10:46:58 10:46:58 hebo (Bob Herlien) * Initial revision */ /****************************************************************************/ #include /* Standard I/O */ #include /* For exit() */ #include /* MBARI type definitions */ #include /* MBARI constants */ #include /* Time */ #include /* OASIS controller definitions */ #include /* for memcpy() */ #include /* for sqrt() */ #include /* for isspace() */ #include /* for strcmp() */ #define BUFSIZE 2048 /* Size of sample buffer */ #define ANALOG_CHANS 8 /* Number of analog channels */ #define PAR_CHAN 0 /* Analog channel number for PARs */ #define DEC(c) (((c) - ' ') & 0x3f) /* uudecode macro */ /********************************/ /* External Functions */ /********************************/ Extern FILE *openDataFile( char *name ); Extern Int32 get_begin_line( FILE *fd ); Extern Int32 getDataLine( Byte *buf, Int len, FILE *fd, FileType ftype ); Extern Int32 readDataFile( Byte *buf, Int len, FILE *fd, FileType ftype ); Extern char *get_can_name( char *dataname ); Extern Status read_cfg( char **cfgname ); Extern Status decode_atlas( Byte *atdata, Int atlen, AtlasDecode *adp, AtlasCal *acp ); Extern Status decode_ctd( Byte *ctddata, Int len, CTDDecode *cdp, CTDCal *ccp ); Extern Status decode_no3( Byte *no3data, Int len, No3Decode *no3dp, No3Cal *no3cp ); Extern Status decode_prr( Byte *spdata, Int len, PrrDecode *sdp, SpecCal *scp ); Extern Status decode_spectro( Byte *spdata, Int splen, SpecDecode *sdp, SpecCal *scp ); Extern Status decode_satlantic( Byte *satdata, Int len, SatlanticDecode sdp, SatlanticCal *scp ); Extern Status decode_ac9( Ac9Data *ac9data, Int len, Ac9Decode *ac9 ); Extern Nat16 getIntelword( Byte *p ); Extern Nat32 getIntellong( Byte *p ); Extern Nat16 getMotword( Byte *p ); Extern Nat16 getHdrWord( Byte *p, FileType ftype ); Extern Nat32 getHdrLong( Byte *p, FileType ftype ); #ifdef WIN32 Extern Int getopt( Int argc, char **argv, char *fmt ); #endif /********************************/ /* External Data */ /********************************/ Extern char *optarg; /* Option argument from getopt() */ Extern Int optind; /* Option index from getopt() */ Extern AtlasCal atlas_cal; /* ATLAS calibration */ Extern Analog analog[]; /* Analog calibration */ Extern CTDCal ctd_cal[]; /* Structs to hold CTD calibrations */ Extern No3Cal no3_cal[]; /* Structs to hold NO3 calibrations */ Extern SpecCal spec_cal[]; /* Structs to hold Spect calibrations*/ Extern SatlanticCal satlantic_cal; /* Struct to hold Satlantic cal */ Extern GndFltCal gfCal[]; /* Gnd fault board cals */ Extern Int oasisAnalogChan; /* Analog channel number for oasis */ /********************************/ /* Global Data */ /********************************/ Global Int itime; /* Integer year/day as yyddd */ /********************************/ /* Module Local Data */ /********************************/ MLocal Byte buffer[BUFSIZE]; /* Decoded data buffer */ MLocal AtlasDecode atlas; /* Buffer for decoded ATLAS data */ MLocal FileType fileType = FT_UUENCODE; /* Input file type */ MLocal Int32 gmt_offset = 0; MLocal MBool dolocaltime = TRUE; /* Output local (not GMT) time */ MLocal MBool outputRaw = FALSE; /* Output raw binary */ MLocal MBool donumber = FALSE; /* Output log numbers */ MLocal MBool decode_all = TRUE; /* Decode all sensors */ MLocal MBool decode_sensor[SENSORS]; /* TRUE to decode particular sensor */ MLocal SpecDecode spec; /* Struct to hold decoded Spect data*/ MLocal PrrDecode specprr; /* Decoded PRR Spectro data */ /* File names */ MLocal char *cfgp = NULL; /* Ptr to name of OASIS config file */ MLocal char *sensor_names[] = { "Empty", "OASIS", "ATLAS", "OASIS", "PAR", "CTD", "Spectro", "ADCP", "GPS", "Modem", "pCO2", "CTD2", "CTD3", "Spectro10", "Spectro20", "Nitrate", "Nitrate2", "SpecPRR", "Satlantic", "GPS", "NRL", "Oxygen", "Fluorometer", "Transmissometer", "NO3", "NO3.2", "AC9", "CO2Pump", "H2OPump", "Shutter0", "Shutter1", "SpecPRRVolts", "Metsys", "TString", "GF" }; MLocal char *ac9ChanNames[] = { "a650", "a676", "a715", "c510", "c555", "c630", "a412", "a440", "a488", "c650", "c676", "c715", "a510", "a555", "a630", "c412", "c440", "c488" }; /********************************/ /* Forward Declarations */ /********************************/ MBool process_command_line ( Int argc, char **argv ); Void use_msg( char *s ); Void decode_file( char *s ); Void print_header( LogRecHdr *hdrp, char *ident ); Void printbytes( Byte *s, Int len ); Void printwords( Byte *p, Int len ); Void print_ascii( Int len, MBool strip_nl, MBool convert_cr ); Void print_analog( Int chan, Int nchans ); Void sensor_error( Status err ); Status print_ctd( Int len, CTDCal *ccp ); Status print_gps( Int len ); Status print_gps_type2( Int len ); Status print_spec( Int len, SpecCal *scp ); Status print_spec_prr( Int len, SpecCal *scp ); Status print_satlantic( Int len, SatlanticCal *scp ); Status print_adcpv1( Void ); Status print_ac9( Int len ); Status print_nitrate_decoded( Int len, No3Cal *no3cp ); Void print_shutter( Byte *p, Int len ); Void print_gndflt( Byte *p, Int len, GndFltCal *gfp ); Void print_tstring( char *buffer, Int len ); /************************************************************************/ /* Function : main */ /* Purpose : Main routine */ /* Inputs : argc, argv */ /* Outputs : none */ /************************************************************************/ Void main( Int argc, char *argv[] ) { Int i; char *filename, *cp; if ( !process_command_line(argc, argv) ) { use_msg(argv[0]); exit( 1 ); } for ( i = optind; i < argc; i++ ) { filename = argv[i]; get_can_name( filename ); cp = cfgp; if ( read_cfg(&cp) != OK ) printf("Can't read configuration file \"%s\"\n", cp); else decode_file( filename ); } exit( 0 ); } /* main() */ /************************************************************************/ /* Function : decode_file */ /* Purpose : Decode one data file, print results to stdout */ /* Inputs : File name */ /* Outputs : none */ /************************************************************************/ Void decode_file( char *filename ) { Int32 cc, len, len_got; FILE *fd; struct tm *tp; MBool did_err_msg; Status rtn; Int32 err, blknum; Nat32 diskerr; LogRecHdr hdr; if ( (fd = openDataFile(filename)) == (FILE *)NULL ) return; blknum = 0; if ( fileType == FT_UUENCODE ) if ( (blknum = get_begin_line(fd)) < 0 ) { printf("No begin line in %s\n", filename); fclose( fd ); return; } else if (donumber) printf("Block %d\n", blknum); did_err_msg = FALSE; while ( (cc = getDataLine(buffer, sizeof(buffer), fd, fileType)) != EOF ) { if ( (cc == UUEND) && (fileType == FT_UUENCODE) ) { blknum = get_begin_line(fd); if ( blknum < 0 ) break; else { if (donumber) printf("Block %d\n", blknum); continue; } } if ( cc == 0 ) continue; did_err_msg = FALSE; hdr.log_type = buffer[0]; hdr.log_nmbr = getHdrWord(&buffer[1], fileType); hdr.log_len = getHdrWord(&buffer[3], fileType); hdr.log_time = getHdrLong(&buffer[5], fileType); tp = gmtime( (time_t *)&hdr.log_time ); itime = (1000 * tp->tm_year) + tp->tm_yday + 1; len_got = cc - 9; /* compute amount of log data gotten*/ if ( len_got > 0 ) memmove( buffer, buffer + 9, sizeof(buffer) - 9 ); else if ( len_got < 0 ) /* Move log data to start of buffer*/ { printf("Incomplete record header\n"); continue; } if ( (len = hdr.log_len) >= (Int32)sizeof(buffer) ) { /* Get size of log data */ len = sizeof(buffer); printf("Record too long in %s, block %d record %d. Truncating.\n", filename, blknum, hdr.log_nmbr); continue; } if ( len_got < len ) { len_got += readDataFile(buffer+len_got, len-len_got, fd, fileType); if ( len_got != len) { if ( !did_err_msg ) printf("Bad record in %s block %d record %d\n", filename, blknum, hdr.log_nmbr); did_err_msg = TRUE; continue; } did_err_msg = FALSE; } if ( !decode_all && !((hdr.log_type < SENSORS) && decode_sensor[hdr.log_type]) ) continue; if ( hdr.log_type < SENSORS ) print_header( &hdr, sensor_names[hdr.log_type] ); if ( outputRaw ) { if ( hdr.log_type == LOG_ERROR ) print_header( &hdr, "Error" ); printbytes( buffer, len ); continue; } switch( hdr.log_type ) { case LOG_EMPTY: printbytes(buffer, len); break; case OASIS_STAT: if ( getIntelword(buffer) ) printf("On\n"); else printf("Off\n"); break; case ATLAS: if ( (rtn = decode_atlas(buffer, len, &atlas, &atlas_cal)) != OK ) { sensor_error( rtn ); break; } printf("Time %9.5f Air %6.3f SST %6.3f\n", atlas.atd_time, atlas.atd_air, atlas.atd_sst); printf(" "); for ( cc = 0; cc < TEMPS; cc++ ) printf("%6.3f ", atlas.atd_temp[cc]); printf("\n Press %6.2f %6.2f RH %5.2f", atlas.atd_press[0], atlas.atd_press[1], atlas.atd_rh); printf(" Wind %6.3f m/s toward %5.1f\n", atlas.atd_windspd, atlas.atd_winddir); printf(" Compass %3.0f Vane %3.0f Raw dirctn %3.0f Raw speed %5.2f\n", atlas.atd_compass, atlas.atd_vane, atlas.atd_rawdir, atlas.atd_rawspeed); break; case OASIS_CAN: print_analog( oasisAnalogChan, len/2 ); break; case PAR: print_analog( PAR_CHAN, len/2 ); break; case CTD: print_ctd( len, &ctd_cal[CTD_CAL] ); break; case CTD2: print_ctd( len, &ctd_cal[CTD2_CAL] ); break; case CTD3: print_ctd( len, &ctd_cal[CTD3_CAL] ); break; case SPECTRO: print_spec( len, &spec_cal[SPECTRO_CAL] ); break; case SPECTRO2: print_spec( len, &spec_cal[SPECTRO2_CAL] ); break; case SPECTRO3: print_spec( len, &spec_cal[SPECTRO3_CAL] ); break; case SPEC_PRR: print_spec_prr( len, &spec_cal[SPECPRR_CAL] ); break; case ADCP: print_adcpv1(); printbytes( buffer, len ); break; case GPS: print_gps( len ); break; case GPS_TYPE2: print_gps_type2( len ); break; case PCO2: print_ascii(len, TRUE, FALSE); break; case NO3: print_ascii(len, FALSE, FALSE); print_nitrate_decoded( len, &no3_cal[NO3_CAL] ); break; case NO32: print_ascii(len, FALSE, FALSE); print_nitrate_decoded( len, &no3_cal[NO3_CAL2] ); break; case SATLANTIC: print_satlantic( len, &satlantic_cal ); break; case NRL: print_ascii(len, FALSE, FALSE); break; case O2: print_ascii(len, TRUE, FALSE); break; case FLUOR: print_analog( FLUOR_CHAN, len/2 ); break; case TRANSMISS: print_analog( TRANSMISS_CHAN, len/2 ); break; case CO2_PUMP: if ( buffer[0] ) printf("On\n"); else printf("Off\n"); break; case H2O_PUMP: printf("\n"); break; case AC9: print_ac9( len ); break; case SHUTTER0: case SHUTTER1: print_shutter(buffer, len); break; case METSYS: print_ascii(len, TRUE, FALSE); break; case TSTRING: print_tstring(buffer, len); break; case GNDFAULT: print_gndflt( buffer, len, gfCal ); break; case LOG_ERROR: cc = getIntelword(buffer); if ( cc & 0x8000 ) { cc &= 0x7fff; print_header(&hdr, "OASIS Error"); if ( cc & RAM_ERR ) printf("RAM_init "); if ( cc & LOG_ERR ) printf("LOG_memory_bad "); if ( cc & CLOCK_ERR ) printf("Clock_failure "); if ( cc & INT_ERR ) printf("Spurious_interrupt "); if ( cc & RESTART_ERR ) printf("Restarted "); if ( cc & COMM_ERR ) printf("24hr_silence"); if ( cc & DISK_ERR ) printf("Disk Write Error "); if ( cc & ARGOS_ERR ) printf("ARGOS Error "); printf("\n"); } else { if ( cc >= SENSORS ) printf("Unknown Error type\n"); else { printf( sensor_names[cc] ); print_header( &hdr, " Error" ); err = (Int16)getIntelword( buffer + 2 ); switch ( err ) { case TMOUT_ERR: printf("Timeout\n"); break; case MALLOC_ERR: printf("No malloc space\n"); break; case NO_DATA: printf("No Data\n"); break; case BAD_DATA: printf("Bad Data\n"); break; case CKSUM_ERR: printf("Checksum Error\n"); break; case SYNC_ERR: printf("Sync Error\n"); break; case NOT_AVAIL_ERR: printf("Not Available\n"); break; case GPS_OOPS: if ( cc == GPS_TYPE2 ) { printf("No first fix.\n"); break; } default: printf("Unknown type %#x\n", (int)err); } } } break; case LOG_COMMENT: print_header( &hdr, "Comment"); for ( cc = 0; cc < len; cc++ ) putchar( buffer[cc] ); printf("\n"); break; case LOG_BIN: switch( cc = getIntelword(buffer) ) { case SPECTRO: case SPECTRO2: case SPECTRO3: printf( sensor_names[cc] ); print_header( &hdr, " V cmd" ); printbytes( &buffer[2], len - 2 ); break; default: print_header( &hdr, "Binary Comment" ); printbytes( buffer, len ); } break; case LOG_DISK_ERROR: print_header( &hdr, "Disk Error"); diskerr = (Nat32)getIntelword( buffer ); printf( "Rtn code %#x\n", (int)diskerr ); break; default: print_header( &hdr, "Unknown" ); printf("\n"); } } fclose( fd ); } /* decode_file() */ /************************************************************************/ /* Function : use_msg */ /* Purpose : Print Usage Message */ /* Inputs : Name of program */ /* Outputs : None */ /************************************************************************/ Void use_msg( char *s ) { fprintf( stderr, "Usage: %s [-c cfg_file] [-i instrument] [-g[offset]] [-h] [-l] [-n]\n", s ); fprintf( stderr, "-c cfg_file specifies a configuration file\n"); fprintf( stderr, "-i instrument decodes data only for specified instrument\n"); fprintf( stderr, "-g prints data in fixed offset (in hours) from GMT time\n" ); fprintf( stderr, " (e.g. -g0 prints in GMT time)\n"); fprintf( stderr, "-b interprets data as binary file (default is uuencode)\n" ); fprintf( stderr, "-h interprets data as hex file (default is uuencode)\n" ); fprintf( stderr, "-l prints data in local time (default)\n"); fprintf( stderr, "-n prints record numbers\n"); fprintf( stderr, "-r outputs raw data\n"); } /* use_msg() */ /************************************************************************/ /* Function : process_command_line */ /* Purpose : Read the arguments from the command line */ /* Inputs : argc, argv from main() routine */ /* Outputs : TRUE if arguments OK, else FALSE */ /************************************************************************/ MBool process_command_line ( Int argc, char **argv ) { Int i; for ( i = 0; i < SENSORS; i++ ) decode_sensor[i] = FALSE; while ( (i = getopt(argc, argv, "bc:g:hi:lnr")) != EOF ) switch( i ) { case 'b': break; case 'c': cfgp = optarg; break; case 'g': dolocaltime = FALSE; putenv( "TZ=GMT0" ); gmt_offset = atoi(optarg); break; case 'h': fileType = FT_HEX; break; case 'i': for ( i = 0; i < SENSORS; i++ ) if ( strcasecmp(optarg, sensor_names[i]) == 0 ) { decode_all = FALSE; decode_sensor[i] = TRUE; } break; case 'l': dolocaltime = TRUE; break; case 'n': donumber = TRUE; break; case 'r': outputRaw = TRUE; break; default: return( FALSE ); } return( TRUE ); } /* process_command_line() */ /************************************************************************/ /* Function : print_header */ /* Purpose : Print log header */ /* Inputs : Identification string */ /* Outputs : None */ /************************************************************************/ Void print_header( LogRecHdr *hdrp, char *ident ) { struct tm *tp; time_t logTime; logTime = (time_t)hdrp->log_time; if ( dolocaltime ) tp = localtime( &logTime ); else { logTime += (3600 * gmt_offset); tp = gmtime( &logTime ); } printf( "%-8s ", ident ); if ( donumber ) printf("%4d ", hdrp->log_nmbr); printf("%02d/%02d/%02d %02d:%02d:%02d ", tp->tm_year, tp->tm_mon+1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec); } /* print_header() */ /************************************************************************/ /* Function : printbytes */ /* Purpose : Print data stream as a stream of bytes */ /* Inputs : Byte ptr, length */ /* Outputs : None */ /************************************************************************/ Void printbytes( Byte *s, Int len ) { Int i, curlen; for ( i = 0; i < len; ) { printf("\n "); curlen = len - i; if ( curlen > 32 ) curlen = 32; while ( curlen-- ) printf("%02x", s[i++]); } printf("\n"); } /* printbytes() */ /************************************************************************/ /* Function : printwords */ /* Purpose : Print data stream as a stream of words */ /* Inputs : Byte ptr, length */ /* Outputs : None */ /************************************************************************/ Void printwords( Byte *p, Int len ) { Int i; for ( i = 0; i < len; i += 2 ) printf( "%04x ", getIntelword(p + i) ); printf("\n"); } /* printwords() */ /************************************************************************/ /* Function : print_ascii */ /* Purpose : Print data stream as ascii stream */ /* Inputs : Length, MBool to strip CR & LF */ /* Outputs : None */ /************************************************************************/ Void print_ascii( Int len, MBool strip_nl, MBool convert_cr ) { char *p; buffer[len] = '\0'; if ( strip_nl ) { while ( (p = strchr((char *)buffer, '\r')) != NULL ) *p = ' '; while ( (p = strchr((char *)buffer, '\n')) != NULL ) *p = ' '; } if ( convert_cr ) { while ( (p = strchr((char *)buffer, '\r')) != NULL ) *p = '\n'; } printf("\n%s\n", buffer); } /* print_ascii() */ /************************************************************************/ /* Function : print_analog */ /* Purpose : Print data stream as analog channel data */ /* Inputs : First channel number, number of channels */ /* Outputs : None */ /************************************************************************/ Void print_analog( Int chan, Int nchans ) { Int i; Reg Analog *ap; for ( i = 0; i < nchans; i++ ) { ap = &analog[chan + i]; printf("%6.2f %s ", (((ap->a * (double)getIntelword(&buffer[2*i])) + ap->b) * ap->c) + ap->d, ap->units); } printf("\n"); } /* print_analog() */ /************************************************************************/ /* Function : print_gps */ /* Purpose : Print buffer as GPS data */ /* Inputs : Length of buffer */ /* Outputs : OK or SIZE_ERR */ /************************************************************************/ Status print_gps( Int len ) { Int32 lat, lon; Nat32 var; Nat16 samples, status; char lathem, lonhem; if ( len != 16 ) { printf("Bad GPS record size, was %d, should be 16\n",len); return( SIZE_ERR ); } lat = getIntellong(buffer); lon = getIntellong(&buffer[4]); var = getIntellong(&buffer[8]); samples = getIntelword(&buffer[12]); status = getIntelword(&buffer[14]); lathem = 'N'; lonhem = 'W'; if ( lat < 0 ) { lat = -lat; lathem = 'S'; } if ( lon < 0 ) { lon = -lon; lonhem = 'W'; } printf("%3d:%02d.%03d%c %3d:%02d.%03d%c StdDev %.2f Samp %d Stat %04x\n", (int)(lat/60000), (int)((lat/1000)%60), (int)(lat%1000), lathem, (int)(lon/60000), (int)((lon/1000)%60), (int)(lon%1000), lonhem, sqrt((double)var), samples, status); return( OK ); } /* print_gps() */ /************************************************************************/ /* Function : print_gps_type2 */ /* Purpose : Print buffer as GPS data */ /* Inputs : Length of buffer */ /* Outputs : OK or SIZE_ERR */ /************************************************************************/ Status print_gps_type2( Int len ) { Int32 lat, lon; Nat32 var; Nat16 samples, totTime, status; if ( len != 18 ) { printf("Bad GPS record size, was %d, should be 18\n",len); return( SIZE_ERR ); } lat = getIntellong(buffer); lon = getIntellong(&buffer[4]); var = getIntellong(&buffer[8]); samples = getIntelword(&buffer[12]); totTime = getIntelword(&buffer[14]); status = getIntelword(&buffer[16]); printf("%10.5f %10.5f StdDev %.2f Samp %d Time %d Stat %04x\n", lat/10000000., lon/10000000., sqrt((double)var), samples, totTime, status); return( OK ); } /* print_gps_type2() */ /************************************************************************/ /* Function : print_ctd */ /* Purpose : Print buffer as CTD data */ /* Inputs : Length of buffer, CTD calibration struct */ /* Outputs : OK or Error type */ /************************************************************************/ Status print_ctd( Int len, CTDCal *ccp ) { CTDDecode ctd; /* Struct to hold decoded CTD data */ Status rtn; /* Return code */ if ( (rtn = decode_ctd(buffer, len, &ctd, ccp)) != OK ) { sensor_error( rtn ); return( rtn ); } printf("Num %d Press %6.3f Temp %6.3f Cond %6.3f\n", ctd.ctd_sample, ctd.ctd_press, ctd.ctd_temp, ctd.ctd_cond); printf(" Salinity %6.4f Transmiss %6.4f Fluor %6.4f\n", ctd.ctd_sal, ctd.ctd_trans, ctd.ctd_fluor); return( OK ); } /* print_ctd() */ /************************************************************************/ /* Function : print_spec */ /* Purpose : Print buffer as Spectroradiometer data */ /* Inputs : Length of buffer, Spectro calibration struct */ /* Outputs : OK or Error type */ /************************************************************************/ Status print_spec( Int len, SpecCal *scp ) { Int i, j, n; /* Scratch */ Status rtn; /* Return code */ if ( (rtn = decode_spectro(buffer, len, &spec, scp)) != OK ) { sensor_error( rtn ); return( rtn ); } printf("Time %9.5f", spec.spc_day + (double)(spec.spc_sec)/86400.0); for ( i = 0, n = 100; i < SPEC_BANKS; i++ ) for ( j = 0; j < scp->spc_nchans[i]; j++ ) { if ( n >= 60 ) { printf("\n "); n = 0; } if ( scp->spc_cal[i][j].type > 0 ) n += printf("%5s %9.6f ", scp->spc_cal[i][j].name, spec.spc_chan[i][j].spc_mean); } printf("\n"); return( OK ); } /* print_spec() */ /************************************************************************/ /* Function : print_nitrate_decoded */ /* Purpose : Decode and print decoded nitrate data */ /* Inputs : Length, calibration struct */ /* Outputs : OK or Error type */ /************************************************************************/ Status print_nitrate_decoded( Int len, No3Cal *no3cp ) { Reg Byte *p, *q; /* Scratch ptrs */ No3Decode no3; /* Struct to hold decoded NO3 data */ Status rtn; /* Return code */ buffer[len] = '\0'; for ( p = buffer; p - buffer < len; p = q ) { /* Loop to decode one line at a time*/ while ( (p - buffer < len) && ((*p == '\r') || (*p == '\n')) ) p++; if ( (q = (Byte *)strchr((char *)p, '\r')) == NULL ) q = (Byte *)strchr((char *)p, '\n'); if ( (q != NULL) && (q - buffer < len) ) *q++ = '\0'; else q = p + strlen((char *)p) + 1; if ( (rtn = decode_no3(p, len, &no3, no3cp)) == OK ) { if ( no3cp->nc_format == NO3_DRIFT1 ) printf("%-.14s no3 %6.4f Temp %6.3f Salinity %6.4f Cond %6.4f\n", no3.no3_time, no3.no3_conc, no3.no3_temp, no3.no3_salinity, no3.no3_conductivity); else printf("%-.14s no3 %6.4f Temp %6.3f\n", no3.no3_time, no3.no3_conc, no3.no3_temp); } } return( OK ); } /* print_nitrate_decoded() */ /************************************************************************/ /* Function : print_spec_prr */ /* Purpose : Print buffer as PRR-600 Spectroradiometer data */ /* Inputs : Length of buffer, Spectro calibration struct */ /* Outputs : OK or Error type */ /************************************************************************/ Status print_spec_prr( Int len, SpecCal *scp ) { Int bank, chan, cursor; /* Bank, chan nums, cursor position*/ Status rtn; /* Return code */ if ( (rtn = decode_prr(buffer, len, &specprr, scp)) != OK ) { sensor_error( rtn ); return( rtn ); } for ( bank = 0, cursor = 100; bank < specprr.prr_nbanks; bank++ ) for ( chan = 0; (chan < specprr.prr_bank[bank].prr_nchans); chan++ ) { if ( cursor >= 60 ) { printf("\n "); cursor = 0; } if ( scp->spc_cal[bank][chan].type > 0 ) cursor += printf("%-5.5s %9.5f ", scp->spc_cal[bank][chan].name, specprr.prr_bank[bank].prr_chan[chan]); } printf("\n"); return( OK ); } /* print_spec_prr() */ /************************************************************************/ /* Function : print_satlantic */ /* Purpose : Print buffer as Satlantic spectroradiometer data */ /* Inputs : Length of buffer, Satlantic calibration struct */ /* Outputs : OK or Error type */ /************************************************************************/ Status print_satlantic( Int len, SatlanticCal *scp ) { Int chan, cursor; /* Channel number, cursor position */ Status rtn; /* Return code */ SatlanticDecode satlantic; /* Decoded Satlantic data */ if ( (rtn = decode_satlantic(buffer, len, satlantic, scp)) != OK ) { sensor_error( rtn ); return( rtn ); } for ( chan = 0, cursor = 80; chan < scp->sat_chans; chan++ ) { if ( cursor >= 64 ) { printf("\n "); cursor = 10; } cursor += printf("%s %9.6f ", scp->sat_cal[chan].sat_name, satlantic[chan]); } printf("\n"); return( OK ); } /* print_satlantic() */ /************************************************************************/ /* Function : print_adcpv1 */ /* Purpose : Print V1 voltage of ADCP */ /* Inputs : None */ /* Outputs : OK */ /************************************************************************/ #define V1_OFS 45 #define V1_MULT 0.05 Status print_adcpv1( Void ) { printf( " V1 %5.2f", V1_MULT * (double)((unsigned char)buffer[V1_OFS])); return( OK ); } /* print_adcpv1() */ /************************************************************************/ /* Function : print_ac9 */ /* Purpose : Print buffer as AC-9 data */ /* Inputs : Length of buffer */ /* Outputs : OK or Error type */ /************************************************************************/ Status print_ac9( Int len ) { Status rtn; Int chan; Ac9Decode ac9; if ( (rtn = decode_ac9((Ac9Data *)buffer, len, &ac9)) != OK ) { sensor_error( rtn ); return( rtn ); } printf( "%d samples Temp %8.4f\n", (int)ac9.ac9_samples, ac9.ac9_temp ); for ( chan = 0; chan < AC9_CHANS; chan++ ) { printf("%s %6.4f ", ac9ChanNames[chan], ac9.ac9_value[chan]); if ( (chan % 6) == 5 ) printf("\n"); } return( OK ); } /* print_ac9() */ /************************************************************************/ /* Function : print_shutter */ /* Purpose : Print shutter log record */ /* Inputs : Sensor, length */ /* Outputs : None */ /************************************************************************/ Void print_shutter( Byte *p, Int len ) { Word status; if ( len < (Int)(2 * sizeof(Word)) ) { printf("Bad record size, was %d, should be 4\n",len); return; } status = getIntelword( buffer + sizeof(Word) ); printf( "Pos %4d Stat %04x Shutter %2d Try %2d Rtn %2d ", getIntelword(buffer), status, ((status >> 12) & 7), (status & 0xff), ((status >> 8) & 0x0f) ); if ( status & 0x8000 ) printf( "open\n"); else printf( "close\n"); } /* print_shutter() */ /************************************************************************/ /* Function : print_gndflt */ /* Purpose : Print Ground Fault data */ /* Inputs : Buffer, length, calibr struct */ /* Outputs : None */ /************************************************************************/ Void print_gndflt( Byte *p, Int len, GndFltCal *gfp ) { Reg int i; Reg GndFltCal *gfPtr; Reg Nat16 raw; double value; for ( i = 0, gfPtr = gfp; i < MAX_GF_CALS; i++, gfPtr++ ) if ( gfPtr->cal_valid && (len >= (Int)(gfPtr->raw_offset + sizeof(Nat16))) ) { raw = getMotword( p + gfPtr->raw_offset ); value = (double)(raw - gfPtr->cal_offset) / gfPtr->cal_divisor; printf( "%s %5.2f %s\n", gfPtr->ident, value, gfPtr->units ); } printf("\n"); } /* print_gndflt() */ /************************************************************************/ /* Function : print_tstring */ /* Purpose : Print data from Inductive Modem Temperature String */ /* Inputs : Buffer, Length */ /* Outputs : None */ /************************************************************************/ Void print_tstring( char *buffer, Int len ) { char *datap, *linep; Reg Int32 cnt; Int32 dummy1; Flt32 dummy2; buffer[len] = '\0'; printf("\n"); for ( datap = buffer, cnt = 0; *datap && (cnt < len); ) { linep = datap; for ( ; *datap && (cnt < len); datap++, cnt++ ) if ( (*datap == '\r') || (*datap == '\n') ) { *datap++ = '\0'; cnt++; break; } if ( sscanf(linep, " %d, %g", &dummy1, &dummy2) == 2 ) printf("%s\n", linep); } } /* print_tstring() */ /************************************************************************/ /* Function : sensor_error */ /* Purpose : Print error in decoding sensor data */ /* Inputs : Error type */ /* Outputs : None */ /************************************************************************/ Void sensor_error( Status err ) { switch( err ) { case ERROR: printf("Error\n"); break; case SIZE_ERR: printf("Wrong size\n"); break; case CHKSUM_ERR: printf("Checksum error\n"); break; case FMT_ERR: printf("Bad data format\n"); break; default: printf("Unknown error\n"); } } /* sensor_error() */ @ 2.8 log @Archiving sources prior to porting to DOS/Windows @ text @d4 1 a4 1 /* $Header: decode.c,v 2.7 97/09/09 09:51:40 bobh Exp $ */ d9 1 a9 1 /* $Revision: 2.7 $ */ d15 3 d58 3 a60 2 #include /* MBARI type definitions */ #include /* MBARI constants */ a61 1 #include /* Time */ d99 1 d102 3 a112 1 Extern Int opterr; /* getopt() error flag */ d119 2 a120 1 Extern Int32 oasisAnalogChan; /* Analog channel number for oasis */ a135 1 MLocal MBool dolocaltime = TRUE; /* Output local (not GMT) time */ d138 2 d154 2 a155 1 "H2OPump", "Shutter0", "Shutter1" }; d172 2 a173 2 Void print_ascii( Int len, MBool strip_nl ); Void print_analog( Nat16 chan, Int nchans ); d185 2 d196 1 a196 1 main( Int argc, char **argv ) d237 1 a237 1 Int32 err; d244 1 a244 6 if ( (fileType == FT_UUENCODE) && (get_begin_line(fd) < 0) ) { printf("No begin line in %s\n", filename); fclose( fd ); return; } d246 10 d262 2 a263 1 if( get_begin_line(fd) < 0 ) d266 3 d270 1 d297 3 a299 1 printf("Record too long in %s. Truncating.\n", filename); d308 2 a309 1 printf("Bad record in %s\n", filename); d323 8 d415 1 a415 1 print_ascii(len, TRUE); d419 1 a419 1 print_ascii(len, FALSE); d424 1 a424 1 print_ascii(len, FALSE); d433 1 a433 1 print_ascii(len, FALSE); d437 1 a437 1 print_ascii(len, TRUE); d468 12 d498 4 d615 1 d619 1 d638 1 a638 1 while ( (i = getopt(argc, argv, "c:g:hi:ln")) != EOF ) d641 3 d675 4 d765 1 a765 1 /* Inputs : Length, MBool to strip CR & LF */ d769 1 a769 1 print_ascii( Int len, MBool strip_nl ) d784 5 a788 1 printf("%s\n", buffer); d790 2 d802 1 a802 1 print_analog( Nat16 chan, Int nchans ) d1181 63 d1275 1 @ 2.7 log @Archiving various changes @ text @d4 1 a4 1 /* $Header: decode.c,v 2.6 96/05/30 15:07:25 bobh Exp $ */ d9 1 a9 1 /* $Revision: 2.6 $ */ d15 3 d142 1 a142 1 { "Empty", "Time", "ATLAS", "OASIS", "PAR", "CTD", "Spectro", "ADCP", d305 5 a309 2 case TIME: printbytes(buffer, len); d1097 1 a1097 1 if ( len < (2 * sizeof(Word)) ) @ 2.6 log @Update for version in use during 1995-6 deployment @ text @d4 1 a4 1 /* $Header: decode.c,v 2.5 94/12/15 10:58:59 hebo Exp $ */ d9 1 a9 1 /* $Revision: 2.5 $ */ d15 3 a60 1 #define UUBUFSIZE 512 /* Size of uu decode buffer */ a61 2 #define NAMESIZE 256 /* Space allocated for file names */ #define UUERROR (-2) /* Error return from uuread() */ a63 2 #define OASIS_CHAN 2 /* Analog chan num for OASIS stuff */ #define CFG_DIR "/oasis/cfg" d71 5 a77 1 Extern Status read_atlas_cal( char *name ); a79 1 Extern Status read_ctd_cal( char *name, CTDCal *ccp ); a81 1 Extern Status read_no3_cal( char *name, No3Cal *no3cp ); a83 1 Extern Status read_spec_cal( char *name, SpecCal *scp ); d85 3 a87 1 SpecPRRDecode sd, SpecCal *scp ); d91 4 d104 7 a117 7 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 char *rcdfile = "/oasis/raw/oasis.rcd"; a124 3 MLocal Byte uubuf[UUBUFSIZE]; /* Buffer for raw uuencoded data */ MLocal LogRecHdr hdr; /* Logging record header */ MLocal time_t oasis_time; /* Time of OASIS data in time_t fmt */ d126 6 a131 5 MLocal Boolean dolocaltime = TRUE; /* Output local (not GMT) time */ MLocal Boolean donumber = FALSE; /* Output log numbers */ MLocal char tmp_buf[NAMESIZE]; /* Misc temporary buffer */ MLocal Boolean decode_all = TRUE; /* Decode all sensors */ MLocal Boolean decode_sensor[SENSORS]; /* TRUE to decode particular sensor */ d133 1 a133 1 MLocal SpecPRRDecode specprr; /* Decoded PRR Spectro data */ a136 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 */ d142 2 a143 1 "Fluorometer", "Transmissometer", "NO3", "NO3.2", "AC9" }; d145 3 a148 3 /********************************/ /* External Functions */ /********************************/ a149 6 Extern FILE *uuopen( char *name ); Extern Int32 get_begin_line( FILE *fd ); Extern Int uuread( Byte *buf, Int len, FILE *fd ); Extern Int uugetline( Byte *buf, Int len, FILE *fd ); d154 1 a154 1 Boolean process_command_line ( Int argc, char **argv ); d157 1 a157 3 Nat16 getIntelword( Byte *p ); Nat32 getIntellong( Byte *p ); Void print_header( char *ident ); d160 1 a160 1 Void print_ascii( Int len, Boolean strip_nl ); d171 2 d218 1 a218 1 Int cc, len, len_got; d221 1 a221 1 Boolean did_err_msg; d223 3 d227 1 a227 1 if ( (fd = uuopen(filename)) == (FILE *)NULL ) d230 1 a230 1 if( get_begin_line(fd) < 0 ) d239 1 a239 1 while ( (cc = uugetline(buffer, sizeof(buffer), fd)) != EOF ) d241 1 a241 1 if ( cc == UUEND ) d255 4 a258 5 hdr.log_nmbr = getIntelword(&buffer[1]); hdr.log_len = getIntelword(&buffer[3]); hdr.log_time = getIntellong(&buffer[5]); oasis_time =(time_t)hdr.log_time; tp = gmtime( &oasis_time ); d262 7 a268 2 memmove( buffer, buffer + 9, sizeof(buffer) - 9 ); /* Move log data to start of buffer*/ d270 1 a270 1 if ( (len = hdr.log_len) > sizeof(buffer) ) d278 2 a279 1 if ( (len_got += uuread(buffer+len_got, len-len_got, fd)) != len) d294 1 a294 1 print_header( sensor_names[hdr.log_type] ); d303 1 a303 3 oasis_time = (time_t)getIntellong( buffer ); tp = gmtime( &oasis_time ); printf("%s", asctime(tp)); d328 1 a328 1 print_analog( OASIS_CHAN, len/2 ); d410 11 d425 5 d435 1 a435 1 print_header("OASIS Error"); d457 42 a498 2 print_header( " Error" ); printf("\n"); d504 1 a504 1 print_header("Comment"); d517 1 a517 1 print_header( " V cmd" ); d522 1 a522 1 print_header( "Binary Comment" ); d527 6 d534 1 a534 1 print_header("Unknown"); d554 10 a563 1 "Usage: %s [-c cfg_file] [-i instrument] [-g] [-l] [-n]", s ); d574 1 a574 1 Boolean d577 1 a577 1 Int i, baud; d582 1 a582 1 while ( (i = getopt(argc, argv, "c:gi:ln")) != EOF ) d591 2 d595 4 d601 1 a601 1 if ( strcmp(optarg, sensor_names[i]) == 0 ) a625 54 /* 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 ) { Nat32 rtn; rtn = (Nat16)(*p << 8); rtn += (Nat16)(p[1]); return( rtn ); } /* getMotword() */ /************************************************************************/ d632 1 a632 1 print_header( char *ident ) d635 1 d637 1 d639 1 a639 1 tp = localtime( (time_t *)&hdr.log_time ); d641 4 a644 1 tp = gmtime( (time_t *)&hdr.log_time ); d647 1 a647 1 printf("%4d ", hdr.log_nmbr); d689 1 a689 1 Int i, curlen, wrd; d692 1 a692 4 { wrd = getIntelword( p + i ); printf("%4d ", wrd); } d702 1 a702 1 /* Inputs : Length, Boolean to strip CR & LF */ d706 1 a706 1 print_ascii( Int len, Boolean strip_nl ) d793 3 a795 3 lat/60000, (lat/1000)%60, lat%1000, lathem, lon/60000, (lon/1000)%60, lon%1000, lonhem, sqrt((double)var), samples, status); d841 1 a841 1 /* Outputs : OK or Error type d946 2 d963 1 a963 1 if ( (rtn = decode_prr(buffer, len, specprr, scp)) != OK ) d969 2 a970 2 for ( bank = 0, cursor = 100; bank < SPEC_BANKS; bank++ ) for ( chan = 0; (chan < scp->spc_nchans[bank]); chan++ ) d980 1 a980 1 specprr[bank][chan]); d1065 1 a1065 1 printf( "%d samples ", ac9.ac9_samples ); d1069 1 a1069 2 if ( ((chan + 3) % 7) == 0 ) printf("\n "); d1071 2 a1072 1 printf("%8.4f ", ac9.ac9_value[chan]); a1074 2 printf( "\n Temp %8.4f\n", ac9.ac9_temp ); d1078 31 @ 2.5 log @Accumlated minor changes, mainly due to move to tsunami @ text @d4 1 a4 1 /* $Header: decode.c,v 2.4 94/01/21 14:35:34 hebo Exp $ */ d9 1 a9 1 /* $Revision: 2.4 $ */ d15 3 d81 3 d85 1 a85 3 Extern Status decode_spectro( Byte *spdata, Int splen, SpecDecode *sdp, SpecCal *scp ); Extern Int decode_prr( Byte *spdata, Int len, d87 3 d107 1 d109 1 d111 1 a111 1 Global Analog analog[ANALOG_CHANS]; /* Analog calibration */ d141 2 a142 1 "Nitrate", "Nitrate2", "SpecPRR" }; d150 1 d166 1 d172 2 a173 1 Status print_spectro( Int len, SpecCal *scp ); d175 1 d177 1 d223 1 a223 1 Int cc, len; d232 7 d241 1 a241 1 while ( (cc = uugetline(buffer, 9, fd)) != EOF ) d243 8 a253 7 if ( cc != 9 ) { if ( !did_err_msg ) printf("Bad record header in %s\n", filename); did_err_msg = TRUE; continue; } d264 7 a270 3 if ( (cc = hdr.log_len) > BUFSIZE ) { cc = BUFSIZE; d274 1 a274 1 if ( (len = uuread(buffer, cc, fd)) != cc) d276 8 a283 4 if ( !did_err_msg ) printf("Bad record in %s\n", filename); did_err_msg = TRUE; continue; a284 1 did_err_msg = FALSE; d371 4 d381 1 d386 1 d389 24 d471 2 a472 1 print_header("Unknown record type"); d652 22 d766 1 a766 1 printf("%3d:%02d.%03d%c %3d:%02d.%03d%c Var %.2f Samp %d Stat %04x\n", d777 35 d881 43 d932 2 a933 1 Int i, j, n, rtn; /* Scratch, return code */ d935 1 a935 1 if ( (rtn = decode_prr(buffer, len, specprr, scp)) <= 0 ) d941 2 a942 2 for ( i = 0, n = 100; i < SPEC_BANKS; i++ ) for ( j = 0; (j < scp->spc_nchans[i]) && (rtn > 0); j++, rtn-- ) d944 1 a944 1 if ( n >= 60 ) d947 1 a947 1 n = 0; d949 4 a952 3 if ( scp->spc_cal[i][j].type > 0 ) n += printf("%5s %9.5f ", scp->spc_cal[i][j].name, specprr[i][j]); d963 37 d1016 36 @ 2.4 log @Added support for date ranges in cfg file @ text @d4 1 a4 1 /* $Header: decode.c,v 2.3 94/01/17 11:09:31 hebo Exp $ */ d9 1 a9 1 /* $Revision: 2.3 $ */ d15 3 d62 1 a62 1 #define CFG_DIR "/usr/local/oasis/cfg" d70 2 d103 1 a124 1 MLocal char cfg_file[NAMESIZE]; /* Name of OASIS configuration file */ a150 1 Status read_cfg( char **cfgname, char *dataname ); d186 1 d188 1 a188 1 if ( read_cfg(&cp, filename) != OK ) @ 2.3 log @Misc changes @ text @d4 1 a4 1 /* $Header: decode.c,v 2.2 93/09/17 10:59:04 hebo Exp $ */ d9 1 a9 1 /* $Revision: 2.2 $ */ d15 3 d68 2 a69 1 Extern Status decode_atlas( Byte *atdata, Int atlen, AtlasDecode *adp ); d90 11 a108 3 MLocal CTDCal ctd_cal[NUM_CTDS]; /* Structs to hold CTD calibrations */ MLocal SpecCal spec_cal[NUM_SPECS]; /* Structs to hold Spect calibrations*/ MLocal Analog analog[ANALOG_CHANS]; /* Analog calibration */ d131 9 a146 3 FILE *uuopen( char *name ); Int uuread( Byte *buf, Int len, FILE *fd ); Int uugetline( Byte *buf, Int len, FILE *fd ); d153 1 a153 1 Void print_error( Status err ); d232 5 a236 2 cc = hdr.log_len; if ( cc > BUFSIZE ) d271 1 a271 1 if ( (rtn = decode_atlas(buffer, len, &atlas)) != OK ) d273 1 a273 1 print_error( rtn ); d300 1 a300 1 print_ctd( len, &ctd_cal[0] ); d304 1 a304 1 print_ctd( len, &ctd_cal[1] ); d308 1 a308 1 print_ctd( len, &ctd_cal[2] ); a481 126 /* Function : uuopen */ /* Purpose : Open a uuencoded file, check its "begin" line */ /* Inputs : Name of file */ /* Outputs : FILE pointer */ /************************************************************************/ FILE *uuopen( char *name ) { FILE *fd; char *p; if ( (fd = fopen(name, "rb")) == (FILE *)NULL ) printf("Cannot open %s\n", name); else { p = (char *)uubuf; while ( fgets(p, sizeof(uubuf), fd) != NULL ) { while ( isspace(*p) ) p++; if (strncmp(p, "begin ", 6) == 0) return( fd ); } printf("No begin line in file %s\n", name); } return( (FILE *)NULL ); } /* uuopen() */ /************************************************************************/ /* 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( Byte *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 : uugetline */ /* Purpose : Read and decode one line from a uuencoded file */ /* Inputs : Buffer for resulting data, size of buffer, FILE ptr */ /* Outputs : Number characters read, UUERROR if error, or EOF */ /************************************************************************/ Int uugetline( Byte *buf, Int len, FILE *fd ) { Int uulen, i; Byte *p, *q; char *p1; if ( fgets((char *)uubuf, sizeof(uubuf), fd) == NULL ) return( EOF ); if (strncmp((char *)uubuf, "end", 3) == 0) return( EOF ); 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 ); p = &uubuf[1]; q = buf; for ( i = uulen; i > 0; i -= 3 ) { uudecode( p, q, i ); p += 4; q += 3; } return( uulen ); } /* uugetline() */ /************************************************************************/ /* 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 */ /* Comment : OASIS records should always begin and end at new line */ /* This function calls uugetline() for the appropriate */ /* number of bytes, and returns UUERROR if size wrong */ /************************************************************************/ Int uuread( Byte *buf, Int len, FILE *fd ) { Int i, left; Byte *p; for ( p = buf, left = len; left > 0; ) { if ( (i = uugetline(p, left, fd)) <= 0 ) return( i ); left -= i; p += i; if ( left < 0 ) return( UUERROR ); } return( len ); } /* uuread() */ /************************************************************************/ d702 1 a702 1 print_error( rtn ); d731 1 a731 1 print_error( rtn ); d770 1 a770 1 print_error( rtn ); d814 2 a815 2 /* Function : print_error */ /* Purpose : Print error in decoding data */ d820 1 a820 1 print_error( Status err ) d844 1 a844 107 } /* print_error() */ /************************************************************************/ /* 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 */ /************************************************************************/ Status read_cfg( char **cfgname, char *dataname ) { FILE *fp; char *p, *q; char unitname[UNITNAMELEN]; Int channel, i; unsigned j; double a, b, c, d; if ( *cfgname == NULL ) { if ( (p = strrchr(dataname, '/')) == NULL ) p = dataname; else p++; 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; } if ( (fp = fopen(*cfgname, "rb")) == (FILE *)NULL ) return( ERROR ); memset( (void *)&analog, 0, sizeof(analog) ); while ( fgets(tmp_buf, sizeof(tmp_buf), fp) != NULL ) { /* Read one line of input*/ if ( (i = sscanf(tmp_buf, " analog %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 ); } else if ( sscanf(tmp_buf, " atlas %s", atlas_file) == 1 ) { if ( read_atlas_cal(atlas_file) != OK ) printf("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 ) printf("Can't read 20 meter CTD calibr 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 ) printf("Can't read M2 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 ) printf("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 ) printf("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 ) printf("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 ) printf("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 ) printf("Can't read SpecPRR calibration file \"%s\"\n", spec_file); } } fclose( fp ); return( OK ); } /* read_cfg() */ @ 2.2 log @Changed method of finding config file based on name of data file. @ text @d4 1 a4 1 /* $Header: decode.c,v 2.1 92/09/04 13:38:18 hebo Exp $ */ d9 1 a9 1 /* $Revision: 2.1 $ */ d15 3 d72 2 d75 1 d102 2 d114 2 a115 2 "GPS", "Modem", "pCO2", "CTD20", "CTDm2", "Spectro10", "Spectro20", "Nitrate", "Nitrate2" }; d139 2 d265 3 d291 1 a291 1 print_spec( len, &spec_cal[0] ); d295 1 a295 1 print_spec( len, &spec_cal[1] ); d299 1 a299 1 print_spec( len, &spec_cal[2] ); d302 4 d307 1 d726 2 a727 1 int i; d730 2 d733 4 a736 2 (analog[chan+i].a * (double)getIntelword(&buffer[2*i])) + analog[chan+i].b, analog[chan+i].units); d751 2 a752 1 Nat32 lat, lon, var; d754 1 a766 4 printf("%3d:%02d.%03dN %3d:%02d.%03dW Var %.2f Samp %d Stat %04x\n", lat/60000, (lat/1000)%60, lat%1000, lon/60000, (lon/1000)%60, lon%1000, sqrt((double)var), samples, status); d768 20 a830 1 SpecDecode spec; /* Struct to hold decoded Spect data*/ d850 2 a851 2 if ( scp->spc_cal[i][j].present ) n += printf("%s %9.6f ", scp->spc_cal[i][j].name, d863 56 d969 1 a969 1 double a, b; d995 2 a996 2 if ( (i = sscanf(tmp_buf, " analog %d %lf %lf %s", &channel, &a, &b, unitname)) >= 3 ) d1000 3 a1002 1 if ( i > 3 ) d1010 1 a1010 1 else if ( sscanf(tmp_buf, " ctd20 %s", ctd_file) == 1 ) d1015 1 a1015 1 else if ( sscanf(tmp_buf, " ctdm2 %s", ctd_file) == 1 ) d1027 1 a1027 1 if ( read_spec_cal(spec_file, &spec_cal[2]) != OK ) d1033 1 a1033 1 if ( read_spec_cal(spec_file, &spec_cal[1]) != OK ) d1039 1 a1039 1 if ( read_spec_cal(spec_file, &spec_cal[0]) != OK ) d1041 6 @ 2.1 log @Read CTD pressure from calibration file if no CTD pressure sensor. @ text @d4 1 a4 1 /* $Header: decode.c,v 2.0 92/08/31 15:35:26 hebo Exp $ */ d9 1 a9 1 /* $Revision: 2.0 $ */ d15 3 a69 1 d869 1 a869 1 char *p; d881 2 a882 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 ); d884 5 a888 1 sprintf( cfg_file, "%s/m1a.cfg", CFG_DIR ); @ 2.0 log @Auguest 1992 Deployment. Changed to allow multiple sensors of same type. @ text @d4 1 a4 1 /* $Header: decode.c,v 1.3 92/06/15 09:07:23 hebo Exp $ */ d9 1 a9 1 /* $Revision: 1.3 $ */ d15 3 d768 3 a770 6 if ( len >= CTD_BYTES ) printf("Num %d Press %6.3f Temp %6.3f Cond %6.3f\n", ctd.ctd_sample, ctd.ctd_press, ctd.ctd_temp, ctd.ctd_cond); else printf("Num %d Temp %6.3f Cond %6.3f\n", ctd.ctd_sample, ctd.ctd_temp, ctd.ctd_cond); @ 1.3 log @*** empty log message *** @ text @d4 1 a4 1 /* $Header: decode.c,v 1.2 92/05/12 18:18:39 hebo Exp $ */ d9 1 a9 1 /* $Revision: 1.2 $ */ d15 3 d47 1 a47 1 #define CFG_FILE "oasis.cfg" /* Configuration file */ d57 6 a62 4 Extern Status read_ctd_cal( char *name ); Extern Status decode_ctd( Byte *ctddata, Int len, CTDDecode *cdp ); Extern Status read_spec_cal( char *name ); Extern Status decode_spectro( Byte *spdata, Int splen, SpecDecode *sdp ); d66 1 a66 1 /* Global Data */ d69 3 a71 8 Global Byte buffer[BUFSIZE]; /* Decoded data buffer */ Global Byte uubuf[UUBUFSIZE]; /* Buffer for raw uuencoded data */ Global time_t oasis_time; /* Time of OASIS data in time_t fmt */ Global double oasis_dtime; /* Time of OASIS data in real format*/ Global AtlasDecode atlas; /* Buffer for decoded ATLAS data */ Global CTDDecode ctd; /* Buffer for decoded CTD data */ Global SpecDecode spec; /* Buffer for decoded Spectro data */ Global Analog analog[ANALOG_CHANS]; /* Analog calibration */ d73 19 d93 5 a97 5 Global char *filename = {"oasis.0"}; /* Name of file to decode */ Global char *cfg_file = CFG_FILE; /* Name of OASIS configuration file*/ Global char atlas_file[NAMESIZE] = ""; /* Name of ATLAS calibration file*/ Global char ctd_file[NAMESIZE] = ""; /* Name of CTD calibration file */ Global char spec_file[NAMESIZE] = ""; /* Name of Spectro cal file */ d99 4 a102 3 char *errtypes[] = { "Empty", "Time", "ATLAS", "OASIS analog", "PAR", "CTD", "Spectro", "ADCP", "GPS" }; d109 4 a112 1 Status read_cfg( char *name ); d118 4 a121 2 Void printbytes( char *ident, Int len ); Void print_analog( char *ident, Nat16 chan, Int nchans ); d123 3 d129 4 a132 4 /* function : main */ /* purpose : Main routine */ /* inputs : argc, argv */ /* outputs : none */ d135 1 a135 1 main( int argc, char **argv ) d137 2 a138 7 Int cc, len, type, i; Nat16 j; FILE *fd; Nat32 lat, lon; struct tm *tp; Boolean did_err_msg; Status rtn; d140 1 a140 1 for ( i = 1; i < argc; i++ ) d142 3 a144 8 if ( *argv[i] == '-' ) { switch( argv[i][1] ) { case 'c': i++; cfg_file = argv[i]; break; d146 6 a151 4 default: printf("Unknown command line switch \"%s\"\n", argv[i]); } } d153 1 a153 1 filename = argv[i]; d156 1 a156 2 if ( (fd = uuopen(filename)) == (FILE *)NULL ) exit( 1 ); d158 1 a158 2 if ( read_cfg(cfg_file) != OK ) printf("Can't open configuration file \"%s\"\n", cfg_file); a159 2 if ( read_atlas_cal(atlas_file) != OK ) printf("Can't open ATLAS calibration file %s\n", atlas_file); d161 14 a174 2 if ( read_ctd_cal(ctd_file) != OK ) printf("Can't open CTD calibration file %s\n", ctd_file); d176 2 a177 2 if ( read_spec_cal(spec_file) != OK ) printf("Can't open Spectroradiometer calibration file %s\n", spec_file); d181 1 a181 1 while ( (cc = uugetline(buffer, 3, fd)) != EOF ) d186 1 a186 1 if ( cc != 3 ) d189 1 a189 1 printf("Bad record header\n"); d195 5 a199 2 type = (Nat32)(buffer[0]); cc = getIntelword( &buffer[1] ); d203 1 a203 1 printf("Record too long. Truncating.\n"); d209 1 a209 1 printf("Bad record\n"); d215 8 a222 1 switch( type ) d225 1 a225 1 printbytes("Empty", len); d231 1 a231 4 oasis_dtime = tp->tm_yday + 1.0 + (double)((3600 * tp->tm_hour) + (60 * tp->tm_min) + tp->tm_sec) / 86400.0; printf("Time %s", asctime(tp)); a234 1 printf("ATLAS "); d236 1 d238 1 a238 12 else { printf("Time %9.5f %9.5f Air %6.3f SST %6.3f\n", oasis_dtime, atlas.atd_time, atlas.atd_air, atlas.atd_sst); printf(" "); for ( i = 0; i < TEMPS; i++ ) printf("%6.3f ", atlas.atd_temp[i]); printf("\n Press %6.2f %6.2f RH %5.2f", atlas.atd_press[0], atlas.atd_press[1], atlas.atd_rh); printf(" Wind %6.3f m/s toward %5.1f\n", atlas.atd_windspd, atlas.atd_winddir); d240 10 d253 1 a253 1 print_analog("OASIS", OASIS_CHAN, len/2); d257 1 a257 1 print_analog("PAR", PAR_CHAN, len/2); d261 1 a261 11 printf("CTD "); if ( (rtn = decode_ctd(buffer, len, &ctd)) != OK ) print_error( rtn ); else { printf("Time %9.5f Num %d Press %6.3f Temp %6.3f Cond %6.3f\n", oasis_dtime, ctd.ctd_sample, ctd.ctd_press, ctd.ctd_temp, ctd.ctd_cond); printf(" Salinity %6.4f Transmiss %6.4f Fluor %6.4f\n", ctd.ctd_sal, ctd.ctd_trans, ctd.ctd_fluor); } d264 8 d273 1 a273 24 printf("Spectro "); if ( (rtn = decode_spectro(buffer, len, &spec)) != OK ) print_error( rtn ); else { printf("Time %9.5f %9.5f depth %9.6f temp %9.6f\n", oasis_dtime, spec.spc_day + (double)(spec.spc_sec)/86400.0, spec.spc_chan[13].spc_mean, spec.spc_chan[14].spc_mean); printf(" "); printf("batt %9.6f %9.6f pitch %9.6f roll %9.6f\n", spec.spc_chan[15].spc_mean, spec.spc_chan[16].spc_mean, spec.spc_chan[17].spc_mean, spec.spc_chan[18].spc_mean); printf(" "); for ( i = 0; i < 6; i++ ) printf(" %9.6f", spec.spc_chan[i].spc_mean); printf("\n "); for ( i = 6; i < 13; i++ ) printf(" %9.6f", spec.spc_chan[i].spc_mean); printf("\n"); } d276 8 d285 1 a285 1 printbytes("ADCP", len); d289 1 a289 14 if ( len != 16 ) printf("GPS record incorrect size, was %d, should be 16\n",len); lat = getIntellong(buffer); lon = getIntellong(&buffer[4]); printf("GPS %3d:%02d.%03dN, %3d:%02d.%03dW, ", lat/60000, (lat/1000)%60, lat%1000, lon/60000, (lon/1000)%60, lon%1000); lat = getIntellong(&buffer[8]); i = getIntelword(&buffer[12]); j = getIntelword(&buffer[14]); printf("Variance %.2f, Samples %d, Status %04x\n", sqrt((double)lat), i, j ); d292 12 d309 1 a309 1 printf("OASIS Error "); d326 1 a326 1 if ( cc > GPS ) d329 5 a333 1 printf("%s Error\n", errtypes[cc]); d338 1 a338 1 printf("Comment Record: "); d340 1 a340 1 putchar( buffer[cc] ); d344 17 d362 1 a362 1 printf("Unknown record type\n"); d368 1 a368 1 } /* main() */ d372 66 d461 1 a461 1 printf("No begin line\n"); d618 25 d645 1 a645 1 /* Inputs : String, length */ d649 1 a649 1 printbytes( char *ident, Int len ) a651 1 char *s; d653 1 a653 1 for ( i = 0, s = ident; i < len; s = "" ) d655 1 a655 1 printf("%-9s", s); d660 1 a660 2 printf("%02x", buffer[i++]); printf("\n"); d662 1 d668 27 d697 1 a697 1 /* Inputs : String, first channel number, number of channels */ d701 1 a701 1 print_analog( char *ident, Nat16 chan, Int nchans ) a704 1 printf("%-9s", ident); d715 106 d846 3 d857 1 a857 1 /* Inputs : Name of file */ d859 3 d864 1 a864 1 read_cfg( char *name ) d867 1 a867 1 char buf[128]; d870 1 d873 14 a886 1 memset( (void *)&analog, 0, sizeof(analog) ); d888 1 a888 1 if ( (fp = fopen(name, "rb")) == (FILE *)NULL ) d891 3 a893 1 while ( fgets(buf, sizeof(buf), fp) != NULL ) d895 1 a895 1 if ( (i = sscanf(buf, " analog %d %lf %lf %s", d903 38 a940 5 else if ( sscanf(buf, " atlas %s", atlas_file) == 1 ) ; else if ( sscanf(buf, " ctd %s", ctd_file) == 1 ) ; else sscanf(buf, " spectro %s", spec_file ); d944 1 @ 1.2 log @Added spectroradiometer decoding (spec.c) @ text @d4 1 a4 1 /* $Header: decode.c,v 1.1 92/03/16 15:42:08 hebo Rel $ */ d9 1 a9 1 /* $Revision: 1.1 $ */ d15 3 d187 1 a187 1 printf("Empty record\n"); @ 1.1 log @Ignore leading blanks on "begin" line @ text @d4 1 a4 1 /* $Header: decode.c,v 1.0 92/02/25 10:46:58 hebo Rel $ */ d9 1 a9 1 /* $Revision: 1.0 $ */ d15 3 d53 2 d67 1 d74 2 a75 1 Global char ctd_file[NAMESIZE] = ""; /* Name of CTD calibration file */ d145 3 d238 24 a261 1 printbytes("Spectro", len); d580 4 d621 3 a623 1 else sscanf(buf, " ctd %s", ctd_file ); @ 1.0 log @Initial revision @ text @d4 1 a4 1 /* $Header: decode.c,v 1.1 92/02/25 10:45:32 hebo Exp $ */ d9 1 a9 1 /* $Revision: 1.1 $ */ d15 1 a15 1 * Revision 1.1 92/02/25 10:45:32 10:45:32 hebo (Bob Herlien) a16 1 * d28 1 d267 3 a269 1 printf("Restarted"); d308 1 d314 6 a319 2 while ( fgets((char *)uubuf, sizeof(uubuf), fd) != NULL ) if (strncmp((char *)uubuf, "begin ", 6) == 0) d321 1 @