static char rcsid[]="$Id: testanf.c,v 1.0 1992/07/28 23:07:53 maurer $"; /*********************************************************************** testanf.c Function: program shows how to read ANF altimetry inversion file This file is part of the STARLab Magellan Altimeter Data Processing Software. Joe Twicken, June 1992. ***********************************************************************/ /* $Log: testanf.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; /* Alt inv 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 */ nh_rec nh; /* Alt inv header record */ nr_rec nr[RECNUM]; /* Alt inv 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 cv; /* Covariance value */ char product_file_name[80];/* Product file name */ FILE *f_anf; /* ANF file pointer */ /* Check usage */ if (argc != 2) { fprintf(stderr,"usage: testanf anf_file\n"); exit(1); } /* Open the ANF file for reading */ if ((f_anf = fopen(argv[1],"r")) == NULL) { fprintf(stderr, "testanf: [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_anf,&sf1,&sf2,&kv2,&sf3,&nh,&sf4,&kv4)) { fprintf(stderr, "testanf: [main] can't read anf 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 = nh.nh_orb; ver = nh.nh_ver; nrec = nh.nh_nrec; strncpy(product_file_name,kv2[0].val,sizeof(product_file_name)); /* Allocate space for the variable length fields in the altimetry inversion data records. anf_allocn() need only be called once per orbit; sufficient memory space is allocated to accommodate the largest possible data record */ if (anf_allocn(nr,RECNUM,&nh)) { fprintf(stderr, "testanf: [main] can't allocate memory space\n"); exit(4); } /* Read altimetry inversion data records, 10 at a time */ while (nrec > 0) { /* Read the data records 10 at a time. Note that anf_readn() returns the number of records successfully read */ nread = (nrec > RECNUM) ? RECNUM : nrec; if (anf_readn(f_anf,nr,nread) != nread) { fprintf(stderr, "testanf: [main] can't read anf 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 first covariance value for the first data record */ nfoot = nr[0].nr_nfoot; cv = nr[0].nr_cvm[0]; } /* Free the memory allocated for the variable length fields in the altimetry inversion data records. The anf_freen() routine must be called once for each call to anf_allocn() */ anf_freen(nr,RECNUM); /* Free the header keyword/value lists */ free_catalog(kv2); free_catalog(kv4); /* Close the ANF file */ fclose(f_anf); return(0); }