OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
spload.c
Go to the documentation of this file.
1 /***************************************************************************
2 NAME: spload
3 
4 PURPOSE:
5 This program creates the binary lookup tables for the state plane
6 projection by reading the ascii nad1927.dat and nad1983.dat files
7 and writing the binary nad27sp and nad83sp files.
8 
9 DEVELOPMENT HISTORY:
10  Adapted from the spload.f file for platforms that do not have a
11  FORTRAN compiler.
12 
13 
14 ***************************************************************************/
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 
20 
21 #define BUFSIZE 80
22 /* size of buffer for doing I/O */
23 
24 int process_file
25 (
26  const char *input_filename,
27  const char *output_filename
28 )
29 {
30  FILE *infile; /* file pointer for the input file */
31  FILE *outfile; /* file pointer for the output file */
32  char buf[BUFSIZE];
33  char zone_name[33];
34  int zone_id;
35  int zone_number;
36  int record_length = 108;
37  int record_num;
38  int line;
39  int i;
40  double parms[9];
41 
42  /* open the input file for reading */
43  infile = fopen(input_filename,"rt");
44  if (!infile)
45  {
46  printf("Error opening %s\n",input_filename);
47  return 1;
48  }
49 
50  /* open the output file for writing */
51  outfile = fopen(output_filename,"wt");
52  if (!outfile)
53  {
54  printf("Error opening %s\n",output_filename);
55  fclose(infile);
56  return 1;
57  }
58 
59  /* process the lines from the input file */
60  record_num = 0;
61  line = 0;
62  while (fgets(buf, BUFSIZE, infile))
63  {
64  char *ptr = buf;
65  int index = (line - 1) * 3;
66  switch (line)
67  {
68  case 0:
69  /* first line of record, so get the zone name, id, and number */
70  strncpy(zone_name,buf,32);
71  zone_name[32] = '\0';
72  if ((sscanf(&buf[39],"%1d",&zone_id) != 1) ||
73  (sscanf(&buf[71],"%4d",&zone_number) != 1))
74  {
75  printf("Error reading record %d from %s\n",record_num,
76  input_filename);
77  fclose(infile);
78  fclose(outfile);
79  return 1;
80  }
81  break;
82  case 1: case 2: case 3:
83  /* process the parameter lines of the record */
84 
85  /* convert 'D' characters to 'E' characters since the
86  ascii file was created in FORTRAN floating point format */
87  while (*ptr)
88  {
89  if (*ptr=='D')
90  *ptr = 'E';
91  ptr++;
92  }
93 
94  /* read the three parameters from this line */
95  if (sscanf(buf,"%lf%lf%lf",&parms[index],
96  &parms[index+1], &parms[index+2])!= 3)
97  {
98  printf("Error reading record %d from %s\n",record_num,
99  input_filename);
100  fclose(infile);
101  fclose(outfile);
102  return 1;
103  }
104  break;
105 
106  }
107 
108  /* advance to the next line */
109  line++;
110  if (line == 4)
111  {
112  /* fourth line of record so write the completed record to the
113  output file */
114  line = 0;
115 
116  /* seek the current record */
117  if (fseek(outfile, record_length * record_num, SEEK_SET) != 0)
118  {
119  printf("Error seeking record %d to %s\n",record_num,
120  output_filename);
121  fclose(infile);
122  fclose(outfile);
123  return 1;
124  }
125 
126  /* write the record */
127  if ((fwrite(zone_name,sizeof(char),32,outfile) != 32) ||
128  (fwrite(&zone_id,sizeof(int),1,outfile) != 1) ||
129  (fwrite(parms,sizeof(double),9,outfile) != 9))
130  {
131  printf("Error writing record %d to %s\n",record_num,
132  output_filename);
133  fclose(infile);
134  fclose(outfile);
135  return 1;
136  }
137 
138  /* advance to the next record */
139  record_num++;
140 
141  /* output record information */
142  printf (" {%d, %d, \n {", zone_number, zone_id);
143  for (i = 0; i < 9; i++)
144  {
145  if ((i != 0) && (i != 3) && (i != 6))
146  printf(", ");
147  printf("%.15e", parms[i]);
148  if ((i == 2) || (i == 5))
149  printf(",\n ");
150  }
151  printf("},\n \"%s\"},\n", zone_name);
152  }
153  }
154 
155  fclose(infile);
156  if (fclose(outfile) != 0)
157  {
158  printf("Error closing output file %s\n",output_filename);
159  return 1;
160  }
161  return 0;
162 }
163 
164 
165 int main(void)
166 {
167  char nad27_source_file[] = "nad1927.dat";
168  char nad27_dest_file[] = "nad27sp.lut";
169  char nad83_source_file[] = "nad1983.dat";
170  char nad83_dest_file[] = "nad83sp.lut";
171 
172  /* process the nad 27 state plane file */
173  printf("static STATE_PLANE_ZONE_DATA nad27_data = {\n");
174  if (process_file(nad27_source_file, nad27_dest_file))
175  {
176  printf("Error creating %s\n",nad27_dest_file);
177  exit (1);
178  }
179  printf("};\n");
180 
181  /* process the nad 27 state plane file */
182  printf("static STATE_PLANE_ZONE_DATA nad83_data = {\n");
183  if (process_file(nad83_source_file, nad83_dest_file))
184  {
185  printf("Error creating %s\n",nad83_dest_file);
186  exit (1);
187  }
188  printf("};\n");
189 
190  return 0;
191 }
#define BUFSIZE
Definition: spload.c:21
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of it will be treated as a constant LUT The manner in which Earth View data is checked for saturation was changed Previously the raw Earth View DNs and Space View DNs were checked against the lookup table values contained in the table dn_sat The change made is to check the raw Earth and Space View DNs to be sure they are less than the maximum saturation value and to check the Space View subtracted Earth View dns against a set of values contained in the new lookup table dn_sat_ev The metadata configuration and ASSOCIATEDINSTRUMENTSHORTNAME from the MOD02HKM product The same metatdata with extensions and were removed from the MOD021KM and MOD02OBC products ASSOCIATEDSENSORSHORTNAME was set to MODIS in all products These changes are reflected in new File Specification which users may consult for exact the pow functions were eliminated in Emissive_Cal and Emissive bands replaced by more efficient code Other calculations throughout the code were also made more efficient Aside from a few round off there was no difference to the product The CPU time decreased by about for a day case and for a night case A minor bug in calculating the uncertainty index for emissive bands was corrected The frame index(0-based) was previously being used the frame number(1-based) should have been used. There were only a few minor changes to the uncertainty index(maximum of 1 digit). 3. Some inefficient arrays(Sigma_RVS_norm_sq) were eliminated and some code lines in Preprocess_L1A_Data were moved into Process_OBCEng_Emiss. There were no changes to the product. Required RAM was reduced by 20 MB. Now
int main(void)
Definition: spload.c:165
PARAM_TYPE_NONE Default value No parameter is buried in the product name name_prefix is case insensitive string compared to the product name PARAM_TYPE_VIS_WAVE The visible wavelength bands from the sensor are buried in the product name The product name is compared by appending and name_suffix ie aph_412_giop where prod_ix will be set to PARAM_TYPE_IR_WAVE same search method as PARAM_TYPE_VIS_WAVE except only wavelength above are looped through but prod_ix is still based ie aph_2_giop for the second and prod_ix set to PARAM_TYPE_INT name_prefix is compared with the beginning of the product name If name_suffix is not empty the it must match the end of the product name The characters right after the prefix are read as an integer and prod_ix is set to that number strncpy(l2prod->name_prefix, "myprod", UNITLEN)
int process_file(const char *input_filename, const char *output_filename)
Definition: spload.c:25
int i
Definition: decode_rs.h:71