/* @(#) File name: fsdf_vtoc.c Release: 1.1 Date: 7/28/94, 14:00:09 */ /**************************************************************************** FUNCTION: VTOC_read AUTHOR: Meng-chun Lin, Mail stop 157B, EOSDIS LANGLEY DAAC, Hampton, VA 23666 (804)864-8657. e-mail: M.LIN@LaRC.NASA.GOV PURPOSE/DESCRIPTION: Function VTOC_read() reads a record of FIRE Standard Data Format (SDF) Volume Table Of Contents (VTOC). This can either be a record in the VTOC file or the first physical record of the ancillary and/or observation data files. The VTOC records are in ASCII format. There are 10 fields defined in a SDF VTOC record with a total of 160 bytes. Each field is separated with at least a blank. See NOTES section for the detailed fields definitions. Bytes 81 through 160 is defined for geometry description. In SRB data, however, they are subdivided into the following fields: 81 - 88 keyword ( AUXFIL=) to identify ancillary file name 89 - 96 ancillary file name 97 - 160 blanks INVOCATION: returned_value = VTOC_read (fptr, rec_size, &toc); WHERE - I is the file pointer for the Volume Table of Contents (VTOC) file, ancillary file, or observation data files. - I is the size of each VTOC record (some data sets come in 80 bytes long, some 160 bytes long). - I, o returns a record that stores all individual field values from reading a VTOC record. - O returns the length of a VTOC record string when there is no error, or returns 0 when it's a blank line (or extra "CR" character). It returns -1 if it's a bad file pointer or end of file is reached. FILE/RECORD REFERENCES: None. EXTERNAL ROUTINES: None. NOTES: 1. The field definitions for VTOC file are described as follows: field pos. field descriptions (starts with 1) ------------- -------------------------------------------------- 1 - 4 file sequence number 6 - 11 record number within a file 13 - 20 record name 22 - 35 earliest observation date and gmt in file 37 - 50 latest observation date and gmt in file 52 - 57 northern most latitude covered by data in the file 59 - 64 southern most latitude covered by data in the file 66 - 72 western most longitude covered by data in the file 74 - 80 eastern most longitude covered by data in the file Fields 81 through 160 are used for geometry description. In SRB data, however, they are subdivided into the following fields: 81 - 88 keyword ( AUXFIL=) to identify ancillary file name 89 - 96 ancillary file name 97 - 160 blank fields 2. Because the VTOC records of some data sets come with two "Carriage Return" characters at the end of the record. The next call to this function will result in a blank line (i.e., a return value of 0). *****************************************************************************/ #ifdef sccs static char sccsid[] = "File: fsdf_vtoc.c Release: 1.1 Date: 7/28/94, 14:00:09" #endif /* System include files. */ #include #include #include /* Local C library include file. */ #include "fire_sdf.h" int VTOC_read (fptr, rec_size, toc) FILE *fptr; int rec_size; vtoc_data *toc; /* Data type defined in local include file. */ { int len; char buf[240], *s; if (fptr == NULL) return (-1); /*** FIRE SDF VTOC records are in ASCII format. */ if (fgets (buf, rec_size+1, fptr) != NULL) { len = str_trim (buf, 0); /*** The following if statement is needed because the VTOC of some *** data sets come with two "Carriage Return" characters at the end *** of the record. The extra CR character will cause the next read *** to be a blank line. ***/ if (strlen (buf) == 0) return (0); sscanf (buf, "%d %d %s", &(toc->fnum), &(toc->rnum), toc->fname); sscanf (&(buf[BEG_GMT-1]), "%14s", toc->i_date_gmt); sscanf (&(buf[END_GMT-1]), "%14s", toc->o_date_gmt); sscanf (&(buf[BEG_LATLON-1]), "%f %f %f %f", &(toc->nlat_max), &(toc->slat_max), &(toc->wlon_max), &(toc->elon_max)); if (strlen(buf) > (AUX_FLDS - 1)) sscanf (&(buf[AUX_FLDS - 1]), "%s", toc->aux_file); /**************************************************************************** * The "aux_file" field is specific for different data. For example, SRB * data use this field to define the map grids (ancillary files). Other * specific definition should be define as a conditional compilation and * codes are added from here. ****************************************************************************/ /***** SRB data specific, tape no. p0101 through p0115 *****/ #ifdef SRB if (strstr (toc->aux_file, KEYWORD_AUX) != (char *)NULL) { s = &toc->aux_file[0]+sizeof(KEYWORD_AUX)-1; strcpy (toc->aux_file, s); } else { fprintf (stderr, "ERROR: ' AUXFIL=' keyword not found. "); fprintf (stderr, "The file may be bad.\n"); strcpy (toc->aux_file, "\0"); } #endif /* SRB */ return (strlen (buf)); } else return (-1); }