/* Sem1PoesScan.c This is a program designed to test decode.c interface. It should print out some fields from the first and last records of a NOAA packed file on tape. It should compile with any ANSI-compliant compiler (such as gcc). Written by Greg Ushomirskiy using code (and most of the hard work) by Minh Huynh Modified by Dan Wilkinson 11/29/95 to do byte swapping w/o external library functions. Now runs under DOS. Speed increase with a search to end rather that read to end. */ #include #include /* #include */ #include /* included to use malloc() */ #include #include "dcwdecode.h" /* Include prototypes and definitions for dcwdecode.c */ void print_record(struct archive_rec rec, struct input_rec inp_rec); #define RECSIZE 332 /* Size of NOAA semi-packed records */ FILE *InputStream, *OutputStream, *DebugStream; long FileOffset; int main (int argc, char *argv[]) { long eof, FileSize, RecCount ; int i=0; /* FILE *ff_out; */ struct input_rec inp_rec; struct archive_rec out_rec; if (argc!=2) { printf("Usage: noaascan [noaascan version 11/29/95]\n"); exit(0); } /* Open the input file */ OutputStream = fopen( "output", "wt" ); InputStream = fopen( argv[1],"rb" ); FileOffset = ftell( InputStream ); eof = fread( &inp_rec, 1, RECSIZE, InputStream ); /* If even the first record is short the file must be bad */ if (eof < RECSIZE) { printf("***ERROR*** Short file\n"); fclose(InputStream); exit(1); } /* Decode first record and dump a couple of fields to output */ decode(inp_rec,&out_rec); printf( "\n" "First & Last 5 records of file %s\n\n" "Sat ID Yr Day Second Orbit Offset\n" "------------------------------------------\n", argv[1] ); print_record(out_rec, inp_rec); printf( "\n" ); fseek(InputStream, 0L, SEEK_END ); FileSize = ftell(InputStream); RecCount = FileSize/RECSIZE; fseek(InputStream, (RecCount-5) * RECSIZE, SEEK_SET ); while ( eof == RECSIZE ) { eof = fread( &inp_rec, 1, RECSIZE, InputStream ); FileOffset = ftell( InputStream ); if( eof == RECSIZE ) { decode(inp_rec, &out_rec); print_record(out_rec, inp_rec); } } printf( "------------------------------------------\n" "Sat ID Yr Day Second Orbit Offset\n"); fclose(InputStream); } void print_record(struct archive_rec rec, struct input_rec inp_rec) { char satID[10]; switch (rec.IHD[0]) { case 0: sprintf(satID,"Bad ID "); break; case 1: sprintf(satID,"TIROS-N"); break; case 2: sprintf(satID,"NOAA- 6"); break; case 3: sprintf(satID,"NOAA-14"); break; case 4: sprintf(satID,"NOAA- 7"); break; case 5: sprintf(satID,"NOAA-12"); break; case 6: sprintf(satID,"NOAA- 8"); break; case 8: sprintf(satID,"NOAA-10"); break; default: sprintf(satID,"NOAA-%2ld",rec.IHD[0]); break; } printf( "%s %2ld %3ld %10.4f " "%6ld %9ld\n", satID,rec.IHD[1], rec.IHD[2], (float)rec.IHD[3]/1000.0, rec.IHD[7], FileOffset); return; }