This routine is intended to serve as an example of the programming required to extract data from the Alberta Research Council's (ARC) Aircraft Data Block (ADB) formatted files. The subroutine structure used is that of the ARC's Aircraft Software System, but the code within the routines has been simplified to deal only with data from disk.
Reads from file ADBFILE.ADB, writes to file AIRDMP.TXT. The tag number of the data to be dumped is supplied on the command line when the program is run.
$ airdmp 4 AIRDMP - 1995 Aug 15 AIRDMP: Input ADB file is adbfile.adb AIRDMP: Output text file is airdmp.txt AIRDMP: input adb file closed. AIRDMP: 783 records read, data tag 4 found in 660. Contents of file AIRDMP.TXT: 1985-Jul-17 23:36:00.014 21 1985-Jul-17 23:36:01.014 21 1985-Jul-17 23:36:02.014 21 1985-Jul-17 23:36:03.014 21 1985-Jul-17 23:36:04.014 21 1985-Jul-17 23:36:05.014 21 1985-Jul-17 23:36:06.014 21 1985-Jul-17 23:36:07.014 21 1985-Jul-17 23:36:08.014 21 1985-Jul-17 23:36:09.014 21 1985-Jul-17 23:36:10.014 22 1985-Jul-17 23:36:11.014 22 1985-Jul-17 23:36:12.014 22 1985-Jul-17 23:36:13.014 22 1985-Jul-17 23:36:14.014 22 ...lines omitted...
/* * Module summary: * AIRDMP - Simple routine to extract data from ADB file * * Revision History: * Name Date Description * Mark Johnson 1995-Aug-12 First version */ /* * Definitions */ #include <stdio.h> #include <stdlib.h> #include "air.h" /* * External modules */ extern BOOLE timec () ; extern BOOLE inadb () ; extern BOOLE rdadb () ; extern BOOLE clsadb () ; extern BOOLE fndtag () ; /* * Constants */ #define FNSIZE 64 /* Filename size */ #define MAXDATASIZE 60 /* Maximum number of bytes to return */ #define TIMTAG 1 /* Tag number of time */ /* * Declare the module */ main(argc, argv) /* AIRDMP - extract data from ADB file */ int argc; /* number of command line arguments */ char *argv [] ; /* ptr to array of char strings containing arguments */ { ADB record [ADB_MAX_SIZE] ; /* ADB - Aircraft Data Block */ ADB_CNTRL_BLOCK *adb_in ; /* ADB control block */ unsigned short timoffset ; /* offset in bytes to time data */ int datatag ; /* tag number of data to extract */ short data[MAXDATASIZE/2] ; /* data extracted */ unsigned short offset, doffset ; /* offset in bytes to directory and data */ char timestr[25] ; /* time as a string */ short bytes ; /* number of bytes of data */ short samples ; /* number of samples */ short size ; /* number of bytes in each sample */ char fin [FNSIZE] ; /* input ADB set filename */ char fout [FNSIZE] ; /* output filename */ FILE *outfile ; /* output file ID */ short read, found ; /* number of ADBs read, number with data */ /* print the program's identification */ fprintf(stdout,"\nAIRDMP - 1995 Aug 15\n") ; /* get the tag number to process from the command line argument */ if (argc > 1) { sscanf(argv[1],"%d",&datatag) ; if (datatag < 0 ) datatag = 0; } else datatag = 0 ; /* prepare input and output files */ /* set file names */ strcpy (fin, "adbfile.adb") ; strcpy (fout, "airdmp.txt") ; /* open the input and output file */ if (!inadb(&adb_in, fin)) /* open input ADB set */ fprintf(stderr, "AIRDMP: Unable to open ADB file: %s\n", fin) ; else fprintf(stdout,"AIRDMP: Input ADB file is %s\n", fin) ; outfile = fopen(fout,"w") ; fprintf(stdout,"AIRDMP: Output text file is %s\n", fout) ; timestr[25] = 0 ; /* Put the null terminator in the time string */ read = 0 ; found = 0 ; /* Set the counters to 0 */ /* read one ADB at a time until end of file */ while (rdadb(adb_in, record)) { read += 1 ; /* count the number of ADB's read */ /* get time ADB was recorded */ if (fndtag(record, TIMTAG, &timoffset)) /* Look for the time tag */ { retdat(record, timoffset, current, 0) ; /* Get the time from the ADB */ if (timec(current,chtime)) /* Convert the time to characters */ { strncpy(timestr, chtime, 24); /* Copy into terminated string */ fprintf(outfile,"%s",timestr); } else fprintf(outfile,"Bad time in ADB"); } else fprintf(outfile,"No time in ADB"); /* Print data value */ if (fndtag(record, datatag, &offset)) /* Look for directory entry for the data tag */ { found += 1 ; dirent(record, offset, &doffset, &bytes, &samples, &size) ; if(size <= MAXDATASIZE) /* If there's room for the data */ { retdat(record, offset, data, 0) ; /* Get the data value */ fprintf(outfile," %6d",data[0]) ; /* Print the first word */ } else fprintf(outfile," Data sample too big to print."); } fprintf(outfile,"\n"); } if (clsadb(adb_in)) fprintf(stdout,"AIRDMP: input adb file closed.\n") ; fclose(outfile) ; fprintf(stdout,"AIRDMP: %d records read, data tag %d found in %d.\n", read, datatag, found) ; }