/*************************************************************************/ /* */ /* maps_co5x5_read.c */ /* */ /* Sample read program for the following MAPS data sets: */ /* MAPS_SRL1_CO5x5_HDF */ /* MAPS_SRL2_CO5x5_HDF */ /* MAPS_OSTA3_CO5x5_HDF */ /* */ /* Version 1.0 February 25, 1996 */ /* Version 2.0 February 02, 1999 */ /* HDF Library: Version 3.3r4 */ /* HDF Library: Version 4.1r2 */ /* */ /* NOTE: Make sure that all paths match to your system. Please review */ /* the makefile, Makefile.maps, before compiling the code. */ /* */ /* This is an interactive program. It prompts the user for all */ /* of the information necessary to read the MAPS data sets. */ /* */ /* CONTACT: If you have any questions with this software or any data, */ /* please feel free to contact us at the following address: */ /* */ /* EOSDIS Langley DAAC User and Data Services */ /* Mail Stop 157D */ /* NASA Langley Research Center */ /* Hampton, Virginia 23681-2199 */ /* */ /* Telephone: (757)864-8656 FAX: (757)864-8807 */ /* E-mail: support-asdc@earthdata.nasa.gov */ /* */ /* 02-03-1999: Modified the code to comply with the Langley DAAC */ /* requirements. */ /*************************************************************************/ #ifndef MAPS #include /* C library */ #include /* C library */ #include /* C library */ #include /* HDF file needs to be in local directory */ #define MAXCHAR 132 /* Max # of characters in string */ #define MAXLEN 10000 #define DFACC_read 1 #define FIRST 1 #define LISTSIZE 6 /* One greater than the number of parameters in file */ #define NumEventPar 5 /* Number of labels to be printed with each event */ #define MAXLNG 55 /* Max number of labels */ #define MAXRANK 2 /* Max number of dimensions */ #define MAXLABLEN 256 /* Max string label length */ #define MAXDATA 9580 /* Max # of latitudes (72) times Max # of data */ /* values per parameter (28) times number of parameters (5)*/ #ifdef PROTOTYPE void Greetings(void); void Assign_rpt_name (char *, char *); void Read_data_descript (char *, FILE *, char *); void Get_data_types (FILE *, char *, int [LISTSIZE]); int Print_data_info (FILE *, char *, int [LISTSIZE]); void Read_data(FILE *, char *, int [LISTSIZE], int); int main(void); #else void Greetings(); /* Declare function */ void Assign_rpt_name(); /* Declare function */ void Read_data_descript(); /* Declare function */ void Get_data_types(); /* Declare function */ int Print_data_info(); /* Declare function */ void Read_data(); /* Declare function */ int main(); #endif #endif #ifdef PROTOTYPE int main() #else int main() #endif { /* Begin main function */ int num_events = 0; /* Stores the number of events */ int dataitems[LISTSIZE]; /* Store reference number of labels */ char yesno[2], /* Stores yes/no number for printing header information */ hdfname[MAXCHAR], /* Stores input data file name */ info[MAXCHAR], /* Used as a temporary string buffer */ outfile[MAXCHAR]; /* Stores output report file name */ FILE *ofp; /* Pointer for output report file */ /**********************************/ /* Main function begins */ /**********************************/ (void) Greetings(); printf("\n\n"); printf("Enter the input data file name. This code assumes file is in your current\n"); printf("working directory.\n"); scanf("%s",info); strcpy(hdfname,info); printf("\n\n"); printf("In your output report file, do you want to include the \n"); printf("file description? Enter 1 for yes and 2 for no .... "); scanf("%s",info); strcpy(yesno,info); printf("\n\n"); /* Create an output report file name. */ (void) Assign_rpt_name (outfile, hdfname); ofp = fopen (outfile, "wt"); if (ofp == NULL) { printf("*********************************************\n"); printf("* ERROR - Not able to open the output file, *\n"); printf("* %s. *\n",outfile); printf("* Program has terminated. *\n"); printf("*********************************************\n"); exit ( -1 ); } /* Reads the data file description from HDF file and writes */ /* it out to the output report file. */ (void) Read_data_descript (hdfname, ofp, yesno); /* Allows the user to select the parameters to be written */ /* out to the output report file. */ (void) Get_data_types (ofp, hdfname, dataitems); /* Print selected data information and output to report file */ num_events = Print_data_info (ofp, hdfname, dataitems); printf("\n\n"); printf("There are %d records/number of events in the HDF file.\n",num_events); printf("NOTE: This will take some time to write out the report file.\n"); /* Read selected data and output to report file */ Read_data (ofp, hdfname, dataitems, num_events); fclose (ofp); /* Print out End of File message onto the screen. */ printf("\n\n"); printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); printf("@ @\n"); printf("@ This program has completed and has created an output report @\n"); printf("@ file called %s in your current @\n",outfile); printf("@ working directory. @\n"); printf("@ @\n"); printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); printf("\n\n"); } /* End main function */ /**************************************************************************** * * * FUNCTION: Greetings * * * * PURPOSE: To print a banner at the beginning of the execution to inform * * the users what version of this read program he or she is * * working with. * * * ****************************************************************************/ #ifdef PROTOTYPE void Greetings(void) #else void Greetings() #endif { /* Begin Greetings function */ printf("\n\n\n"); printf(" *****************************************************\n"); printf(" * *\n"); printf(" * MAPS Read Program Version 2.0 *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * This sample read program currently reads the *\n"); printf(" * following data sets: *\n"); printf(" * *\n"); printf(" * MAPS_SRL1_CO5x5_HDF *\n"); printf(" * MAPS_SRL2_CO5x5_HDF *\n"); printf(" * MAPS_OSTA3_CO5x5_HDF *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * 02-02-1999 *\n"); printf(" *****************************************************\n"); printf("\n\n\n"); } /* End of Greetings function */ /**************************************************************************** * * * FUNCTION: Assign_rpt_name * * * * PURPOSE: Creates a report filename for the appropriate experiment. * * * ****************************************************************************/ #ifdef PROTOTYPE void Assign_rpt_name (char *outfile, char *hdfname) #else void Assign_rpt_name (outfile, hdfname) char *outfile, *hdfname; #endif { strcpy(outfile,"./"); strcat(outfile,hdfname); strcat(outfile,".rpt"); } /* End of function, Assign_rpt_name. */ /**************************************************************************** * * * FUNCTION: Read_data_descript * * * * PURPOSE: Opens input HDF file, reads the file description, and prints * * the file description to the report file if the user desires to * * have it printed. * * * ****************************************************************************/ #ifdef PROTOTYPE void Read_data_descript (char *hdfname, FILE * ofp, char *yesno) #else void Read_data_descript (hdfname, ofp, yesno) char *hdfname; FILE *ofp; char *yesno; #endif { int dfile, iret; char id[MAXLEN], filedesc[MAXLEN]; /* Open HDF input file using HDF user commands. */ dfile = Hopen(hdfname, DFACC_read, 0); if (dfile == NULL) { printf("************************************************\n"); printf("* ERROR - Not able to open the HDF input file. *\n"); printf("* Program has terminated. *\n"); printf("************************************************\n"); exit ( -1 ); } /* Get file id from HDF input file. */ iret = DFANgetfid (dfile, id, MAXLEN, FIRST); if (iret == -1) { printf("************************************************\n"); printf("* ERROR - Not able to get file id from the HDF *\n"); printf("* input data file. *\n"); printf("* Program has terminated. *\n"); printf("************************************************\n"); exit ( -1 ); } /* Get file description from HDF input file. */ iret = DFANgetfds(dfile, filedesc, MAXLEN, FIRST); if (iret == -1) { printf("**************************************************\n"); printf("* ERROR - Error in getting file description from *\n"); printf("* the HDF input data file. *\n"); printf("* Program has terminated. *\n"); printf("**************************************************\n"); exit ( -1 ); } else { if (atoi(yesno) == 1) { fprintf(ofp,"%s\n%s\n\n","File ID: ",id); fprintf(ofp,"%s\n\n%s","File description is as follows:",filedesc); fprintf(ofp,"\n\n"); } } } /* End of function, Read_data_descript. */ /**************************************************************************** * * * FUNCTION: Get_data_types * * * * PURPOSE: This function prints out all of the parameters within the data * * file (HDF) and allows the user to select which parameters he * * or she wishes to see. Only the first six parameters in the * * string called EventStr will automatically be printed to the * * report file. Geometric Altitude will be printed in the event * * information as well as the user being able to select it. * * * ****************************************************************************/ #ifdef PROTOTYPE void Get_data_types(FILE * ofp, char *hdfname, int dataitems[LISTSIZE]) #else void Get_data_types(ofp, hdfname, dataitems) FILE *ofp; char *hdfname; int dataitems[LISTSIZE]; #endif { int nlabels, itemnumber, startpos; int cnt0, cnt1, cnt2, cnt3; uint16 reflist[LISTSIZE]; int index[LISTSIZE]; int numchoices; char labellist[LISTSIZE * MAXLNG + 1]; char datalabellist[MAXLNG][MAXLABLEN]; /* 08/10/94 */ int datalabelval[MAXLNG]; /* 08/10/94 */ int datacount; /* 08/10/94 */ char yesno[2]; /* 08/10/94 */ int iret, numdims, numtype; int32 dimsize[MAXRANK]; char datalabel[MAXLABLEN], dataunit[MAXLABLEN], datafmt[MAXLABLEN], datacoord[3]; char dimlab[2][40], dimunt[30], dimfmt[5]; char all_flag[2]; TRYAGAIN: cnt0 = 0; cnt2 = 1, cnt3 = 0; startpos = 1; numchoices = 0; /* initialize dataitems array */ for (cnt1 = 0; cnt1 < LISTSIZE; cnt1++) { dataitems[cnt1] = 65535; reflist[cnt1] = 0; index[cnt1] = 0; }/* end of for */ for (cnt1 = 0; cnt1 "); scanf("%s",all_flag); if ((strcmp(all_flag,"Y")==0) || (strcmp(all_flag,"y")==0) ) { for (cnt1=1; cnt1 <= numchoices; cnt1++) { itemnumber = index[cnt1 - 1]; dataitems[cnt0] = reflist[itemnumber]; datalabelval[cnt0] = itemnumber; cnt0++; } } else { /* print labels in groups of 15 to ask for users input */ for (cnt1 = 0; cnt1 < numchoices; ++cnt1) { if (cnt2 == 1) { itemnumber = 1; printf(" Item Number Label\n\n"); }/* end of if */ /* 08/10/94 Modified this line of code so that the data labels would */ /* be printed onto the screen instead of the annotation labels. The */ /* data labels contain more information in them compared to the */ /* annotation label. This was changed at the request of the data */ /* producer. */ /* printf(" %3d %s\n", cnt1 + 1, labellist + (index[cnt1] * MAXLNG)); */ printf(" %3d %s\n", cnt1 + 1, datalabellist[cnt1]); cnt2++; if (cnt1 == numchoices - 1) { printf("\nPlease choose the numbers of the data items you wish to dump.\n"); printf("Enter -1 to continue to next list or 0 to begin processing.\n\n"); while (itemnumber != 0 || itemnumber != -1) { /* read the user's selection */ scanf("%d", &itemnumber); /* If user's selection equals -1, then */ /* display 15 more parameters. */ if (itemnumber == -1) break; /* If the user's selection equals 0, then */ /* the user has finished his/her selection */ /* and we can return to the calling routine. */ if (itemnumber == 0) { /* At this time, the code will print out the list of parameters */ /* the user has selected. At this time, the user has the option */ /* to continue with the program or re-enter in his selection. */ printf("\n\n\n"); printf("The following is a list of the parameters you have selected:\n\n"); for (datacount = 0; datacount < cnt0; datacount++) { printf(" %d %s\n",datalabelval[datacount]+1,datalabellist[datalabelval[datacount]]); } printf("\n\n"); printf("Would you like to make a new selection of these parameters or\n"); printf("would you like this program to exit the selection process and\n"); printf("begin retrieving the data? \n"); printf("Enter Y for yes to retrieve data or N for no make a new selection. --> "); scanf("%s",yesno); if (strcmp(yesno,"N")==0) goto TRYAGAIN; else if (strcmp(yesno,"n")==0) goto TRYAGAIN; else printf("\n\n"); dataitems[cnt0] = 0; return; } else { /* If the user's selection is not -1 or 0, */ /* then they have selected a parameter and */ /* we will add the reference number for */ /* that parameter to the dataitems array. */ itemnumber = index[itemnumber - 1]; dataitems[cnt0] = reflist[itemnumber]; datalabelval[cnt0] = itemnumber; cnt0++; }/* end of else */ }/* end of while */ cnt2 = 1; }/* end of if (cnt1 == numchoices - 1) */ }/* end of for */ }/* end of outside else */ dataitems[cnt0] = 0; return; }/* end of Getdatatypes */ /**************************************************************************** * * * FUNCTION: Print_data_info * * * * PURPOSE: This function prints out all of the label information for those* * parameters that the user has just selected. * * * ****************************************************************************/ #ifdef PROTOTYPE int Print_data_info(FILE * ofp, char *hdfname, int dataitems[LISTSIZE]) #else int Print_data_info(ofp, hdfname, dataitems) FILE *ofp; char *hdfname; int dataitems[LISTSIZE]; #endif { int winst[MAXRANK], windims[MAXRANK], winend[MAXRANK]; int dims[MAXRANK], ref_dims[MAXRANK]; int i, j, k, l, iret; int numdims, rnumdims; int32 dimsize[MAXRANK], numtype; int index, event; char datalabel[MAXLABLEN], dataunit[MAXLABLEN]; char datafmt[MAXLABLEN], datacoord[3]; char dimlab[2][40], dimunt[30], dimfmt[5]; float data[MAXDATA]; float ref_data[MAXDATA]; float max, min; int num_events; /* according to reference numbers go to next data set */ printf("\n\nReading labels....\n"); k = 0; while (dataitems[k] != 0) { iret = DFSDreadref(hdfname, dataitems[k]); if (iret == -1) { printf("***********************************************\n"); printf("* ERROR - Not able to get specified reference *\n"); printf("* number %d. *\n",dataitems[k]); printf("***********************************************\n"); exit ( -1 ); } /* get dimensions of SDS */ iret = DFSDgetdims(hdfname, &numdims, dimsize, MAXRANK); if (iret != 0) { printf("***************************************\n"); printf("* ERROR - Not able to get dimensions. *\n"); printf("* Program has terminated. *\n"); printf("***************************************\n"); exit ( -1 ); } else { /* 08/09/94 */ /* The data producer has asked to comment this line out. Please feel */ /* free to remove these comments to print out the dimensions of the */ /* parameters in the output report file. */ /* fprintf(ofp, "\n\nDimensions are %d by %d\n\n", dimsize[0], dimsize[1]); */ num_events = dimsize[1]; }/* end of else */ /* get number type */ iret = DFSDgetNT(&numtype); if (iret != 0) { printf("**********************************************\n"); printf("* ERROR - Not able to get DFSDgetNT numtype. *\n"); printf("* Program has terminated. *\n"); printf("**********************************************\n"); exit ( -1 ); } /* Print message indicating there are no dimension scales */ fprintf(ofp, "*** There are no dimension scales for this data set. ***\n\n"); /* set up slice dimensions */ /* no subsetting required */ winst[0] = 1; winst[1] = 1; windims[0] = dimsize[0]; windims[1] = dimsize[1]; dims[0] = windims[0]; dims[1] = windims[1]; /* Print dimension attributes */ for (l = 1; l <= numdims; l++) { iret = DFSDgetdimstrs(l, dimlab[l - 1], dimunt, dimfmt); if (iret != 0) { printf("*************************************************\n"); printf("* ERROR - Not able to get dimension attributes. *\n"); printf("* Program has terminated. *\n"); printf("*************************************************\n"); exit ( -1 ); } else { fprintf(ofp, "%s%s\n%s%s\n%s%s\n\n", "Description : ", dimlab[l - 1], "Units : ", dimunt, "Format : ", dimfmt); } } /* get data attributes */ iret = DFSDgetdatastrs(datalabel, dataunit, datafmt, datacoord); if (iret != 0) { printf("********************************************\n"); printf("* ERROR - Not able to get data attributes. *\n"); printf("* Program has terminated. *\n"); printf("********************************************\n"); exit ( -1 ); } else { /* Print the data attributes */ fprintf(ofp, "Data attributes are as follows:\n\n"); fprintf(ofp, "%s%s\n%s%s\n%s%s\n\n", "Label : ", datalabel, "Units : ", dataunit, "Format: ", datafmt); } /* Get data max and min values */ iret = DFSDgetrange((void *)&max, (void *)&min); if (iret == -1) { printf("*******************************************\n"); printf("* ERROR - Not able to get 32-bit data max *\n"); printf("* and min values. *\n"); printf("* Program has terminated. *\n"); printf("*******************************************\n"); exit ( -1 ); } else { /* print the data max and mins */ fprintf(ofp, "%s%.2f\n", "Data Max: ", max); fprintf(ofp, "%s%.2f\n\n", "Data Min: ", min); } k++; fprintf(ofp, "\n\n"); }/* end of while */ return (num_events); } /* End of function, Print_data_info. */ /**************************************************************************** * * * FUNCTION: Read_data * * * * PURPOSE: This function prints out all of the data for those parameters * * the user has just selected. * * * ****************************************************************************/ #ifdef PROTOTYPE void Read_data(FILE * ofp, char *hdfname, int dataitems[LISTSIZE], int num_events) #else void Read_data(ofp, hdfname, dataitems, num_events) FILE *ofp; char *hdfname; int dataitems[LISTSIZE]; int num_events; #endif { int32 winst[MAXRANK], windims[MAXRANK], winend[MAXRANK]; int32 dims[MAXRANK], ref_dims[MAXRANK]; int ii, i,j, k, l, iret; int numdims, rnumdims; int32 dimsize[MAXRANK], numtype; int index, event,firstevent; char datalabel[MAXLABLEN], dataunit[MAXLABLEN]; char datafmt[MAXLABLEN], datacoord[3]; char dimlab[2][40], dimunt[30], dimfmt[5]; float data[MAXDATA]; float ref_data[MAXDATA]; float max, min; char stringdate[7], stringtime[7]; /* 08/10/94 */ /* According to reference numbers go to next data set */ printf("\n\nReading data, Please wait ...\n"); /* print out message for data arrangement */ fprintf(ofp, "Data are printed from left to right in event order.\n\n\n\n"); for (ii=0; ii