/************************************************************* *Name - rdc2hdf2.c(no change in GMT) Type - Program * *Language - c * *Version - 1.0 * * Date - 09/21/92 Programmer-MADIRA MUKHERJE, SAIC * * * * Purpose- This program reads monthly ISCCP_C2_DATA file * * which is in the HDF format. * * * * INPUT - Monthly HDF file named ISCCP_C2_yymm * * * *OUTPUT - Report file name ISCCP_C2-yymm.rpt * * * * Key paramaters- gmt_select- gmt of the selected parameter * * par_num - parameter number * * par_name - parameter name * * convertlabel- array of 7 labels of tables * * convertunit- array of 7 units of table * * Inconvertfmt-array of 7 formats of table * * labellist-array of labels for 72 parameters* * including 9 files per month(648). * * conv_data- stores converted data * * data_select- stores integer data from hdf * * file. * * datalabel- label for parameter * * dataunit- unit of the converted label * * datafmt - format of the data set * * * * Functions called - getinput : gets input data date * * * * getfilename : reads HDF filename * * * * fileiddescp : describe and indicates the* * input year and month of the HDF file. * * * * convdattributes:gets physical units and * * their attributes for the conversion table* * * * getdatatype: asks for the line number * * to indicate the parameter required for * * conversion * * * * convertdata: takes the parameter indicated* * through the line number and applies the * * conversion table * *************************************************************/ #include "hdf.h" #include #include #include #define first 1 #define maxrank 2 #define dftag_sdg 700 #define listsize 648 #define DFACC_READ 1 #define maxlen 30000 #define maxlng 150 int numdims, Dimsizec[maxrank], numtype, dimsize[maxrank], gmt_select, par_num; char par_name[54],conkey; char ddate[4], hdfname[60], outfile[60]; char convertlabel[7][80]; char convertunit[7][80]; char Inconvertfmt[7], label[100]; char datalabel[100], dataunit[30], datafmt[30], datacoord[30]; float conv_data[6596]; float data[6596]; unsigned char data_select[6596]; FILE *rptfp; float TMPTAB[256]; float TMPVAR[256]; float PRETAB[256]; float RFLTAB[256]; float TAUTAB[256]; float PRWTAB[256]; float OZNTAB[256]; int getinput(); void getfilename(); void fileiddescp(); void convdattributes(); void convertdata(); void getdatatype(); void getareatype(); main() { printf("\nTHIS PROGRAM READS THE ISCCP_C2_DATA FROM HDF FORMATTED\n"); printf("FILES. THE INPUT FILE IS NAMED ACCORDING TO NAMING CONVENTIONS\n"); printf("FORMED BY THE LANGLEY DAAC. IF YOU HAVE CHANGED THE NAME OF THE\n"); printf("FILE OR NEED TO SPECIFY A PATH, YOU WILL NEED TO MODIFY THIS \n"); printf("PROGRAM. \n"); printf("PLEASE ENTER (Q) TO QUIT or (C) TO CONTINUE.\n"); scanf("%s",&conkey); if (conkey=='q'|| conkey == 'Q') { printf("\nEXITING PROGRAM................\n"); exit(1); } else { getinput(); getfilename(); printf("\n%s%s\n","INPUT FILE NAME IS ",hdfname); printf("%s%s\n","OUTPUT FILE NAME IS ",outfile); fileiddescp(); convdattributes(); getdatatype(); if (rptfp != NULL) { fclose(rptfp); }/* end of if */ printf("\nEXITING PROGRAM....................\n"); } } /**************************************************************** *FUNCTION GETINPUT * *Name-getinput Type-Function * *Version-1.0 Date- 10/1/92 * * Programmer-Madira Mukherje(SAIC) * * * *Purpose- This function asks for the data date (yymm)of the HDF * *file to read. * * * *Input parameter- ddate -the data date (yymm) * ****************************************************************/ int getinput() { printf("ENTER DATA DATE OF HDF FILE TO READ (yymm): "); scanf("%s", ddate); printf("\nREADING FILE DESCRIPTION .. PLEASE WAIT ..\n"); } /***************************************************************** *FUNCTION GET FILENAME * *Name- getfilename Type-Function * *Version - 1.0 Date-10/8/92 * * Programmer-Madira Mukherje(SAIC) * * * *Purpose- creates the output file name ISCCP_C2_ddate_00 * * * * * *Input parameter- * * ddate-the data date(yymm) * *Output parameter- * * Outfile-stores name of the output file * *****************************************************************/ void getfilename() { strcpy(outfile, "c2_3hrlymon_"); strcat(outfile, ddate); strcat(outfile, ".rpt"); rptfp = fopen(outfile, "w"); strcpy(hdfname,"c2_3hrlymon_"); strcat(hdfname, ddate); } /***************************************************************** * GET FILE ID AND DESCRIPTION * *Name-fileiddescp Type- function * *Version-1.0 Date- 10/10/92 * * Programmer-Madira Mukherje (SAIC) * * * *Purpose- reads the ID and file description from HDF file * * * * * *Input parameters - * * hdfname-name of hdf file * * rptfp-report file pointer * * maxlen-maximum length for file id and file * * description * * first-set to 1 * * * *Output parameter- * * hdfname-name of hdf file * * * *Key local parameters- * * iret- return value * * dfile-name of hdf open file * * id - idicates the year and month of the input file* * desc- describes the indicated file * * * *Functions called- * * hdf library functions * * * *****************************************************************/ void fileiddescp() { int iret; int dfile; uint16 reflist[72]; char id[75]; char desc[30000]; dfile = Hopen(hdfname, DFACC_READ, 0); if (dfile == NULL) { fprintf(rptfp, "ERROR IN OPENING HDF FILE \n\n"); exit(1); } iret = DFANgetfid(dfile, id, maxlen, first); if (iret == -1) { fprintf(rptfp, "s\n\n", "ERROR IN GETTING FILE ID"); exit(1); } else fprintf(rptfp, "%s%s\n\n", "FILE ID: ", id); iret = DFANgetfds(dfile, desc, maxlen, first); if (iret == -1) { fprintf(rptfp, "%s\n\n", "ERROR IN GETTING FILE DESCRIPTION"); exit(1); } else fprintf(rptfp, "%s%s\n\n", "FILE DESCRIPTION IS AS FOLLOWS:", desc); iret = Hclose(dfile); } /**************************************************************** * GET DATA AND DATA ATTRIBUTES FOR THE CONVERSION TABLE * *Name-convdattributes Type-function * *Version-1.0 Date-11/10/92 * * Programmer-Madira Mukherje (SAIC) * * * *Purpose - This function retrieves the data of the conversion * *table from the HDF file where each table are stored as * *scientific dataset. * * * *Input parameters- * * hdfname-hdf file name * * numdims-number of dimension 2 * * Dimsizec-dimension size for conversion table * * 1 by 256 * * maxrank- maximum rank set to 2 * * * *Output parameters- * *TMPTAB -Conversion counts (1-253)to temperature (165k-345k) * *TMPVAR -Conversion counts (1-253)to temp. variance(.075k-85k) * *PRETAB -Conversion counts (1-241)to pressure(1mb-1200mb) * *RFLTAB- Conversion counts (1-253)to reflectance(0.0-1.108) * *TAUTAB -Conversion counts(1-231)to TAU (0.02-119.59) * *PRWTAB -Conversion counts(1-253)to precipitable water(humidity)* * (0.0-8.0)in centimeters. * *OZNTAB-Conversion counts (1-253)to ozone abundance (0-515)in * * dobson units. * * * *Key local variables- * * iret- indicates return value from hdf library * * function * * i - count set up for cheking table data * * * *Functions called- * * hdf library functions * * * ****************************************************************/ void convdattributes() { long int iret; int i; /* get dimension */ iret = DFSDgetdims(hdfname, &numdims, Dimsizec, maxrank); if (iret != 0) { fprintf(rptfp, "ERROR IN GETTING DIMENSIONS error = %d\n\n", iret); exit(1); } /* else { fprintf(rptfp, "DIMENSIONS ARE %d by %d\n\n", Dimsizec[0], Dimsizec[1]); } */ /***************************************************************/ iret = DFSDgetNT(&numtype); iret = DFSDgetdatastrs(convertlabel[0], convertunit[0], Inconvertfmt, " "); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR TMPTAB ATTRIBUTES"); exit(1); } iret = DFSDgetdata(hdfname, 2, Dimsizec, TMPTAB); if (iret != 0) { printf("ERROR TMPTAB DATA\n"); exit(1); } /* else { for(i = 0;i<256;++i){ printf("%d = %10.3f\n",i,TMPTAB[i]); } } */ /***************************************************************/ iret = DFSDgetdatastrs(convertlabel[1], convertunit[1], Inconvertfmt, " "); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR TMPVAR ATTRIBUTES"); exit(1); } iret = DFSDgetdata(hdfname, 2, Dimsizec, TMPVAR); if (iret != 0) { printf("ERROR TMPVAR DATA\n"); exit(1); } /* else{ for(i = 0;i<256;++i){ printf("%d = %10.3f\n",i,TMPVAR[i]); } } */ /****************************************************************/ iret = DFSDgetdatastrs(convertlabel[2], convertunit[2], Inconvertfmt, " "); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR PRETAB ATTRIBUTES"); exit(1); } iret = DFSDgetdata(hdfname, 2, Dimsizec, PRETAB); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR PRETAB DATA"); exit(1); } /* else{ for(i = 0;i<256;++i){ printf("%d = %10.3f\n",i,PRETAB[i]); } } */ /***************************************************************/ iret = DFSDgetdatastrs(convertlabel[3], convertunit[3], Inconvertfmt, " "); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR RFLTAB ATTRIBUTES"); exit(1); } iret = DFSDgetdata(hdfname, 2, Dimsizec, RFLTAB); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR RFLTAB DATA "); exit(1); } /* else{ for(i = 0;i<256;++i){ printf("%d = %10.3f\n",i,RFLTAB[i]); } } */ /***************************************************************/ iret = DFSDgetdatastrs(convertlabel[4], convertunit[4], Inconvertfmt, " "); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR TAUTAB ATTRIBUTES"); exit(1); } iret = DFSDgetdata(hdfname, 2, Dimsizec, TAUTAB); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR TAUTAB DATA"); exit(1); } /* else{ for(i = 0;i<256;++i){ printf("%d = %10.3f\n",i,TAUTAB[i]); } } */ /***************************************************************/ iret = DFSDgetdatastrs(convertlabel[5], convertunit[5], Inconvertfmt, " "); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR PRWTAB ATTRIBUTES "); exit(1); } iret = DFSDgetdata(hdfname, 2, Dimsizec, PRWTAB); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR PRWTAB DATA "); exit(1); } /* else{ for(i = 0;i<256;++i){ printf("%d = %10.3f\n",i,PRWTAB[i]); } } */ /*****************************************************************/ iret = DFSDgetdatastrs(convertlabel[6], convertunit[6], Inconvertfmt, " "); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR OZNTAB ATTRIBUTES "); exit(1); } iret = DFSDgetdata(hdfname, 2, Dimsizec, OZNTAB); if (iret != 0) { fprintf(rptfp, "%s\n\n", "ERROR OZNTAB DATA "); exit(1); } /* else{ for(i = 0;i<256;++i){ printf("%d = %10.3f\n",i,OZNTAB[i]); } } */ } /*************************************************************** *FUNCTION GETAREATYPE * *Name- getareatype Type- Function * *Version-1.0 Date- 10/11/92 * * Programmer-Madira Mukherje(SAIC) * * * * Purpose: This function asks for cell number begin and cell * * number end for subsetting. If no subsetting required enter * * N or n . If subsetting required enter C or c and then enter * * begin cell and end cell. * * * *Output parameter- * * ibegin- parameter for begin cell number * * iend - parameter for end cell number * * * * * *Key local variables- * *areatyp- c for cell numbers or n for no subsetting requested * *cell_begin- enters beginning of cell number * *cell_end- enters end cell number * * * *Functions called- * * None * * * ***************************************************************/ void getareatype(ibegin,iend) int *ibegin,*iend; { char areatyp; int cell_begin,cell_end; printf("\nENTER IF YOU WOULD LIKE TO SUBSET\n"); printf("BASED ON CELL NUMBER(C) OR NO SUBSETTING(N)\n"); scanf("%s",&areatyp); if (areatyp=='n' || areatyp == 'N') return; printf("\nPLEASE ENTER BEGIN AND END CELL NUMBER BETWEEN 1 AND 6596:"); scanf("%d%d",&cell_begin,&cell_end); if ((cell_begin>0) || (cell_begin<=6596)) *ibegin = cell_begin - 1; if((cell_end >= cell_begin) || (cell_end <= 6596)) *iend = cell_end ; return; } /************************************************************** * FUNCTION GETDATATYPE * * Name - getdatatype Type- function * * Version- 1.0 Date - 11/10/92 * * Programmer-Madira Mukherje(SAIC) * * * * Purpose: This function output 18 labels at a time and * * through the line number asked it reaches the indicated * * parameter.It reads the line_input selects the parameter and * * applies the convert table. * * * * Input parameters- * * hdfname- name of hdf file * * reflist- refference list * * labellist- list of labels * * listlen- length of list 648 * * maxlng- maximum length for each labellist * * startpos- starting position for data. * * startpos is set to 8 because the first 7 set* * contains the conversion table. * * * * * *Output parameter- * * conv_data-converted data value * * * *Key local variables- * * nlabels- number of labels * * ref_select- reference selected * * line_select- line selected * * Par_num- parameter number * * par - name of the indicated parameter * * gmt- name of indicated gmt(string GMT) * * ibegin-default beginning cell number * * iend- default ending cell number * * * *Functions called- * * getareatype- * * conv_data * * hdf library functions * * * **************************************************************/ void getdatatype() { int i, k, nlabels, startpos=8 , listlen = 655, iret; int ibegin,iend; int short reflist[listsize]; int ref_select, line_select, line_input; char *labellist; char par_name[150], par[5], gmt[5]; if ((labellist = (char *) malloc((maxlng + 100) * listsize * sizeof(char))) != NULL) { nlabels = DFANlablist(hdfname, DFTAG_NDG, reflist, labellist, listlen, maxlng, startpos); if (nlabels == -1) { printf("ERROR GETTING ANNOTATION LABELS\n"); exit(1); } /**** enter choice of cell to be printed out in file********/ ibegin=0; iend = 6596; getareatype (&ibegin,&iend); /****** *******/ line_input = 1; for (k = 0; line_input != 0 && k < 36; ++k) { printf("LABELS OF SCIENTIFIC DATASET IN FILE \n"); printf(" ITEMNUMBER LABEL \n\n"); for (i = k * 18; i < (k * 18) + 18 && i < nlabels; ++i) { printf("%4d %s\n", i+1,labellist +(i * maxlng)); }/* end of for */ line_input = 1; while ( line_input >= 1 ) { printf("\nPLEASE ENTER ITEM_NUMBER TO BE CONVERTED IN PHYSICAL UNITS\n"); printf("ITEM NUMBER MUST BE BETWEEN 1 THROUGH %d\n", nlabels); printf("ENTER -1 TO CONTINUE AND 0 TO DISCONTINUE .\n"); scanf("%d", &line_input); if (line_input >= 1 && line_input <= nlabels) { line_select = line_input - 1; ref_select = reflist[line_select]; /**printf("This is ref_select (%d)\n", ref_select);*****/ sscanf(labellist + (line_select * maxlng), "%s%d%s%d%s", par, &par_num, gmt, &gmt_select, par_name); /* printf("GMT= %d\n",gmt_select); */ /* printf("PARAMETER NUM = %d\n",par_num); */ printf("%s\n", labellist + (line_select * maxlng)); printf("\nPLEASE WAIT.......CONVERTING DATA.......\n"); /**********reads ref number *******************************/ iret = DFSDreadref(hdfname, ref_select); if (iret != 0) { fprintf(rptfp, "ERROR GOING TO SPECIFIED REFERENCE NUMBER-"); fprintf(rptfp, "%d\n\n", ref_select); exit(1); } /* get data attributes **************************************/ iret = DFSDgetdims(hdfname, &numdims, dimsize, maxrank); if (iret != 0) { fprintf(rptfp, "ERROR IN GETTING DIMENSION\n"); exit(1); } else { fprintf(rptfp, "\n\nDIMENSIONS ARE %d by %d\n\n", dimsize[0], dimsize[1]); } /************************************************************/ iret = DFSDgetdatastrs(datalabel, dataunit, datafmt, datacoord); if (iret != 0) { fprintf(rptfp, "ERROR ON GETTING DATA ATTRIBUTES\n\n"); exit(1); } else { fprintf(rptfp, "DATA ATTRIBUTES ARE AS FOLLOWS: \n\n"); fprintf(rptfp, "%s%s\n%s%s\n%s%s\n", "LABEL: ", datalabel, "UNITS : ", dataunit, "FORMAT: ", datafmt); fprintf(rptfp, "GMT : %d\n", gmt_select); fprintf(rptfp, "VAR : %d\n\n", par_num); fprintf(rptfp, "DATA VALUES: \n\n"); } /********************************************************** * GET DATA * **********************************************************/ iret = DFSDgetNT(&numtype); iret = DFSDgetdata(hdfname, 2, dimsize, data_select); if (iret != 0) { fprintf(rptfp, "ERROR GETTING DATA\n"); exit(1); } convertdata(); /****** getareatype(&ibegin,&iend);********/ fprintf(rptfp, "CONVERTED DATA VALUES ARE \n"); fprintf(rptfp, "CELL DATA CELL DATA CELL DATA"); fprintf(rptfp, " CELL DATA \n"); for (i = ibegin; i < iend ; ++i) { if (i % 4 == 0) fprintf(rptfp, "\n"); fprintf(rptfp," %4d %10.3f ",i+1,conv_data[i]); } fprintf(rptfp, "\n"); } }/* end of while */ }/* end of for */ free(labellist); }/* end of if */ return; }/* end of function */ /************************************************************** *FUNCTION CONVERT DATA * *Name-convertdata Type- Function * *Version-1.0 Date-11/15/92 * * Programmer- Madira Mukherje(SAIC) * * * *Purpose: Assigns value to output array (var). ALL * *decoded values are representing physical units. The * *conversion tables used are stored in HDF files. * * * *Input parameter- * * Par_num- parameter number * * conv_data- converted data stored * * gmt_select- stores gmt retreived from label list of the * indicated parameter * * TMPTAB-conversion counts(1-253)to temperature(165k-345k) * * TMPVAR-conversion counts(1-253)to temp variance(.075k-85k) * * PRETAB-conversion counts(1-241)to pressure(1mb-1200mb) * * RFLTAB-conversion counts(1-253)to reflectance(0.0-1.108) * * TAUTAB-conversion counts(1-231)to TAU (0.02-119.59) * * PRWTAB-conversion counts(1-253)to precipitable water * * (humidity)(0.0-8.0)in centimeters * * OZNTAB-conversion counts (1-253) to ozone abundance (0-515) * * in dobson units * * * *Output parameter- * * conv_data-converted data value * * * *Functions called- * * None * * * **************************************************************/ void convertdata() { int j, i; if (par_num == 1 || par_num == 2 || par_num == 3 || par_num == 4) { for (j = 0; j < 6596; ++j) conv_data[j] = data_select[j]; }/* end of if */ else if (par_num == 14 || par_num == 25 || par_num == 28 || par_num == 34 || par_num == 38 || par_num == 42 || par_num == 50 || par_num == 54 || par_num == 58 || par_num == 65 || par_num == 66 || par_num == 68 || par_num == 31 || par_num == 46 || par_num == 60 || par_num == 69 || par_num == 38) { for (j = 0; j < 6596; ++j) conv_data[j] = TMPTAB[data_select[j]]; }/* end of if */ else if (par_num == 15 || par_num == 16 || par_num == 61) { for (j = 0; j < 6596; ++j) conv_data[j] = TMPVAR[data_select[j]]; }/* end of if */ else if (par_num == 11 || par_num == 12 || par_num == 13 || par_num == 27 || par_num == 30 || par_num == 33 || par_num == 37 || par_num == 41 || par_num == 45 || par_num == 24 || par_num == 49 || par_num == 53 || par_num == 57 || par_num == 64 || par_num == 67) { for (j = 0; j < 6596; ++j) conv_data[j] = PRETAB[data_select[j]]; }/* end of if */ else if (par_num == 62) { for (j = 0; j < 6596; ++j) conv_data[j] = RFLTAB[data_select[j]]; }/* end of if */ else if (par_num == 17 || par_num == 18 || par_num == 19 || par_num == 20 || par_num == 21 || par_num == 22 || par_num == 35 || par_num == 39 || par_num == 43 || par_num == 59 || par_num == 47 || par_num == 51 || par_num == 55 || par_num == 59) { for (j = 0; j < 6596; ++j) conv_data[j] = TAUTAB[data_select[j]]; }/* end of if */ else if (par_num == 70) { for (j = 0; j < 6596; ++j) conv_data[j] = PRWTAB[data_select[j]]; }/* end of if */ else if (par_num == 71) { for (j = 0; j < 6596; ++j) conv_data[j] = OZNTAB[data_select[j]]; }/* end of if */ else if (par_num == 5 || par_num == 6 || par_num == 7 || par_num == 63) { for (j = 0; j < 6596; ++j) { if (data_select[j] != 255) conv_data[j] = data_select[j]; else conv_data[j] = -1000.; } }/* end of if */ else if (par_num == 8 || par_num == 10 || par_num == 23 || par_num == 26 || par_num == 29 || par_num == 32 || par_num == 36 || par_num == 40 || par_num == 44 || par_num == 48 || par_num == 52 || par_num == 56 || par_num == 72) { for (j = 0; j < 6596; ++j) { if (data_select[j] != 255) conv_data[j] = data_select[j] / 2.; else conv_data[j] = -1000.; } }/* end of if */ else if (par_num == 9) { for (j = 0; j < 6596; ++j) { if (data_select[j] != 255) { if (gmt_select == 255) { conv_data[j] = data_select[j] / 2.; }/* end of if */ else conv_data[j] = data_select[j]; }/* end of if */ else conv_data[j] = -1000.; } }/* end of if */ }