/* ************************************************************* * * * WOODS HOLE OCEANOGRAPHIC INSTITUTION * * UPPER OCEAN PROCESSES GROUP * * PHYSICAL OCEANOGRAPHY DEPT. * * WOODS HOLE, MASSACHUSETTS USA 02543 * * * * File: vlwrasc.c Model: - * * * * Function: ASIMET LWR binary data file to ASCII converter * * * * Project: ASIMET * * * Programmer: G.A. * * * * Copyright (c) 2002 Woods Hole Oceanographic Institution * * * ************************************************************* */ /* Additional reserved words not recognized by Source Print. uchar */ /* * Program to read the processed binary output file of the VOS C51 logger * and convert to ASCII - run vlwrswab first. * * Usage: vlwrasc datafile outputfile * datafile - binary data file name * outputfile - ascii data file name The ASCII output file is formatted with 1 hour's records per line, comma-separated value, as follows: hour, minute, second, day, day-of-week, month, 4 digit year, 60 float values of Dome Temperature in degrees K, 60 float values of Body Temperature in degrees K, 60 float values of Thermopile Voltage in microvolts, 60 float values of Long Wave Radiation Flux in watts/m^2, "used" value (0xA5A5 = 42405) CRC (unused; always zero) crlf ******************************************************************* */ /* a structure to hold the RTC register times. */ // struct time_type // { // unsigned char hour; // unsigned char min; // unsigned char sec; // unsigned char day; // unsigned char dow; /* day of week - Sunday = 1 */ // unsigned char mon; // unsigned int year; // }; /* this is the LWR data record structure, 612 bytes */ // struct LWR_record // { // struct time_type time1; /* 8 bytes of time */ // unsigned short temp_dome[60]; /* 60 minutes of packed dome temp data */ // unsigned short temp_body[60]; /* 60 minutes of packed body temp data */ // float volts_pile[60]; /* 60 minutes of thermopile voltage data */ // unsigned short lw_flux[60]; /* 60 minutes of packed LW_flux data */ // unsigned short used; /* set to 0xA5A5 upon record write */ // unsigned short lwr_CRC; /* CRC of previous 510 bytes */ // }; #include #include #include #include /* this is the usage string */ char usage[] = "\nUsage: vlwrasc datafile outputfile\n\ datafile - binary data file name\n\ outputfile - ascii data file name\n\n"; /* main program */ void main(int argc,char *argv[]) { FILE *fd1,*fd2; char outbuf[100]; char buffer; short int intbuf; unsigned short used; long lbuf; float fvar; int ret; int j; struct tm *tptr; /* check correct calling sequence */ if (argc < 3) { printf("%s",usage); exit(-1); } /* input file name */ fd1 = fopen(argv[1],"rb"); if ( fd1 == NULL ) { printf("\nUnable to open input file %s\n",argv[1]); printf("%s",usage); exit(-1); } /* output file name */ fd2 = fopen(argv[2],"w"); if ( fd2 == NULL ) { printf("\nUnable to open output file %s\n",argv[2]); printf("%s",usage); exit(-1); } /* stay here until EOF, error, or last record aborts */ while (1) { /* first are 8 time bytes, first six are char */ for (j = 0; j < 6; j++) { /* read the byte, put a byte */ ret = fread(&buffer,sizeof(char),1,fd1); if ( ret != 1 ) goto end; /* transfer it to ASCII file */ fprintf(fd2,"%.2u,",(unsigned int)buffer); } /* next read the 2 "year" bytes */ ret = fread(&intbuf,sizeof(short),1,fd1); if ( ret != 1 ) goto end; /* transfer it to ASCII file */ fprintf(fd2,"%.2u,",intbuf); /* next read 60 minutes of dome temperature and body temperature data */ for ( j = 0; j < 120; j++ ) { /* read a value */ ret = fread(&intbuf,sizeof(short),1,fd1); if ( ret != 1 ) goto end; /* transfer it to ASCII file */ fprintf(fd2,"%7.2f,",((float)intbuf) / 100.0); } /* next read 60 minutes of thermoplile voltage data */ for ( j = 0; j < 60; j++ ) { /* read a value */ ret = fread(&fvar,sizeof(float),1,fd1); if ( ret != 1 ) goto end; /* transfer it to ASCII file */ fprintf(fd2,"%6.1f,",fvar); } /* next read 60 minutes of LW_flux data */ for ( j = 0; j < 60; j++ ) { /* read a value */ ret = fread(&intbuf,sizeof(short),1,fd1); if ( ret != 1 ) goto end; /* transfer it to ASCII file */ fprintf(fd2,"%6.1f,",((float)intbuf) / 10.0); } /* next read the 2 "used" bytes - they should be A5A5 in a good record */ ret = fread(&used,sizeof(short),1,fd1); if ( ret != 1 ) goto end; /* transfer "used" to ASCII file */ fprintf(fd2,"%.2u,",used); /* next read the 2 CRC bytes - unused set to 0 for now */ ret = fread(&intbuf,sizeof(short),1,fd1); if ( ret != 1 ) goto end; /* transfer CRC to ASCII file */ fprintf(fd2,"%.2u",(unsigned short)intbuf); /* end each line with crlf */ fprintf(fd2,"\n"); /* was this a good record ? */ if (used != 0xA5A5) goto end; } /* end while */ end: printf("\n"); fclose(fd1); fclose(fd2); }