OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_read_L1Aspecific_metadata.c
Go to the documentation of this file.
1 /* File: GEO_read_L1Aspecific_metadata.c */
2 
3 #include "PGS_MODIS_35251.h"
4 #include "GEO_input.h"
5 #include "L1a_data.h"
6 #include "smfio.h"
8 
10  MODFILE * const l1a_file,
11  l1a_metadata_struct * const granule_metadata,
12  int * const number_of_scans
13  )
14 
15 /*
16 !C**************************************************************************
17 
18 !Description:
19  Routine in Input group of the Level-1A geolocation
20  software to read L1A specific granule metadata from
21  the input product. These metadata are retrieved from
22  individual global HDF attributes using MAPI calls.
23 
24 !Input Parameters:
25  MODFILE *l1a_file - the MAPI structure for the L1A product
26 
27 !Output Parameters:
28  granule_metadata - l1a specific granule metadata
29  number_of_scans - the number of scans in the granule
30 
31 Return parameter:
32  SUCCESS if all the specified specific granule metadata are
33  read from the l1a_file,
34  FAIL otherwise.
35 
36 Global variables: None
37 
38 Call functions:
39  int getMODISfileinfo - MAPI routine to read a global
40  metadata attribute from an HDF file.
41  modsmf(MODIS_X_MNEMONIC_STRING, "user message string",
42  "function, GEO_write_parameters.c");
43 
44 
45 !Revision History:
46  $Log: GEO_read_L1Aspecific_metadata.c,v $
47  Revision 4.1 2003/02/21 22:44:48 kuyper
48  Corrected to use void* pointers with %p format code.
49 
50  Revision 3.1 2002/06/13 22:54:16 kuyper
51  Removed unnecessary NCSA acknowledgement.
52 
53  Revision 2.1 1997/10/21 18:16:22 kuyper
54  Returned from ClearCase
55 
56  * Revision /main/GEO_V2_DEV/1 1997/09/4 Ding
57  * Revised to read Version 2 data.
58  * ding@ltpmail.gsfc.nasa.gov
59  *
60  * Revision 1.7 1997/07/21 16:24:34 kuyper
61  * Baselined Version 1
62  *
63  * Revision 1.7 1997/03/26 18:13:50 fhliang
64  * Initial revision of SDST delivery of GEO_read_L1Aspecific_metadata.c.
65  *
66  Revision 1.6 1997/02/13 19:53:38 kuyper
67  Merged seed files.
68 
69  Revision 1.5 1997/01/30 20:20:50 kuyper
70  Backed out temporary changes made to match
71  the errors in the simulated data.
72 
73  Revision 1.4 1997/01/14 22:38:28 kuyper
74  Changed to use M01 M-API macros indirectly.
75  Temporary change to acommodate incorrectly simulated L1A files.
76 
77  Revision 1.3 1997/01/14 19:30:25 kuyper
78  Adjusted header files.
79  James Kuyper - kuyper@ltpmail.gsfc.nasa.gov
80 
81  Revision 1.2 1997/01/14 18:44:30 mikej
82  Cosmetic typo fixed in comment.
83 
84  Revision 1.1 1997/01/14 18:20:58 mikej
85  Initial revision
86 
87 
88 Requirements:
89  PR03-F-2.1-1
90  PR03-F-2.1-2
91 
92 !Team-unique Header:
93  This software is developed by the MODIS Science Data Support
94  Team for the National Aeronautics and Space Administration,
95  Goddard Space Flight Center, under contract NAS5-32373.
96 
97 
98 !END***************************************************************************
99 */
100 
101 {
102 /* Initialize an array of structures, attribute_object's:
103  attribute_object.name text string of the attribute's name.
104  attribute_object.data_type DATATYPELENMAX long string of the
105  attribute's M-API data type.
106  attribute_object.n_elements number of elements in the metadata
107  attribute_object.data pointer to where to (eventually) store
108  the data from the attribute.
109 
110  Initialize int32 data type num_scans_in
111  to retrieve the number of
112  scans into the correct
113  data type
114 
115  attribute_object initialization:
116 
117  .name .data_type .n_elements .data
118 
119 ================================================================================
120  | | |
121 "Number of scans" I32 1 number_of_scans
122 "Max Earth Frames" I32 1 granule_metadata.
123  max_earth_frames
124 "Max SD Frames" I32 1 granule_metadata.
125  max_sd_frames_in
126 "Max SV Frames" I32 1 granule_metadata.max_sv_frames
127 "Incomplete Scans" I32 1 granule_metadata.
128  incomplete_scans
129 "Missing_packets" I32 1 granule_metadata.
130  missing_packets
131 "Packets with bad CRC" I32 1 granule_metadata.
132  bad_CRC_packets
133 "Discarded Packets" I32 1 granule_metadata.
134  discarded_packets
135  Note: data types of elements in the granule_metadata structure
136  match the data types of the attributes in the L1A file.
137 */
138 
139 #define N_ELEMENTS(foo) ((int) (sizeof(foo) / sizeof(foo[0])))
140 #define STRMAX 120
141 #define NAMEMAX (STRMAX - 40)
142 
143  /*
144  Warning: The order and sequence of the initilizations can not
145  be changed. We finish the initilization later and count on this order
146  */
147  struct L1Ameta{
148  char *name; /* name of attribute */
149  char data_type[DATATYPELENMAX]; /* M-API data type */
150  long int n_elements; /* Number of metadata elements to retrieve */
151  void * data; /* pointer to the data */
152  } attribute_object[] = {
153  {NUMBER_OF_SCANS, I32, 1L, NULL},
154  {MAX_EARTH_FRAMES, I32, 1L, NULL},
155  {MAX_SD_FRAMES, I32, 1L, NULL},
156  {MAX_SV_FRAMES, I32, 1L, NULL},
157  {INCOMPL_SCANS, I32, 1L, NULL},
158  {MISSING_PACKETS, I32, 1L, NULL},
159  {PACKTS_BAD_CRC, I32, 1L, NULL},
160  {DISCARD_PACKETS, I32, 1L, NULL}
161  };
162  int32 number_of_scans_in;
163  int i, rtval=SUCCESS; /* loop index */
164  char msgbuf[STRMAX]; /* scratch string buffer */
165 
166 /* IF (l1a_file = NULL)
167  OR (granule_metadata = NULL)
168  OR (number_of_scans = NULL)
169  BEGIN
170  CALL modsmf function to report error in LogStatus:
171  "GEO_read_L1Aspecific_metadata, GEO_read_L1Aspecific_metadata.c():
172  MODIS_E_BAD_INPUT_ARG:XXXXXXXXX"
173  timestamp "Invalid input argument l1a_file = " l1a_file
174  ", granule_metadata = " granule_metadata
175  ", number_of_scans = " number_of_scans
176 
177  RETURN FAIL
178  END
179 */
180  if((l1a_file == NULL) || (granule_metadata == NULL) ||
181  (number_of_scans == NULL )){
182  sprintf(msgbuf, " l1a_file = %p, granule_metadata = %p, "
183  "number_of_scans = %p",
184  (void*)l1a_file, (void*)granule_metadata, (void*)number_of_scans);
185  modsmf(MODIS_E_BAD_INPUT_ARG, msgbuf,
186  "GEO_read_L1Aspecific_metadata, GEO_read_L1Aspecific_metadata.c");
187  return FAIL;
188  }
189 
190 /* Finish initializing the attribute_object array with the contents
191  defined above.
192 
193  See warning about sequence in declaration section
194 */
195  attribute_object[0].data = &number_of_scans_in;
196  attribute_object[1].data = &granule_metadata->max_earth_frames;
197  attribute_object[2].data = &granule_metadata->max_sd_frames;
198  attribute_object[3].data = &granule_metadata->max_sv_frames;
199  attribute_object[4].data = &granule_metadata->incomplete_scans;
200  attribute_object[5].data = &granule_metadata->missing_packets;
201  attribute_object[6].data = &granule_metadata->bad_CRC_packets;
202  attribute_object[7].data = &granule_metadata->discarded_packets;
203 
204 /* FOR each metadata object, i, in the attribute_object array
205  BEGIN
206  IF call to getMODISfileinfo(l1a_file,
207  attribute_object[i].name,
208  attribute_object[i].data_type,
209  attribute_object[i].n_elements,
210  attribute_object[i].data)
211  to read the geolocation specific granule metadata
212  from an HDF global attribute
213  does NOT return MAPIOK
214  BEGIN
215  CALL modsmf function to report error in LogStatus:
216  "putMODISfileinfo, GEO_read_L1Aspecific_metadata.c():
217  MODIS_E_GEO:XXXXXXXXX"
218  timestamp "Error returned by function reading"
219  attribute_object[i].name
220  RETURN FAIL
221  END
222  END FOR each attribute_object
223 */
224  for (i = 0; i < N_ELEMENTS(attribute_object); i++) {
225  if (getMODISfileinfo(l1a_file, attribute_object[i].name,
226  attribute_object[i].data_type, &attribute_object[i].n_elements,
227  attribute_object[i].data) != MAPIOK) {
228  sprintf(msgbuf, " reading %.*s", NAMEMAX,
229  attribute_object[i].name);
230  modsmf(MODIS_E_GEO, msgbuf,
231  "getMODISfileinfo, GEO_read_L1Aspecific_metadata.c");
232  rtval = FAIL;
233  }
234  }
235 
236  /* Read Extract Metadata */
237  read_extract_metadata(l1a_file->sd_id,
238  &granule_metadata->Extract_Pixel_Offset,
239  &granule_metadata->Extract_Pixel_Count,
240  &granule_metadata->Extract_Line_Offset,
241  &granule_metadata->Extract_Line_Count);
242 
243 /* Perform explicit type conversion of number_of_scans_in
244  into number_of_scans.
245 */
246  *number_of_scans = (int) number_of_scans_in;
247 
248  return rtval;
249 
250 /* END GEO_read_L1Aspecific_metadata
251 */
252 }
#define MISSING_PACKETS
Definition: L1a_data.h:118
#define SUCCESS
Definition: ObpgReadGrid.h:15
#define L(lambda, T)
Definition: PreprocessP.h:185
#define MAX_SD_FRAMES
Definition: L1a_data.h:115
#define FAIL
Definition: ObpgReadGrid.h:18
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_BAD_INPUT_ARG
#define MAX_EARTH_FRAMES
Definition: L1a_data.h:114
#define MODIS_E_GEO
#define NAMEMAX
#define MAX_SV_FRAMES
Definition: L1a_data.h:116
int GEO_read_L1Aspecific_metadata(MODFILE *const l1a_file, l1a_metadata_struct *const granule_metadata, int *const number_of_scans)
#define N_ELEMENTS(foo)
#define INCOMPL_SCANS
Definition: L1a_data.h:113
#define PACKTS_BAD_CRC
Definition: L1a_data.h:120
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
#define DISCARD_PACKETS
Definition: L1a_data.h:109
#define NUMBER_OF_SCANS
Definition: L1a_data.h:119
#define STRMAX
int i
Definition: decode_rs.h:71
int read_extract_metadata(int32 sd_id, int32 *extract_pixel_offset, int32 *extract_pixel_count, int32 *extract_line_offset, int32 *extract_line_count)