/***************************************************************************/ /* Name - rds4gscnhdf.c Type -Program * Version - 1.0 Date - 12/13/92 Programmer - J. Travers, SAIC * Version - 2.0 Date - 05/26/94 Programmer - Langley DAAC * Version - 2.1 Date - 07/01/94 Programmer - Langley DAAC * Version - 2.2 Date - 07/21/94 Programmer - Langley DAAC * Version - 2.3 Date - 07/26/94 Programmer - Langley DAAC * * * Purpose - This program read a monthly S-4G scanner HDF file (either 2.5, * 5.0, 10.0 degree regional, or the zonal/global file). * * 05/26/94 The longitude values which are stored in the S-4G HDF files * are being stored from -180.0 to 180.0 where as the data * is being stored from 0 to 360 degrees. * * !!!!!!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!! * The longitude values in the data files have not been corrected. * Only this read program has been modified to correct this * presentation of the data. This is only affected when a * user selects data from a latitude/longitude option. * If the user decides to use an outside piece of software which * depends on these latitude/longitude values, please ignore * these values. * * 07-01-94 A correction was made to correct the assignment statement * which affected the output of 10 degree data. The user * would receive the 10 degree data but would also receive * an extra band of data since the code thought that it * was working with 5 degree data. * * 07-21-94 A correction was made in writing out the fill value for a * 32-bit word. It was writing out 2147483648.0 instead of * 2147483647.0. * * 07-26-94 The minimum and maximum values are incorrect within the * HDF data files for the longwave and shortwave parameters. * So that the user would not get this information from the * data file, the print lines for this information have * been commented out in this code. For the correct * values for all parameters, please refer to the ERBE * S-4G User's Guide. * * Input - HDF file named s4g_sc2.5_yymm_s, s4g_sc5.0_yymm_s, * s4g_sc10._yymm_s, or s4g_sc_zg_yymm_s * Output - Report file named HDF file name as above plus .rpt * * Key Local Parameters : ddate - data date of file * satcd - the satellite code of file * hdfname - name of hdf file * outfile - name of report file * numdims - number of dimensions * dimsize - dimension sizes * dataitems - reference numbers of dataitems wanted * type - tells whether user specified subset as * lat and lon or region number or none * begin1-beginning latitude in degrees or region numb * begin2-beginning longitude in degrees or 0 if region * end1 - ending latitude in degrees or region number * end2 - ending longitude in degress or 0 if region * out - pointer to report file * datatyp- type of spatial average * resol - resolution (2.5, 5.0, or 10.0 degrees) * * functions called : chkcode - checks input data * ask - ask for input * getfilenames - builds input and output file names * readhdf - reads hdf file id and file description * getarea - gets area to subset * getdatatypes- gets parameters to subset * readdata - reads data and attributes from HDF file *****************************************************************************/ #include #include #include #include "hdf.h" #define FALSE 0 #define TRUE1 1 #define first 1 #define maxlen 625 #define DFACC_read 1 #define maxlng 21 #define listsize 650 #define maxrank 2 #define maxlength 5 #define FILL 2147473647.0 int main() { int iret, datatyp, resol; int status = FALSE; unsigned short int dataitems[listsize]; float begin1, begin2, end1, end2; char type[2],contkey[2]; char ddate[5], satcd[2], hdfname[50], outfile[50]; FILE *out; /* function prototypes */ int Chkcode(); char *ask(); void getfilenames(); void readhdf(); void getarea(); void getdatatypes(); void readdata(); /* prompt for input information */ if (!status){ printf(" *******************************************************************\n"); printf(" * *\n"); printf(" * S-4G HDF SCANNER READ PROGRAM *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * Version 2.3 July 26, 1994 *\n"); printf(" * *\n"); printf(" * NOTE TO THE USER!!!!! *\n"); printf(" * FOR YOUR INFORMATION AS HOW THE DATA HAS BEEN STORED IN THE *\n"); printf(" * S-4G HDF FILE, LATITUDE VALUES AND LONGITUDE VALUES HAVE *\n"); printf(" * BEEN ADDED TO THE INPUT FILE. PLEASE IGNORE THESE VALUES *\n"); printf(" * WHEN USING OTHER HDF PACKAGES BECAUSE THESE NUMBERS WILL NOT *\n"); printf(" * REPRESENT THE DATA CORRECTLY. THIS READ PROGRAM HAS BEEN *\n"); printf(" * MODIFIED TO HANDLE THESE VALUES. IF YOU HAVE ANY QUESTIONS, *\n"); printf(" * PLEASE FEEL FREE TO CONTACT THE LANGLEY DAAC. *\n"); printf(" * THE WAY THAT THE LATITUDE AND LONGITUDE VALUES ARE STORED IN *\n"); printf(" * THE DATA FILE WILL NOT HAVE ANY MEANING OR REPRESENT THE *\n"); printf(" * DATA CORRECTLY IN OUTSIDE SOFTWARE PACKAGES. *\n"); printf(" * THIS READ PROGRAM HAS BEEN CORRECTED WHEN A USER SELECTS 10 *\n"); printf(" * DEGREE DATA, THE USER WILL GET THIS DATA. ORIGINALLY, THE *\n"); printf(" * USER RECEIVED 10 DEGREE DATA AND AN EXTRA BAND OF DATA. *\n"); printf(" * THIS WAS BECAUSE IN THE COMPARISON STATEMENT FOR WHICH *\n"); printf(" * DEGREE SELECTION, AN ASSIGNMENT STATEMENT WAS SET INSTEAD. *\n"); printf(" * *\n"); printf(" * 07-26-94 THE MINIMUM AND MAXIMUM VALUES ARE INCORRECT WITHIN*\n"); printf(" * THE HDF DATA FILES FOR THE LONGWAVE AND SHORTWAVE PARAMETERS.*\n"); printf(" * SO THAT THE USER WOULD NOT GET THIS INFORMATION FROM THE *\n"); printf(" * DATA FILE, THE PRINT LINES FOR THIS INFORMATION HAVE BEEN *\n"); printf(" * COMMENTED OUT IN THIS CODE. FOR THE CORRECT VALUES FOR ALL *\n"); printf(" * PARAMETERS, PLEASE REFER TO THE ERBE S-4G USER'S GUIDE. *\n"); printf(" * PLEASE IGNORE THESE VALUES WHEN USING OUTSIDE SOFTWARE *\n"); printf(" * PACKAGES! *\n"); printf(" * *\n"); printf(" *******************************************************************\n"); printf("\nPlease enter Q to exit the program or any other character to continue. "); scanf("%s",contkey); if (contkey[0]=='Q' || contkey[0]=='q'){ printf("\n\nExiting Program ..."); exit( 1 ); } else{ do{ ask(ddate,satcd,&datatyp,&resol); iret = Chkcode(ddate,satcd,&datatyp,&resol); } while(iret != TRUE1); } } /* get hdf file name and name of output file */ getfilenames(ddate,satcd,hdfname,outfile,datatyp,resol); /* open output file */ if ((out = fopen(outfile,"wt")) == NULL){ printf("\n!! Cannot open output file"); exit( -1 ); } /* call function to read file description and file id and dimensions */ printf("Reading file id and description ...\n\n"); readhdf(out,hdfname); /* call function to get area to subset */ getarea(type,&begin1,&begin2,&end1,&end2,datatyp); /* call function to get parameters to subset */ getdatatypes(out,hdfname,dataitems,datatyp,resol); /* call function to read data */ printf("\n\nOutput file name is %s\n\n",outfile); printf("\n\nGetting data, Please wait ...\n\n"); readdata(out,hdfname,dataitems,type,begin1,begin2,end1,end2, datatyp,resol); printf("\n\n"); } /* End of main function */ /****************************************************************************/ /* Name - Chkcode Type - Function * Version - 1.0 Date - 09/08/92 Programmer - J. Travers,SAIC * 2.0 12/13/92 J. Travers,SAIC * * Purpose - This function checks for correct input * * Input - arg1 - data date * arg2 - satellite code * arg3 - spatial average type * arg4 - resolution type ****************************************************************************/ int Chkcode(arg1,arg2,arg3,arg4) char *arg1, *arg2; int *arg3, *arg4; { if ((!isdigit(arg1[0])) || (!isdigit(arg1[1])) || (!isdigit(arg1[2])) || (!isdigit(arg1[3])) || (!isdigit(arg2[0]))) { return FALSE; } else if ((*arg3 < 1) || (*arg3 > 3) || (*arg4 < 1) || (*arg4 > 3)){ return FALSE; } else return TRUE1; } /****************************************************************************/ /* Name - Ask Type - Function * Version - 1.0 Date - 09/08/92 Programmer - J. Travers, SAIC * 2.0 12/13/92 J. Travers, SAIC * * Purpose - This function ask the user for input * * Output - ddate - the data date * satcd - the satellite code of data * datatyp - type of spatial average regional, zonal, global * resol - type of resolution 2.5, 5.0, 10.0 degrees * ****************************************************************************/ char *ask(ddate,satcd,datatyp,resol) char *ddate, *satcd; int *datatyp, *resol; { printf("\n\nEnter data date and satellite code of data to read \n"); printf("separated by a space. (Enter H for help, Q to Quit):"); scanf("%s",ddate); /* exit if requested */ if (ddate[0] == 'Q' || ddate[0] == 'q') { exit(1); } /* help if requested */ else if (ddate[0] =='H' || ddate[0] == 'h'){ printf("\n"); printf("============================================================\n\n"); printf("Enter data date (yymm), Example: 8504\n\n"); printf("Enter satellite code - one of following:\n"); printf(" 1- NOAA-9 4- NOAA-9 and NOAA-10\n"); printf(" 2- ERBS 5- ERBS and NOAA-9\n"); printf(" 3- NOAA-10 6- ERBS and NOAA-10\n"); printf(" 7- All 3 satellites\n\n"); printf("============================================================\n\n"); } else{ scanf("%s",satcd); printf ("\n\n1) Regional 2) Zonal 3) Global \n\n"); printf ("Choose data type from above choices : "); scanf("%d",datatyp); if (*datatyp != 3) { printf ("\n\n1) 2.5 degree 2) 5.0 degree 3) 10.0 degree \n\n"); printf ("Choose resolution from the above choices : "); scanf("%d",resol); } else *resol = 1; } } /****************************************************************************/ /* Name - getfilenames type - function * Version - 1.0 Date - 09/08/92 Programmer - J. Travers, SAIC * 2.0 12/14/92 J. Travers, SAIC * * Purpose - This function builds the names of the input and output files * * Input: ddate - the data date of the data * satcd - the satellite code of the data * datatyp - the type of spatial average * resol - resolution type * * Output: hdfname - name of HDF input file * outfile - name of output report file ***************************************************************************/ void getfilenames(ddate,satcd,hdfname,outfile,datatyp,resol) char *ddate, *satcd, *hdfname, *outfile; int datatyp, resol; { /* create hdfname */ if (datatyp == 1 && resol == 1){ strcpy(hdfname,"s4g_sc2.5_"); strncat(hdfname,ddate,4); strcat(hdfname,"_"); strncat(hdfname,satcd,1); } else if (datatyp == 1 && resol == 2){ strcpy(hdfname,"s4g_sc5.0_"); strncat(hdfname,ddate,4); strcat(hdfname,"_"); strncat(hdfname,satcd,1); } else if (datatyp == 1 && resol == 3){ strcpy(hdfname,"s4g_sc10._"); strncat(hdfname,ddate,4); strcat(hdfname,"_"); strncat(hdfname,satcd,1); } else if (datatyp >= 2){ strcpy(hdfname,"s4g_sc_zg_"); strncat(hdfname,ddate,4); strcat(hdfname,"_"); strncat(hdfname,satcd,1); } /* create output file name */ strncpy(outfile,hdfname,16); *(outfile + 16) = NULL; strcat(outfile,".rpt"); printf("\n\nInput file is %s",hdfname); printf("\nOutput file is %s\n\n",outfile); } /****************************************************************************/ /* Name - readhdf Type - function * Version - 1.0 Date - 12/14/92 Programmer - J. Travers,SAIC * * Purpose - This function reads the file id and file description * * Input: hdfname - name of HDF input file * out - pointer to output report file * * Output: NONE * * Key Local Parameters : iret - return code from HDF routines * dfile - pointer to HDF file * id - file id * filedesc - file description * * Functions Called : HDF functions to get file id and descriptions ***************************************************************************/ void readhdf(out,hdfname) char *hdfname; FILE *out; { int iret,dfile,i; char id[96],filedesc[625]; dfile = Hopen(hdfname,DFACC_read,0); if (dfile == NULL){ fprintf(out,"%s\n\n","Error in opening HDF file"); exit(1); } /* get file id */ iret = DFANgetfid(dfile,id,maxlen,first); if (iret == -1){ fprintf(out,"%s\n\n","Error in getting file id"); exit(1); } else fprintf(out,"%s\n\n%s\n\n","File ID: ",id); /* get file description */ iret = DFANgetfds(dfile,filedesc,maxlen,first); if (iret == -1){ fprintf(out,"%s\n\n","Error in getting file description"); exit(1); } else{ fprintf(out,"%s\n\n","File description is as follows:"); for (i=0; i 15 || i == nlabels - 1){ printf("\nPlease choose the numbers of the data items you wish to dump.\n"); printf("Note that the item numbers skip on daily and hourly parameters to\n"); printf("show the number of days or hours that you will receive.\n"); printf("Enter -1 to continue to next list or 0 to end selection portion of program.\n\n"); while (itemnumber != 0 || itemnumber != -1) { scanf("%d",&itemnumber); if (itemnumber == -1) break; if (itemnumber == 0){ dataitems[k] = 0; return; } /* get daily parameters reference numbers */ if (itemnumber==9 || itemnumber==100 || itemnumber==131 || itemnumber==162 || itemnumber==193 || itemnumber==224 || itemnumber==255 || itemnumber==430 || itemnumber==461 || itemnumber==492 || itemnumber==523){ for (count = itemnumber -1; count < itemnumber - 1 + 31; count++){ dataitems[k] = reflist[count]; k++; } } /* get hourly parameters reference numbers */ else if (itemnumber==40 || itemnumber==64 || itemnumber==286 || itemnumber==310 || itemnumber==334 || itemnumber==358 || itemnumber==382 || itemnumber==406 || itemnumber==554 || itemnumber==578 || itemnumber==602 || itemnumber==626){ for (count = itemnumber - 1; count < itemnumber - 1 + 24; count++){ dataitems[k] = reflist[count]; k++; } } else{ dataitems[k] = reflist[itemnumber-1]; k++; } } j=1; } } dataitems[k] = 0; } /*************************************************************************/ /* Name - getarea type - function * * Version - 1.0 Date -10/02/92 Programmer - J. Travers,SAIC * * 2.0 12/14/92 J. Travers,SAIC * * * * Purpose - This functions asks the user to enter the latitude and * * longitude ranges, region numbers or band number * * to subset data * * * * Input Parameters - datatyp - type of spatial average * * * * Output Parameters -type - enter lat & lon, regions, or none * * begin1-beginning latitude or region number * * begin2-beginning longitude or 0 if region * * end1 - ending latitude or region number * * end2 - ending longitude or 0 if region * * * * Key Local Parameters - kind - subset by lat and lon, region, or none * * * * Functions Called - NONE * *************************************************************************/ void getarea(type,begin1,begin2,end1,end2,datatyp) char *type; float *begin1,*begin2,*end1,*end2; int datatyp; { char kind[2]; /* regional data */ if (datatyp == 1){ printf("Enter whether you would like to further subset based on latitude\n"); printf("and longitude (L), region number (R), or no subsetting (N) "); scanf("%s",kind); *type = toupper(kind[0]); if (type[0] == 'L'){ printf("\n\nEnter beginning and ending latitude (-90 to 90) "); scanf("%f %f",begin1,end1); /* 05-25-94 Error Checking */ if (*begin1 > *end1){ printf("**********************************************************\n"); printf("* ERROR - The beginning latitude value cannot be greater *\n"); printf("* than the ending value. *\n"); printf("* Program has terminated. *\n"); printf("**********************************************************\n"); exit ( -1 ); } else if ( (*begin1 < -90.0) || (*end1 < -90.0) ){ printf("*********************************************************\n"); printf("* ERROR - The latitude value cannot be less than -90.0. *\n"); printf("* Program has terminated. *\n"); printf("*********************************************************\n"); exit ( -1 ); } else if ( (*begin1 > 90.0) || (*end1 > 90.0) ){ printf("***********************************************************\n"); printf("* ERROR - The latitude value cannot be greater than 90.0. *\n"); printf("* Program has terminated. *\n"); printf("***********************************************************\n"); exit ( -1 ); } printf("\n\nEnter beginning and ending longitude (0 to 360) "); scanf("%f %f",begin2,end2); /* 05-25-94 Error Checking */ if (*begin2 > *end2){ printf("***********************************************************\n"); printf("* ERROR - The beginning longitude value cannot be greater *\n"); printf("* than the ending value. *\n"); printf("* Program has terminated. *\n"); printf("***********************************************************\n"); exit ( -1 ); } else if ( (*begin2 < 0.0) || (*end2 < 0.0) ){ printf("********************************************************\n"); printf("* ERROR - The longitude value cannot be less than 0.0. *\n"); printf("* Program has terminated. *\n"); printf("********************************************************\n"); exit ( -1 ); } else if ( (*begin2 > 360.0) || (*end2 > 360.0) ){ printf("*************************************************************\n"); printf("* ERROR - The longitude value cannot be greater than 360.0. *\n"); printf("* Program has terminated. *\n"); printf("*************************************************************\n"); exit ( -1 ); } } else if (type[0] == 'R') { printf("\n\nEnter beginning and ending region number "); printf("\n\n(1-10368: 2.5 degree) (1-2592: 5.0 degree) (1-648: 10.0 degree) "); scanf("%f%f",begin1,end1); *begin2 = 0.0; *end2 = 0.0; } else if (type[0] == 'N'){ *begin1 = 0.0; *begin2 = 0.0; *end1 = 0.0; *end2 = 0.0; } else{ printf ("\n\nWrong subsetting entry ... Exiting program"); exit(1); } } /* zonal data */ else if (datatyp == 2){ printf("Enter whether you would like to futher subset by latitude band "); printf("number (B) or no subsetting (N) "); scanf("%s",kind); *type = toupper(kind[0]); if (type[0] == 'B'){ printf("\n\nEnter beginning and ending band number (1-72: 2.5 degree)\n"); printf("(1-36: 5.0 degree) (1-18: 10.0 degree) "); scanf("%f%f",begin1,end1); *begin2 = 0.0; *end2 = 0.0; } else if (type[0] == 'N'){ *begin1 = 0.0; *begin2 = 0.0; *end1 = 0.0; *end2 = 0.0; } else{ printf("\n\nWrong subsetting entry ... Exiting program"); exit(1); } } /* global data */ else{ type[0] = 'G'; *begin1 = 0.0; *begin2 = 0.0; *end1 = 0.0; *end2 = 0.0; } } /***************************************************************************/ /* Name - readdata type - function * * Version - 1.0 Date-10/05/92 Programmer- J. Travers,SAIC * * 2.0 12/14/92 J. Travers,SAIC * * * * Purpose - This function gets the dimensions of the data slice, dimension * scales, and attributes, and then determines the data * * slice to retrieve and using the appropriate reference number * * gets the appropriate data, data attributes (as labels,etc) * * max, min, and scale factor. It also applies the scale * * factor to the data before printing it out. * * * * Input Parameters - hdfname - name of hdf file to read * * dataitems- stores reference numbers of data chosen * * type-type of subsetting (lat,lon, region #, band * * number or none) * * begin1- beginning latitude,region, or band number * * begin2- beginning longitude or 0 * * end1- ending latitude, region, or band number * * end2- ending longitude or 0 * * datatyp - type of spatial average * * resol - type of resolution * * * * Output Parameters - none * * * * Key Local Parameters - winst - stores starting dimensions of data slice* * windims- stores length of slice * * dims - stores dimension of data array * * data - stores data gotten from HDF file * * scale - stores scale factor * * datalabel - stores label for data * * dataunit- stores units for data * * datafmt - stores format for data * * sclabel - stores scale factor as annotation text* * max - stores maximum value * * min - stores minimum value * * reg1, reg2 - actual regions obtained in slice * * dimsize - size of each dimension * * numdims - number of dimension in the SDS * * dimscale - array of dimension scales * * dimlab - dimension label * * dimunt - dimension units * * dimfmt - dimension format * * numtype - stores datatype of SDS * * index - index into data array * * resoltn - stores resoltn 2.5, 5.0, 10.0 * * factor - factor for dimension scales * * * * Subroutines Called - HDF routines to read the SDS data slice, max,min * * data attributes, etc. * ***************************************************************************/ void readdata(out,hdfname,dataitems,type,begin1,begin2,end1,end2, datatyp,resol) char *hdfname,*type; int datatyp,resol; float begin1,begin2,end1,end2; unsigned short int dataitems[listsize]; FILE *out; { int8 data8[10368], max8, min8,dimscal8[144]; int16 data16[10368], max16, min16,dimscal16[144]; int32 winst[maxrank], windims[maxrank], dims[maxrank], data32[10368]; int winend[maxrank], scale, max32, min32,i,j,k,iret,numdims,index,numtype; int reg1, reg2,iloop1,iloop2,outindex; int32 dimscal32[144], dimsize[maxrank]; char datalabel[46], datafmt[6], dataunit[16], datacoord[2], sclabel[5]; char dimlab[2][40], dimunt[30], dimfmt[5]; float datavalue, factor, resoltn, latindex; /* according to reference numbers go to next data set */ k = 0; while (dataitems[k] != 0){ iret = DFSDreadref(hdfname,dataitems[k]); if (iret == -1) { fprintf(out,"Error on going to specified reference number - "); fprintf(out,"%d\n\n", dataitems[k]); exit(1); } /* get dimensions of SDS */ if (k == 0){ iret = DFSDgetdims(hdfname,&numdims,dimsize,maxrank); if (iret != 0){ fprintf(out,"%s\n\n","Error getting dimensions"); exit(1); } else fprintf(out,"\n\nDimensions are %d by %d\n\n",dimsize[0], dimsize[1]); /* get number type */ iret = DFSDgetNT(&numtype); /* get dimension attributes*/ for (i=1;i<=numdims;++i){ iret = DFSDgetdimstrs(i,dimlab[i-1],dimunt,dimfmt); if (iret != 0){ fprintf(out,"%s\n\n","Error on getting dimension attributes"); exit(1); } else{ fprintf(out,"%s%s\n%s%s\n%s%s\n\n","Description : ",dimlab[i-1], "Units : ",dimunt,"Format : ",dimfmt); } } /* get dimension scales for all but global data */ if (datatyp != 3){ for (i=1; i<=numdims; ++i){ if (numtype == 24) iret = DFSDgetdimscale(i,dimsize[i-1],dimscal32); else if (numtype == 22) iret = DFSDgetdimscale(i,dimsize[i-1],dimscal16); else if (numtype == 20 && datatyp==2 && resol==3) iret = DFSDgetdimscale(i,dimsize[i-1],dimscal16); else if (numtype == 20) iret = DFSDgetdimscale(i,dimsize[i-1],dimscal8); if (iret != 0){ fprintf(out,"%s\n\n","Error on getting dimension scales"); exit(1); } else{ /* set up appropriate factors for arithmetic */ if (datatyp == 1 && resol == 1){ factor = 2.5; } else if (datatyp == 1 && resol == 2){ factor = 5.0; } else if (datatyp == 1 && resol == 3){ factor = 10.0; } else{ factor = 1.0; } fprintf(out,"%s %d %s\n\n","Dimension number", i,"scales: "); for (j=0; j dimsize[1]){ windims[1] = dimsize[1]; } if (windims[0] > dimsize[0]){ windims[0] = dimsize[0]; } dims[0] = windims[0]; dims[1] = windims[1]; reg1 = (winst[0] - 1)*dimsize[1] + 1; reg2 = winend[0]*dimsize[1]; } else if (type[0] == 'L'){ if (resol == 1){ resoltn = 2.5; } /* 07-01-94 else if (resol = 2){ This is an assignment statement. */ else if (resol == 2){ resoltn = 5.0; } else if (resol == 3){ resoltn = 10.0; } /* subset by latitude and longitude */ /* winst[0] = (int) (((90.0 - end1)/resoltn) + 1); winst[1] = (int) (((-180.0 - begin2)/resoltn)*-1 + 1); winend[0] = (int)(((90.0 - begin1)/resoltn) + 1); winend[1] = (int) (((-180.0 - end2)/resoltn)*-1 + 1); */ /* Langley DAAC 5/26/94 - adjusted for 180 degree offset problem */ winst[0] = (int) (((90.0 - end1)/resoltn) + 1); winst[1] = (int) (((0.0 + begin2)/resoltn) + 1); winend[0] = (int)(((90.0 - begin1)/resoltn) + 1); winend[1] = (int) (((0.0 + end2)/resoltn) + 1); if (winst[0] > dimsize[0]) winst[0] = dimsize[0]; if (winst[1] > dimsize[1]) winst[1] = dimsize[1]; if (winend[0] > dimsize[0]) winend[0] = dimsize[0]; if (winend[1] > dimsize[1]) winend[1] = dimsize[1]; windims[0] = winend[0] - winst[0] + 1; windims[1] = winend[1] - winst[1] + 1; dims[0] = windims[0]; dims[1] = windims[1]; } else if (type[0] == 'N' || type[0] == 'G'){ /* 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]; } else if (type[0] == 'B'){ /* subset by latitude band number */ winst[0] = begin1; winst[1] = 1; winend[0] = end1; winend[1] = 1; windims[0] = end1 - begin1 + 1; windims[1] = 1; dims[0] = windims[0]; dims[1] = windims[1]; } /* get data attributes */ iret = DFSDgetdatastrs(datalabel,dataunit,datafmt,datacoord); if (iret != 0) { fprintf(out,"\n\nError on getting data attributes\n\n"); exit(1); } else { fprintf(out,"Data attributes are as follows:\n\n"); fprintf(out,"%s%s\n%s%s\n%s%s\n\n","Label : ",datalabel,"Units : ", dataunit,"Format: ",datafmt); } /* get data max and min values for 32 bit data*/ if (numtype == 24){ iret = DFSDgetrange(&max32,&min32); if (iret == -1) { fprintf(out,"Error on getting data max and min\n\n"); exit(1); } /* 07-26-94 The minimum and maximum values are incorrect within the HDF data files for the longwave and shortwave parameters. So that the user would not get this information from the data file, the print lines for this information have been commented out in this code. For the correct values for all parameters, please refer to the ERBE S-4G User's Guide. else { fprintf(out,"%s%d\n","Data Max: ",max32); fprintf(out,"%s%d\n\n","Data Min: ",min32); } */ /* get data slice */ iret = DFSDgetslice(hdfname,winst,windims,data32,dims); if (iret == -1) { fprintf(out,"Error on getting data slice\n\n"); exit(1); } else { iret = DFANgetlabel(hdfname,DFTAG_SD,dataitems[k],sclabel,maxlength); if (iret == -1) { fprintf(out,"Error on getting scale factor annotation\n\n"); exit(1); } scale = atoi(sclabel); fprintf(out,"Scale factor of %d has been applied to the data\n\n",scale); /* print out message for data arrangement */ if (type[0] == 'R'){ fprintf(out,"\nSlice to encompass regions desired starts at region "); fprintf(out,"%5d and ends at region %5d\n",reg1,reg2); fprintf(out,"Values are printed by ascending region number from "); fprintf(out,"left to right\n\n"); fprintf(out,"Region Data \n\n"); outindex = reg1; } else if (type[0] == 'L'){ fprintf(out,"Slice encompasses latitude %6.1f to %6.1f ",end1, begin1); fprintf(out,"and longitude %6.1f to %6.1f\n",begin2,end2); fprintf(out,"Values are printed in sections representing all "); fprintf(out,"requested longitudes for a given latitude\n\n"); fprintf(out,"Please note that lat and lon numbers are for the top and left "); fprintf(out,"lat and lon of the cell.\nTherefore the last latitude will be "); fprintf(out,"%4.1f degrees less than what you specified.\n\n",factor); } else if (type[0] == 'B'){ fprintf(out,"Slice encompasses zonal values for latitude band "); fprintf(out,"%2d to %2d\n",(int)begin1,(int)end1); fprintf(out,"Values are printed by ascending band number\n\n"); fprintf(out,"Band # Data \n\n"); outindex = (int) begin1; } else if (type[0] == 'G'){ fprintf(out,"Slice is all 3 global values for 2.5, 5.0, 10.0 "); fprintf(out,"degrees, respectively\n\n"); } else if (type[0] == 'N' && datatyp == 1){ fprintf(out,"All data values are printed out for resolution "); fprintf(out,"chosen. Each section represents all longitude\n"); fprintf(out,"values for a given latitude\n\n"); fprintf(out,"Please note that lat and lon numbers are for the top and left "); fprintf(out,"lat and lon of the cell.\nTherefore the last latitude will be "); fprintf(out,"%4.1f degrees less than what you specified.\n\n",factor); } else if (type[0] == 'N' && datatyp == 2){ fprintf(out,"All data values are printed out for resolution "); fprintf(out,"chosen. Each section represents all\n"); fprintf(out,"latitude bands.\n\n"); fprintf(out,"Band # Data \n\n"); outindex = 1; } /* print out data after applying scale factor */ if (dims[1] == 1){ iloop1 = dims[1]; iloop2 = dims[0]; } else { iloop1 = dims[0]; iloop2 = dims[1]; } for (i=0; i