static char rcsid[]="$Id: testgmf.c,v 1.0 1992/07/28 23:07:53 maurer $"; /*********************************************************************** testgmf.c Function: program illustrates how to read GMF G-matrix file This file is part of the STARLab Magellan Altimeter Data Processing Software. Joe Twicken, June 1992. ***********************************************************************/ /* $Log: testgmf.c,v $ * Revision 1.0 1992/07/28 23:07:53 maurer * Initial revision * */ #include #include "scvdr.h" #include "scvparse.h" #include "scvparse.i" #include "scv_rdr.i" #define RECNUM 10 /* Number data recs to read at once */ int main(argc,argv) int argc; /* Number of program arguments */ char *argv[]; /* Argument strings */ { sfdu sf1; /* CCSDS header SFDU label */ sfdu sf2; /* Keyword/value SFDU label */ sfdu sf3; /* G-matrix header SFDU label */ sfdu sf4; /* Aggr start marker SFDU label */ keyval_t *kv2; /* Catalog keyword/value list */ keyval_t *kv4; /* Aggr smarker keyword/value list */ gh_rec gh; /* G-matrix header record */ gr_rec gr[RECNUM]; /* G-matrix data records */ int ng; /* Number of data records remaining */ int nread; /* Number of data records to read */ int Gnum; /* G-matrix ID number */ float gbr; /* Angle-range G-matrix value */ char product_file_name[80];/* Product file name */ FILE *f_gmf; /* GMF file pointer */ /* Check usage */ if (argc != 2) { fprintf(stderr,"usage: testgmf gmf_file\n"); exit(1); } /* Open the GMF file for reading */ if ((f_gmf = fopen(argv[1],"r")) == NULL) { fprintf(stderr, "testgmf: [main] can't open %s\n",argv[1]); exit(2); } /* Read the 4 header SFDU's. Remember to free the keyword/value list pointers with free_catalog() when they are no longer needed */ if (hdr_read(f_gmf,&sf1,&sf2,&kv2,&sf3,&gh,&sf4,&kv4)) { fprintf(stderr, "testgmf: [main] can't read gmf header\n"); exit(3); } /* Do something with the header values. The example here shows how to get the number of G-matrices and product file name */ ng = (int) gh.gh_ng; strncpy(product_file_name,kv2[0].val,sizeof(product_file_name)); /* Allocate space for the variable length fields in the G-matrix data records. gmf_allocn() need only be called once per file; sufficient memory space is allocated to accommodate the largest possible data record */ if (gmf_allocn(gr,RECNUM,&gh)) { fprintf(stderr, "testgmf: [main] can't allocate memory space\n"); exit(4); } /* Read G-matrix data records, 10 at a time */ while (ng > 0) { /* Read the data records 10 at a time. Note that gmf_readn() returns the number of records successfully read */ nread = (ng > RECNUM) ? RECNUM : ng; if (gmf_readn(f_gmf,gr,nread) != nread) { fprintf(stderr, "testgmf: [main] can't read gmf data recs\n"); exit(5); } ng -= nread; /* Do something with the data values. The example here shows how to read the G-matrix ID number and the first angle-range G-matrix value for the first data record */ Gnum = (int) gr[0].gr_Gnum; gbr = gr[0].gr_gbr[0]; } /* Free the memory allocated for the variable length fields in the G-matrix data records. The gmf_freen() routine must be called once for each call to gmf_allocn() */ gmf_freen(gr,RECNUM); /* Free the header keyword/value lists */ free_catalog(kv2); free_catalog(kv4); /* Close the GMF file */ fclose(f_gmf); return(0); }