static char rcsid[]="$Id: testnff.c,v 1.0 1992/07/28 23:07:53 maurer $"; /*********************************************************************** testnff.c Function: program illustrates how to read NFF inversion fit file This file is part of the STARLab Magellan Altimeter Data Processing Software. Joe Twicken, June 1992. ***********************************************************************/ /* $Log: testnff.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; /* Inversion fit 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 */ fh_rec fh; /* Inversion fit header record */ fr_rec fr[RECNUM]; /* Inversion fit data records */ int orb,ver; /* Orbit and version */ int nrec; /* Number of data records remaining */ int nread; /* Number of data records to read */ int nfoot; /* Footprint number */ float p1; /* Fit parameter p1 */ char product_file_name[80];/* Product file name */ FILE *f_nff; /* NFF file pointer */ /* Check usage */ if (argc != 2) { fprintf(stderr,"usage: testnff nff_file\n"); exit(1); } /* Open the NFF file for reading */ if ((f_nff = fopen(argv[1],"r")) == NULL) { fprintf(stderr, "testnff: [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_nff,&sf1,&sf2,&kv2,&sf3,&fh,&sf4,&kv4)) { fprintf(stderr, "testnff: [main] can't read nff header\n"); exit(3); } /* Do something with the header values. The example here shows how to get the orbit, version, record number and product file name */ orb = fh.fh_orb; ver = fh.fh_ver; nrec = fh.fh_nrec; strncpy(product_file_name,kv2[0].val,sizeof(product_file_name)); /* Allocate space for the variable length fields in the inversion fit data records. nff_allocn() need only be called once per orbit; sufficient memory space is allocated to accommodate the largest possible data record */ if (nff_allocn(fr,RECNUM,&fh)) { fprintf(stderr, "testnff: [main] can't allocate memory space\n"); exit(4); } /* Read inversion fit data records, 10 at a time */ while (nrec > 0) { /* Read the data records 10 at a time. Note that nff_readn() returns the number of records successfully read */ nread = (nrec > RECNUM) ? RECNUM : nrec; if (nff_readn(f_nff,fr,nread) != nread) { fprintf(stderr, "testnff: [main] can't read nff data recs\n"); exit(5); } nrec -= nread; /* Do somethings with the data values. The example here shows how to read the footprint number and the p1 value for the first scattering law in the first record */ nfoot = fr[0].fr_nfoot; p1 = fr[0].fr_sslf[0].fr_p1; } /* Free the memory allocated for the variable length fields in the inversion fit data records. The nff_freen() routine must be called once for each call to nff_allocn() */ nff_freen(fr,RECNUM); /* Free the header keyword/value lists */ free_catalog(kv2); free_catalog(kv4); /* Close the NFF file */ fclose(f_nff); return(0); }