static char rcsid[]="$Id: testif.c,v 1.0 1992/07/28 23:07:53 maurer $"; /*********************************************************************** testif.c Function: program illustrates how to read SIF/OIF image data files This file is part of the STARLab Magellan Altimeter Data Processing Software. Joe Twicken, June 1992. ***********************************************************************/ /* $Log: testif.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; /* Image 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 */ ih_rec ih; /* Image header record */ ir_rec ir[RECNUM]; /* Image 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 inten; /* Cumulative intensity */ char product_file_name[80];/* Product file name */ FILE *f_if; /* SIF/OIF file pointer */ /* Check usage */ if (argc != 2) { fprintf(stderr,"usage: testif sif/oif_file\n"); exit(1); } /* Open the SIF/OIF file for reading */ if ((f_if = fopen(argv[1],"r")) == NULL) { fprintf(stderr, "testif: [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_if,&sf1,&sf2,&kv2,&sf3,&ih,&sf4,&kv4)) { fprintf(stderr, "testif: [main] can't read sif/oif 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 = ih.ih_orb; ver = ih.ih_ver; nrec = ih.ih_nrec; strncpy(product_file_name,kv2[0].val,sizeof(product_file_name)); /* Allocate space for the variable length fields in the image data records. sif_oif_allocn() need only be called once per orbit; sufficient memory space is allocated to accommodate the largest possible data record */ if (sif_oif_allocn(ir,RECNUM,&ih)) { fprintf(stderr, "testif: [main] can't allocate memory space\n"); exit(4); } /* Read image data records, 10 at a time */ while (nrec > 0) { /* Read the data records 10 at a time. Note that sif_oif_readn() returns the number of records successfully read */ nread = (nrec > RECNUM) ? RECNUM : nrec; if (sif_oif_readn(f_if,ir,nread) != nread) { fprintf(stderr, "testif: [main] can't read sif/oif 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 intensity value from the first angle in the first data record */ nfoot = ir[0].ir_nfoot; inten = ir[0].ir_bins[0].inten; } /* Free the memory allocated for the variable length fields in the image data records. The sif_oif_freen() routine must be called once for each call to sif_oif_allocn() */ sif_oif_freen(ir,RECNUM); /* Free the header keyword/value lists */ free_catalog(kv2); free_catalog(kv4); /* Close the SIF/OIF file */ fclose(f_if); return(0); }