/* ************************************************************* * * * WOODS HOLE OCEANOGRAPHIC INSTITUTION * * UPPER OCEAN PROCESSES GROUP * * PHYSICAL OCEANOGRAPHY DEPT. * * WOODS HOLE, MASSACHUSETTS USA 02543 * * * * File: vhrhasc.c Model: - * * * * Function: ASIMET HRH 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 vhrhswab first. * * Usage: vhrhasc 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 RH%, 60 float values of Temperature in degrees C, "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 HRH data record structure, 512 bytes */ // struct HRH_record // { // struct time_type time1; /* 8 bytes of time */ // float rh_cal[60]; /* 60 minutes of RH% data */ // float tmp_cal[60]; /* 60 minutes of TMP data */ // unsigned char unused[20]; // unsigned short used; /* set to 0xA5A5 upon record write */ // unsigned short hrh_CRC; /* CRC of previous 510 bytes */ // }; #include #include #include #include /* this is the usage string */ char usage[] = "\nUsage: vhrhasc 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 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 RH% 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,"%7.3f,",fvar); } /* next read 60 minutes of TEMP 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,"%7.3f,",fvar); } /* next are 20 unused bytes for now - just skip */ for (j = 0; j < 20; j++) { /* read the byte, but discard */ ret = fread(&buffer,sizeof(char),1,fd1); if ( ret != 1 ) goto end; } /* 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); }