/************************************************************************ * * * PROGRAM: bio_burn_sav_for_read.c * * * * VERSION: 1.1 DATE: December 03, 1996 * * VERSION: 2.0 DATE: February 12, 1997 * * VERSION: 3.0 DATE: February 21, 1997 * * VERSION: 4.0 DATE: January 31, 1999 * * * * PURPOSE: The purpose of this code is to read the Biomass * * Burning Tropical data set by Dr. Wei Min Hao. * * This sample read software concentrates on the savanna * * and forest data file granules. * * * * ALGORITHM: None. * * * * INVOCATION: read_5x5_hao_sav_for datafile * * WHERE: * * - optional * * input ASCII data file * * * * FILE/RECORD REFERENCES: * * Currently, this program will produce no output files. ALL * * output will be printed to the screen. * * * * EXTERNAL ROUTINES: None. * * * * INTERNAL ROUTINES: * * #include * * #include * * #include * * * * NOTES: This program has been set up to read all files which * * pertain to the Tropical data set. Each file has a * * different layout. All files are in ASCII. * * The read program is able to identify which location the * * user would like to read. The locations are Africa, * * America, and Asia. * * This read software reads the savanna and forest biomass * * burned granules. * * These files consist of the first four lines of text * * information. * * This information pretains to a particular file. The rest of * * the file consists of actual data. * * There are three parameters in these granules: * * 1. Coordinate (latitude and longitude value) * * 2. Latitude * * 3. Longitude * * 4. Annual Value * * 5. January * * 6. February * * 7. March * * 8. April * * 9. May * * 10. June * * 11. July * * 12. August * * 13. Septemeber * * 14. October * * 15. November * * 16. December * * * * CONTACT INFORMATION: If you have any questions with the data or * * software, please contact: * * EOSDIS Langley DAAC * * User and Data Services * * NASA Langley Research Center * * Mail Stop 157D * * Hampton, Virginia 23681-2199 * * U.S.A. * * * * Telephone: (757) 864-8656 * * FAX: (757) 864-8807 * * E-mail: support-asdc@earthdata.nasa.gov * * * * REVISION INFORMATION: * * 12-03-1996 Sample read software files were renamed. This only * * the comment section of the software. The makefile for * * this code was also changed. * * * * 02-12-1997 Corrected the August array. August values were printing * * for Annual parameter. * * * * 02-21-1997 Corrected the arrays for storing months. Off by one * * position. * * * * 01-31-1999 Updated code with new address change wording of some code. * * * ************************************************************************/ #include #include #include #define LINESIZE 300 #define NUM_PARAMS 16 main(argc,argv) int argc; char *argv[]; { char in_file[LINESIZE], /* data file to be read */ mon_coord[10], fname[LINESIZE], /* data file name given in command line */ tmp[25], /* place holding for the param selection */ list[3], buf[LINESIZE]; /* buffer to hold the three lines of header */ int count, counter, /* counter */ lat, lon, /* latitude and longitude values */ params[NUM_PARAMS], /* integer format for params selected */ i,j; /* loop counters */ float data_value, /* data value */ values[NUM_PARAMS]; FILE *fptr; /* file pointer to input data file */ void Display_greeting(); /* Initialize the params array to 0 */ for (count=0; count < NUM_PARAMS; count++) params[count] = -99; (void) Display_greeting(); /* Get name of data file to be read */ if (argc == 1) { printf("Please enter the name of the data file to be read: "); scanf("%s",fname); strcpy(in_file,fname); } else { strcpy(in_file,argv[1]); } printf("\n\n"); printf("The data file to be read is %s \n", in_file); /* Open data file to read */ fptr = fopen(in_file,"r"); /* Check to see if eof encountered */ if(fptr == NULL) { printf("**********************************************************\n"); printf("* *\n"); printf("* ERROR -- UNABLE TO OPEN THE DATA SET *\n"); printf("* PROGRAM TERMINATED *\n"); printf("* *\n"); printf("**********************************************************\n"); exit(-1); } /* Print the parameters available on this data file */ printf("\n\n"); printf("The following are the parameters on this data file: \n"); printf("\n\n"); printf("No. Parameter Units \n"); printf("--- --------- ----- \n"); printf("\n"); printf(" 1. Coordinate Degrees\n"); printf(" 2. Latitude Degrees\n"); printf(" 3. Longitude Degrees\n"); printf(" 4. Annual x 10^3 Tons/Year\n"); printf(" 5. January x 10^3 Tons/Month\n"); printf(" 6. February x 10^3 Tons/Month\n"); printf(" 7. March x 10^3 Tons/Month\n"); printf(" 8. April x 10^3 Tons/Month\n"); printf(" 9. May x 10^3 Tons/Month\n"); printf(" 10. June x 10^3 Tons/Month\n"); printf(" 11. July x 10^3 Tons/Month\n"); printf(" 12. August x 10^3 Tons/Month\n"); printf(" 13. Septemeber x 10^3 Tons/Month\n"); printf(" 14. October x 10^3 Tons/Month\n"); printf(" 15. November x 10^3 Tons/Month\n"); printf(" 16. December x 10^3 Tons/Month\n"); printf("\n\n"); /* Selection of parameters whether all or some */ list[0] = 'Q'; while ((list[0]!='a') && (list[0]!='A') && (list[0]!='s') && (list[0]!='S') && (list[0]!='x') && (list[0]!='X')) { printf(" Do you want all parameters to be printed \n"); printf(" Please select: a or A for All; S for Some; X to eXit: "); scanf("%s",tmp); strcpy(list,tmp); printf("\n\n"); } /* end of while statement */ if ((list[0] == 'a') || (list[0] == 'A')) { for(count=0; count < NUM_PARAMS; count++) params[count] = count; } else if ((list[0] == 's') || (list[0] == 'S')) { printf("**** Selection of parameters ***\n"); tmp[0] = 'S'; count = 0; while(((tmp[0] != 'x') && (tmp[0] != 'X') || (tmp[0] != 'q') && (tmp[0] != 'Q')) && (count < NUM_PARAMS)) { printf("Please enter parameter# you wish to view \n"); printf("Enter q to end selection process or X to exit the program--> "); scanf("%s",tmp); strcpy(list,tmp); if ((list[0] == 'q') || (list[0] == 'Q')) { if(params[0] == -99) { strcpy(tmp," "); printf("\n"); printf(" Selection of parameters have not yet been made \n"); printf(" Do you want to exit the program -- enter x or X \n"); printf(" OR Enter parameters numbers \n"); scanf("%s",tmp); strcpy(list,tmp); } else break; } if ((list[0] == 'x') || (list[0] == 'X')) { printf("\n\n"); printf(" **** EXITING THE PROGRAM PER YOUR REQUEST ****\n"); printf("\n\n"); exit(0); } if((atoi(list) > NUM_PARAMS) || (atoi(list) <= 0)) { printf("\n"); printf("A NUMBER NOT AVAILABLE FOR PARAMETER SELECTION HAS BEEN ENTERED\n"); strcpy(tmp," "); } else { params[count] = atoi(list) - 1; count++; } } /* end of the for statement */ } /* end of the if-else statement */ else if ((list[0] = 'x') || (list[0] = 'X')) { printf("\n\n"); printf(" **** EXITING THE PROGRAM PER YOUR REQUEST *****\n"); exit(0); } /* Read the first four lines of the data file since this is header info */ for(i=1; i<= 4; i++) fgets(&buf[0],LINESIZE,fptr); /* Print the headers for the requested parameters */ for (i = 1; i <= count; i++) { switch (params[i-1]) { case 0: printf("Coord-M"); break; case 1: printf(" Lat "); break; case 2: printf(" Lon "); break; case 3: printf("Annual"); break; case 4: printf(" Jan "); break; case 5: printf(" Feb "); break; case 6: printf(" Mar "); break; case 7: printf(" Apr "); break; case 8: printf(" May "); break; case 9: printf(" Jun "); break; case 10: printf(" Jul "); break; case 11: printf(" Aug "); break; case 12: printf(" Sep "); break; case 13: printf(" Oct "); break; case 14: printf(" Nov "); break; case 15: printf(" Dec "); break; default: break; } /* end of case statement */ } /* end of the for loop */ printf("\n"); counter = 0; /* counter is for # of records read */ /* This while loop read all data records until the EOF. */ while ((feof(fptr) == 0)) { for (i=0; i