OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_write_geospecific_metadata.c
Go to the documentation of this file.
1 #include "GEO_output.h"
2 #include "GEO_product.h"
3 #include "PGS_MODIS_35251.h"
5 
7  MODFILE * const geo_file,
8  l1a_metadata_struct const * const granule_metadata,
9  int const number_of_scans,
10  GEO_param_struct const * const geo_parameter,
11  qa_metadata_struct const * const qa_metadata,
12  utcpole_metadata_struct const * const utcpole_metadata
13 )
145 {
146  static float32 zero = 0.0, half = 0.5;
147  struct {
148  char *name; /* the attribute's name. */
149  char data_type[DATATYPELENMAX]; /* M-API data type. */
150  long n_elements; /* number of elements */
151  void const *data; /* pointer to data */
152  }attribute_object[] = {
153  { NUMSCN, I32, 1, NULL},
154  { MAX_EFRM, I32, 1, NULL},
155  { MAX_SFRM, I32, 1, NULL},
156  { MAX_SV_FRM, I32, 1, NULL},
157  { INCOMP_SCANS, I32, 1, NULL},
158  { MISS_PCKTS, I32, 1, NULL},
159  { BAD_PCKTS, I32, 1, NULL},
160  { DISCRD_PCKTS, I32, 1, NULL},
161  { EA_SOURCE, TXT, 0, NULL},
162  { TERRAIN_CORRECTION, TXT, 0, NULL},
163  { PARVERS, TXT, 0, NULL},
164  { GEO_EST_RMS_ERROR, R32, 1, NULL},
165  { CUM_GFLAGS, UI32, 8, NULL},
166  { UTCPOLE_FH, TXT, 0, NULL},
167  { POLAR_MOTION, R64, 3, NULL},
168  { NULL, R32, 1, &half},
169  { NULL, R32, 1, &zero}
170  };
171 
172  static char ea_source[PGSd_PC_VALUE_LENGTH_MAX] = "";
173  static char terrain_correction[PGSd_PC_VALUE_LENGTH_MAX] = "";
174  int32 tmp_int32;
175  int num_objects;
176  int obj = 0;
177  char filefunc[] = __FILE__ ", GEO_write_geospecific_metadata";
178  char msgbuf[PGS_SMF_MAX_MSGBUF_SIZE] = "";
179  PGSt_SMF_status ret_val = PGS_S_SUCCESS;
180 
181  if (geo_file == NULL )
182  {
183  sprintf(msgbuf, "geo_file = %p ", (void*)geo_file);
184  modsmf(MODIS_E_BAD_INPUT_ARG, msgbuf, filefunc);
185  return MODIS_E_BAD_INPUT_ARG;
186  }
187 
188  /*Identify the source of spacecraft kinematic data */
189  if( ea_source[0] == '\0' &&
190  (PGS_PC_GetConfigData(EA_SOURCE_SELECT_LUN, ea_source)!= PGS_S_SUCCESS))
191  {
192  sprintf(msgbuf, "PGS_PC_GetConfigData(%d)", EA_SOURCE_SELECT_LUN);
193  modsmf(MODIS_E_GEO, msgbuf, filefunc);
194  ea_source[0] = '\0';
195  }
196 
197  /*Identify the source of spacecraft kinematic data */
198  if( terrain_correction[0] == '\0' &&
199  (PGS_PC_GetConfigData(TERRAIN_CORRECT_LUN, terrain_correction)
200  != PGS_S_SUCCESS))
201  {
202  sprintf(msgbuf, "PGS_PC_GetConfigData(%d)", TERRAIN_CORRECT_LUN);
203  modsmf(MODIS_E_GEO, msgbuf, filefunc);
204  terrain_correction[0] = '\0';
205  }
206 
207  /*
208  Finish initializing the attribute_object array with the contents
209  defined above. IF any of the input arguments are NULL or
210  ea_source was not successfully retrieved, set
211  the dependent .data('s) to NULL.
212  */
213 
214  /* int32 */
215  tmp_int32 = (int32)number_of_scans;
216  attribute_object[obj].data = &tmp_int32;
217  obj++;
218 
219  if (granule_metadata != NULL){
220 
221  /* element 1 int32 */
222  attribute_object[obj].data = &granule_metadata->max_earth_frames;
223  obj++;
224 
225  /* element 2 int32 */
226  attribute_object[obj].data = &granule_metadata->max_sd_frames;
227  obj++;
228 
229  /*element 3 int32 */
230  attribute_object[obj].data = &granule_metadata->max_sv_frames;
231  obj++;
232 
233  /*element 4 int32 */
234  attribute_object[obj].data = &granule_metadata->incomplete_scans;
235  obj++;
236 
237  /*element 5 int32 */
238  attribute_object[obj].data = &granule_metadata->missing_packets;
239  obj++;
240 
241  /*element 6 int32 */
242  attribute_object[obj].data = &granule_metadata->bad_CRC_packets;
243  obj++;
244 
245  /* element 7 int32 */
246  attribute_object[obj].data = &granule_metadata->discarded_packets;
247  obj++;
248  }else
249  obj += 7;
250 
251  /* TXT */
252  attribute_object[obj].n_elements = (long)strlen(ea_source);
253  attribute_object[obj].data =
254  attribute_object[obj].n_elements ? ea_source : NULL;
255  obj++;
256 
257  /* TXT */
258  attribute_object[obj].n_elements = (long)strlen(terrain_correction);
259  attribute_object[obj].data =
260  attribute_object[obj].n_elements ? terrain_correction : NULL;
261  obj++;
262 
263  if ( geo_parameter != NULL){
264  /* TXT */
265  attribute_object[obj].n_elements = (long)strlen(geo_parameter->revision);
266  attribute_object[obj].data = geo_parameter->revision;
267  obj++;
268 
269  /* float32 */
270  attribute_object[obj].data = &geo_parameter->RMS_error;
271  obj++;
272  }else
273  obj +=2;
274 
275  if (qa_metadata != NULL)
276  /* uint32 */
277  attribute_object[obj].data = qa_metadata->cumulated_gflags;
278  obj++;
279 
280  if (utcpole_metadata != NULL)
281  {
282  /* TXT */
283  attribute_object[obj].n_elements =
284  (long)strlen(utcpole_metadata->header);
285  attribute_object[obj++].data = utcpole_metadata->header;
286 
287  /* R32 */
288  attribute_object[obj++].data = utcpole_metadata->polar_motion;
289  } else
290  obj += 2;
291 
292  switch(geo_parameter->geometry_params.N_samp
293  [geo_parameter->geometry_params.band_number])
294  {
295  default:
296  break;
297  case 2:
298  attribute_object[obj++].name = FROFF_SCAN_20;
299  attribute_object[obj++].name = FROFF_FRAME_2;
300  break;
301  case 4:
302  attribute_object[obj++].name = FROFF_SCAN_40;
303  attribute_object[obj++].name = FROFF_FRAME_4;
304  break;
305  }
306  num_objects = obj;
307 
308  for (obj =0; obj < num_objects; obj++)
309  {
310  if (attribute_object[obj].data == NULL)
311  {
312  /* "Output value not available for" */
313  modsmf(MODIS_E_MISSING_OUTPUT, attribute_object[obj].name,
314  filefunc);
315 
316  ret_val = MODIS_E_MISSING_OUTPUT;
317  }else if(putMODISfileinfo(geo_file, attribute_object[obj].name,
318  attribute_object[obj].data_type, attribute_object[obj].n_elements,
319  attribute_object[obj].data) != MAPIOK)
320  {
321  sprintf(msgbuf, "putMODISfileinfo(\"%s\", \"%s\", \"%s\", %ld)",
322  geo_file->filename, attribute_object[obj].name,
323  attribute_object[obj].data_type,
324  attribute_object[obj].n_elements);
325  modsmf(MODIS_E_GEO, msgbuf, filefunc);
326 
327  ret_val = MODIS_E_GEO;
328  }
329  }
330 
331  /* Write Extract Metadata */
332  write_extract_metadata(geo_file->sd_id,
333  granule_metadata->Extract_Pixel_Offset,
334  granule_metadata->Extract_Pixel_Count,
335  granule_metadata->Extract_Line_Offset,
336  granule_metadata->Extract_Line_Count);
337 
338  return ret_val;
339 }
#define POLAR_MOTION
Definition: GEO_product.h:261
PGSt_SMF_status GEO_write_geospecific_metadata(MODFILE *const geo_file, l1a_metadata_struct const *const granule_metadata, int const number_of_scans, GEO_param_struct const *const geo_parameter, qa_metadata_struct const *const qa_metadata, utcpole_metadata_struct const *const utcpole_metadata)
#define MODIS_E_MISSING_OUTPUT
#define NUMSCN
Definition: GEO_product.h:259
#define FROFF_FRAME_4
Definition: GEO_product.h:267
#define MAX_EFRM
Definition: GEO_product.h:255
#define FROFF_SCAN_40
Definition: GEO_product.h:266
int write_extract_metadata(int32 sd_id, int32 extract_pixel_offset, int32 extract_pixel_count, int32 extract_line_offset, int32 extract_line_count)
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_BAD_INPUT_ARG
#define MAX_SFRM
Definition: GEO_product.h:256
#define BAD_PCKTS
Definition: GEO_product.h:248
#define EA_SOURCE
Definition: GEO_product.h:280
#define FROFF_FRAME_2
Definition: GEO_product.h:265
#define MODIS_E_GEO
#define PARVERS
Definition: GEO_product.h:260
#define MISS_PCKTS
Definition: GEO_product.h:258
#define UTCPOLE_FH
Definition: GEO_product.h:262
unsigned short N_samp[MAX_BAND_NUMBER_PLUS_ONE]
unsigned char revision[10]
focal_plane_geometry_struct geometry_params
#define MAX_SV_FRM
Definition: GEO_product.h:257
#define EA_SOURCE_SELECT_LUN
Definition: GEO_geo.h:93
#define INCOMP_SCANS
Definition: GEO_product.h:252
#define TERRAIN_CORRECT_LUN
Definition: GEO_geo.h:95
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
#define DISCRD_PCKTS
Definition: GEO_product.h:250
#define FROFF_SCAN_20
Definition: GEO_product.h:264
#define TERRAIN_CORRECTION
Definition: GEO_product.h:268
uint32 cumulated_gflags[8]
#define GEO_EST_RMS_ERROR
Definition: GEO_product.h:283
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed as required for compatibility with version of the SDP toolkit Corrected test output file names to end in per delivery and then split off a new MYD_PR03 pcf file for Aqua Added AssociatedPlatformInstrumentSensor to the inventory metadata in MOD01 mcf and MOD03 mcf Created new versions named MYD01 mcf and MYD03 where AssociatedPlatformShortName is rather than Terra The program itself has been changed to read the Satellite Instrument validate it against the input L1A and LUT and to use it determine the correct files to retrieve the ephemeris and attitude data from Changed to produce a LocalGranuleID starting with MYD03 if run on Aqua data Added the Scan Type file attribute to the Geolocation copied from the L1A and attitude_angels to radians rather than degrees The accumulation of Cumulated gflags was moved from GEO_validate_earth_location c to GEO_locate_one_scan to ensure that all gflag bits get accumulated Changed GEO_write_ECS_metadata to write PGEVERSION as Changed GEO_locate_one_granule c to make a failure to find an orbit number in the staged ephemeris files be non fatal Updated GEO_parameters dat to reflect latest estimate of and to screen out the jumps in encoder times which occur at the beginning of each S C ancillary data packet Changed GEO_product h to use mapiL1Bgeo h as source for CUM_GFLAGS
Definition: HISTORY.txt:478