RadDmp
RadDmp - Dump radar data
This routine is intended to serve as an example of the programming required to extract data from the Alberta Research Council's (ARC) Compressed Data Block (CDB) formatted files. The subroutine structure used is that of the ARC's Radar Software System, but the code within the routines has been simplified to deal only with data from disk.
Reads compressed radar data blocks (CDBs) from the file CDBFILE.CDB, writes the time, elevation, azimuth, and data for each ray to the file RADDMP.TXT.
EXAMPLE
$ raddmp RADDMP - 1995 Aug 18 RADDMP: Input CDB file is cdbfile.cdb RADDMP: Output text file is raddmp.txt Read a block RADDMP: 2 rays printed. Contents of the file RADDMP.TXT: Note that the lines in this example have been truncated. The program dumps a value for each of the 147 bins. Antenna Bin (sample) Number Time Elev Azim 1 2 3 4 5 6 7 8 9 10 11 12 ... 13:36:59.533 06.9 189.1 028 017 012 013 001 007 000 000 004 000 000 000 ... 13:36:59.550 06.9 190.2 024 021 012 011 002 008 000 000 003 003 002 001 ...
CODE
/* * Module summary: * RADDMP - Simple routine to extract data from CDB file * * Revision History: * Name Date Description * Mark Johnson 1995-Aug-18 First version */ /* * Definitions used */ #include #include #include "rad.h" /* * External variables and modules */ /* * Static variables declared */ #define FNSIZE 64 /* * Factor for the conversion between raw angle data and tenths of degrees */ #define THE_FACTOR ( 16384.0 / 360.0 ) /* * Internal macros */ #define azconv(word) ( (word & 037777)/THE_FACTOR ) /* used to add 5.0 */ #define elconv(word) ( (word & 037777)/THE_FACTOR/10.0 ) #define minconv(word) ( getbit(word,14,7) ) #define hrconv(word) ( getbit(word,6,7) ) #define secconv(word) ( getbit(word,5,6) ) #define milconv(word) ( (getbit(word,14,7)*100)/6 ) #define CLEARBIT15(word) ( (word) & ~0100000 ) /* * getbit - get n bits from position p * * Note: this is a function rather than a macro so that * the orginal parameters are unchanged. */ static getbit(x, p, n) unsigned short x ; unsigned int p, n ; { return ((x >> (p+1-n)) & ~(~0 <<n) ) ; } /* * movefor -- move pointer forward * to the next valid word in CDB */ #define movefor(ptr) while (datablock[++(ptr)] == HARDWERR) ++(ptr) /* * rayfor -- move pointer forward * to the begining of the next ray */ #define rayfor(ptr) \ while ( (datablock[ptr] != EOB) && \ !(BIT15SET(datablock[ptr]) && BIT15SET(datablock[ptr+1])) ) \ movefor(ptr) /* * Declare the module */ main(argc, argv) /* RADDMP - extract data from CDB file */ int argc; /* number of command line arguments */ char *argv [] ; /* ptr to array of char strings containing arguments */ { CDB datablock ; /* data block */ int dataptr ; RAY dataray ; float azimuth, elevation ; char antpos[11] ; /* antenna position "ee.e aaa.a" */ char timestr[13] ; /* time "hh:mm:ss.mmm" */ int hours, minutes, seconds, milsecs ; char fin [FNSIZE] ; /* input CDB set filename */ char fout [FNSIZE] ; /* output filename */ FILE *outfile ; /* output file ID */ FILE *infile ; /* input file ID */ int port ; /* port number to print */ int numrays ; /* number of rays printed */ int status ; /* number of blocks read */ int i ; char *raystrptr ; char raystr[147*4] ; /* program identification */ fprintf(stdout,"\nRADDMP - 1995 Aug 18\n") ; /* prepare input and output files */ /* set file names */ strcpy (fin, "cdbfile.cdb") ; strcpy (fout, "raddmp.txt") ; /* open the input and output file */ infile = fopen(fin,"rb") ; if (infile) fprintf(stdout,"RADDMP: Input CDB file is %s\n", fin) ; else { fprintf(stderr, "RADDMP: Unable to open CDB file: %s\n", fin) ; return(0) ; } outfile = fopen(fout,"w") ; fprintf(stdout,"RADDMP: Output text file is %s\n", fout) ; numrays = 0 ; /* read the blocks */ while (fread(datablock, CDBSIZ*2, 1, infile) ) { fprintf(stdout,"Read a block\n"); dataptr = 0 ; /* read the rays */ while ( datablock[dataptr] != EOB ) { getray(datablock,dataptr,dataray) ; azimuth = azconv(datablock[dataptr]) ; movefor(dataptr) ; elevation = elconv(datablock[dataptr]) ; movefor(dataptr) ; sprintf(antpos,"%04.1f %05.1f",elevation,azimuth); hours = hrconv(datablock[dataptr]) ; minutes = minconv(datablock[dataptr]) ; movefor(dataptr) ; seconds = secconv(datablock[dataptr]) ; milsecs = milconv(datablock[dataptr]) ; sprintf(timestr,"%02d:%02d:%02d.%03d",hours,minutes,seconds,milsecs); raystrptr = raystr ; for (i = 0 ; i < 147 ; ++i ) raystrptr += sprintf(raystrptr," %03d",dataray[i]) ; fprintf(outfile,"%s %s%s\n",timestr,antpos,raystr) ; rayfor(dataptr) ; numrays += 1 ; } } fclose(infile) ; fclose(outfile) ; fprintf(stdout,"RADDMP: %d rays printed.\n", numrays) ; }