OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_prepare_l1a_data.c
Go to the documentation of this file.
1 #include "smfio.h"
2 #include "GEO_global_arrays.h"
3 #include "GEO_input.h"
4 #include "PGS_MODIS_35251.h"
5 
7 
8 PGSt_SMF_status GEO_prepare_l1a_data(
9  MODFILE * const l1a_file,
10  GEO_param_struct const * const geo_params,
12 )
13 /*
14 !C*****************************************************************************
15 !Description:
16  subroutine in input group of the Level-1A geolocation
17  software to read and process geolocation input data from
18  the Level 1A file. First it reads relevant Level 1A
19  metadata which are required for geolocation. It then reads
20  scan start times, mirror sides and number of frames for the
21  scans, followed by the the mirror encoder times, sector
22  start times and spacecraft ancillary data as packed arrays.
23  The packed data are unpacked, converted and validated for
24  use in the geolocation processing.
25 
26 !Input Parameters:
27  l1a_file - the MAPI structure for the Level 1A file
28  geo_params - structure containing geolocation process
29  parameters from the parameter file.
30 
31 !Output Parameters:
32  l1a_data - structure for data read from L1A file
33 
34 Return parameter:
35  MODIS_E_BAD_INPUT_ARG If any pointer argument is null
36  MODIS_E_GEO If any subroutine fails.
37  MODIS_E_GEO_SCANNO_INPUT Invalid number of scans in file
38  MODIS_E_GEO_WRONG_PLATFORM L1A file is for wrong platform
39  PGS_S_SUCCESS Otherwise
40 
41 Externally Defined:
42  CHAN_A "GEO_parameters.h"
43  CHAN_B "GEO_parameters.h"
44  ELEC_SIDES "GEO_parameters.h"
45  ENCODER_LENGTH "GEO_geo.h"
46  MAX_SCAN_NUMBER "GEO_geo.h"
47  MODIS_E_BAD_INPUT_ARG "PGS_MODIS_325251.h"
48  MODIS_E_GEO "PGS_MODIS_325251.h"
49  MODIS_E_GEO_FORMATTER "PGS_MODIS_325251.h"
50  MODIS_E_GEO_SCANNO_INPUT "PGS_MODIS_325251.h"
51  MODIS_E_GEO_WRONG_PLATFORM "PGS_MODIS_325251.h"
52  PGS_S_SUCCESS "PGS_SMF.h"
53  SECTOR_LENGTH "GEO_geo.h"
54  SUCCESS "GEO_basic.h"
55 
56 Called By:
57  GEO_locate_one_granule
58 
59 
60 Routines called:
61  GEO_prepare_mirr_data "GEO_input.h"
62  GEO_prepare_ancil_data "GEO_input.h"
63  GEO_read_L1AECS_metadata "GEO_input.h"
64  GEO_read_L1Apacket_data "GEO_input.h"
65  GEO_read_L1Ascan_metadata "GEO_input.h"
66  GEO_read_L1Aspecific_metadata "GEO_input.h"
67  GEO_read_L1Atemp_data "GEO_input.h"
68  modsmf "smfio.h"
69 
70 !Revision History:
71 $Log: GEO_prepare_l1a_data.c,v $
72 Revision 6.2 2010/06/29 20:18:56 kuyper
73 Corrected test for error return from GEO_prepare_ancil_data().
74 
75 Revision 6.1 2010/06/01 23:03:49 kuyper
76 Helped resolve Bug 2472 by defining ss_cp_mode, passing it to
77  GEO_read_L1Apacket_data() to be filled in, and to GEO_prepare_ancil_data() to
78  be used.
79 Corrected to test for != PGS_SUCCESS, rather than == FAIL.
80 Changed to return status codes.
81 Changed to expect status codes to be returned by GEO_read_L1Apacket_data(),
82  GEO_prepare_ancil_data(), and GEO_prepare_mirr_data().
83 Made error messages more informative.
84 
85 James Kuyper Jr. James.R.Kuyper@NASA.gov
86 
87 Revision 4.3 2003/08/12 14:16:38 kuyper
88 Corrected to move mirr_side from globals to locals before calling
89  GEO_prepare_mirr_data().
90 
91 Revision 4.2 2003/06/03 13:57:56 vlin
92 Moved GEO_prepare_ancil_data() ahead of GEO_prepare_mirr_data()
93 call GEO_read_L1Atemp_data() to fill in l1a_data.temperatures array.
94 vlin@saicmodis.com
95 
96 Revision 4.1 2003/03/12 17:42:05 kuyper
97 Corrected pointer types passed to %p.
98 
99 Revision 3.4 2001/06/05 23:54:48 kuyper
100 Changed GEO_prepare_ancil_data failures back to being non-fatal, per PDL.
101 
102 10/10/95
103 Tracey W. Holmes
104 Added debug option.
105 
106 Requirements:
107  PR03-F-2.1-1
108  PR03-F-2.1-2
109  PR03-F-2.1-3
110  PR03-F-2.2-1
111  PR03-F-2.3-1
112  PR03-F-2.4-1
113  PR03-F-2.4-2
114  PR03-F-2.5-1
115  PR03-F-2.5-2
116  PR03-F-2.5-3
117  PR03-F-2.5-5
118  PR03-I-1
119 
120 !Team-unique Header:
121  This software is developed by the MODIS Science Data Support
122  Team for the National Aeronautics and Space Administration,
123  Goddard Space Flight Center, under contract NAS5-32373.
124 
125 !END
126 *****************************************************************************/
127 
128 {
129  int scan;
130 
131  /* array of View Sector Start encoder count and Vernier Count words */
132  int16 view_sector_start[MAX_SCAN_NUMBER][SECTOR_LENGTH] = {0};
133 
134  /* array of Earth Encoder Time Data (the time between every 100th mirror
135  *encoder pulse over the Earth View)
136  */
137  uint16 earth_encoder_times[MAX_SCAN_NUMBER][ENCODER_LENGTH] = {0};
138 
139  /* data identifying the selected mirror assembly channel */
140  int16 mirr_side[MAX_SCAN_NUMBER];
141  uint16 FRside[MAX_SCAN_NUMBER][ELEC_SIDES];
142  uint16 SAside[MAX_SCAN_NUMBER][ELEC_SIDES];
143  uint16 ss_cp_mode[MAX_SCAN_NUMBER];
144  sc_ancil_struct sc_ancillary_data[2];
145  char msgbuf[512];
146  char filefunc[] = __FILE__ ", GEO_prepare_l1a_data";
147 
148  /* Begin program logic */
149 
150  if ((l1a_file == NULL) || (geo_params == NULL) || (l1a_data == NULL)) {
151  sprintf(msgbuf, " l1a_file = %p, geo_params = %p, l1a_data = %p",
152  (void*)l1a_file, (void*)geo_params, (void*)l1a_data);
153  modsmf(MODIS_E_BAD_INPUT_ARG, msgbuf, filefunc);
154 
155  return MODIS_E_BAD_INPUT_ARG;
156  }
157 
158  if (GEO_read_L1Aspecific_metadata(l1a_file, &l1a_data->granule_metadata,
159  &l1a_data->num_scans)!= SUCCESS)
160  {
161  sprintf(msgbuf, "GEO_read_L1Aspecific_metadata(\"%s\")",
162  l1a_file->filename);
163  modsmf(MODIS_E_GEO, msgbuf, filefunc);
164 
165  return MODIS_E_GEO;
166  }
167 
168  if (GEO_read_L1AECS_metadata(l1a_file, &l1a_data->ECS_metadata) != SUCCESS)
169  {
170  sprintf(msgbuf, "GEO_read_L1AECS_metadata(\"%s\")",
171  l1a_file->filename);
172  modsmf(MODIS_E_GEO, msgbuf, filefunc);
173 
174  return MODIS_E_GEO;
175  }
176 
177  if (strncmp((l1a_data->ECS_metadata).platformshortname,
178  geo_params->spacecraft_ID,sizeof(geo_params->spacecraft_ID))!=0)
179  {
180  sprintf(msgbuf, "platformshortname:%s\tdoesn't match spacecraft_ID: %s",
181  (l1a_data->ECS_metadata).platformshortname,
182  geo_params->spacecraft_ID);
183  modsmf(MODIS_E_GEO_WRONG_PLATFORM, msgbuf, filefunc);
184 
186  }
187 
188  if ((l1a_data->num_scans < 0) || (l1a_data->num_scans > MAX_SCAN_NUMBER))
189  {
190  sprintf(msgbuf, "%d",l1a_data->num_scans);
191  modsmf(MODIS_E_GEO_SCANNO_INPUT, msgbuf, filefunc);
192 
194  }
195  else if (l1a_data->num_scans == 0)
196  return SUCCESS;
197 
198  if (GEO_read_L1Ascan_metadata(l1a_file, l1a_data->num_scans,
199  &l1a_data->granule_metadata, l1a_data->frame_data, mirr_side)
200  != SUCCESS)
201  {
202  sprintf(msgbuf, "GEO_read_L1Ascan_metadata(\"%s\", %ld)",
203  l1a_file->filename, (long)l1a_data->num_scans);
204  modsmf(MODIS_E_GEO, msgbuf, filefunc);
205 
206  return MODIS_E_GEO;
207  }
208 
209  if (GEO_read_L1Apacket_data(l1a_file, l1a_data->num_scans,
210  earth_encoder_times, sc_ancillary_data, view_sector_start, FRside,
211  SAside, ss_cp_mode) != PGS_S_SUCCESS)
212  {
213  sprintf(msgbuf, "GEO_read_L1Apacket_data(\"%s\", %ld)",
214  l1a_file->filename, (long)l1a_data->num_scans);
215  modsmf(MODIS_E_GEO, msgbuf, filefunc);
216 
217  return MODIS_E_GEO;
218  }
219 
220  if (GEO_read_L1Atemp_data(geo_params, l1a_file, l1a_data->num_scans,
221  l1a_data->temperatures) != PGS_S_SUCCESS)
222  {
223  sprintf(msgbuf, "GEO_read_L1Atemp_data(\"%s\", %ld)",
224  l1a_file->filename, (long)l1a_data->num_scans);
225  modsmf(MODIS_E_GEO, msgbuf, filefunc);
226 
227  return MODIS_E_GEO;
228  }
229 
230  for (scan = 0; scan < l1a_data->num_scans; scan++) {
231  if (SAside[scan][CHAN_A]) {
232  if (SAside[scan][CHAN_B]) {
233  if (FRside[scan][CHAN_A]) {
234  l1a_data->mirr_data[scan].mirr_chan = CHAN_A;
235  if (FRside[scan][CHAN_B]) {
236  sprintf(msgbuf, "%d", scan);
237  modsmf(MODIS_E_GEO_FORMATTER, msgbuf, filefunc);
238  }
239  } else l1a_data->mirr_data[scan].mirr_chan = CHAN_B;
240  } else l1a_data->mirr_data[scan].mirr_chan = CHAN_A;
241  } else l1a_data->mirr_data[scan].mirr_chan = CHAN_B;
242  }
243 
244  /* Note: the ancillary data must be initialized before the mirror data can
245  * be prepared, because part of the preparation depends upon correcting
246  * encoder times that happen at a fixed time after the reciept of ancillary
247  * data packets.
248  */
249 
250  if(GEO_prepare_ancil_data(l1a_data->num_scans, geo_params,
251  sc_ancillary_data, ss_cp_mode) != PGS_S_SUCCESS)
252  {
253  sprintf(msgbuf, "GEO_prepare_ancil_data(%ld)",
254  (long)l1a_data->num_scans);
255  modsmf(MODIS_E_GEO, msgbuf, filefunc);
256  }
257 
258  /* Needed by GEO_prepare_mirr_data. */
259  for (scan = 0; scan < l1a_data->num_scans; scan++)
260  l1a_data->mirr_data[scan].mirr_side = (uint16)mirr_side[scan];
261 
262  if (GEO_prepare_mirr_data(earth_encoder_times, view_sector_start,
263  &geo_params->mirror_prep_params, geo_params->geometry_params.t_frame,
264  l1a_data) != SUCCESS)
265  {
266  sprintf(msgbuf, "GEO_prepare_mirr_data(%g)",
267  geo_params->geometry_params.t_frame);
268  modsmf(MODIS_E_GEO, msgbuf, filefunc);
269 
270  return MODIS_E_GEO;
271  }
272 
273  /* Set by GEO_prepare_mirr_data. */
274  for (scan = 0; scan < l1a_data->num_scans; scan++)
275  num_impulse[scan] = (int)l1a_data->mirr_data[scan].num_impulse;
276 
277  return PGS_S_SUCCESS;
278 }
279 
PGSt_SMF_status GEO_read_L1Atemp_data(const GEO_param_struct *const, MODFILE *const, int const, float32[])
integer, parameter int16
Definition: cubeio.f90:3
#define SUCCESS
Definition: ObpgReadGrid.h:15
PGSt_SMF_status GEO_prepare_ancil_data(int const number_of_scans, const GEO_param_struct *params, const sc_ancil_struct sc_ancillary_data[2], const uint16 ss_cp_mode[])
PGSt_SMF_status GEO_read_L1Apacket_data(MODFILE *l1a_file, int const number_of_scans, uint16 earth_encoder_times[MAX_SCAN_NUMBER][ENCODER_LENGTH], sc_ancil_struct sc_ancillary_data[2], int16 view_sector_start[MAX_SCAN_NUMBER][SECTOR_LENGTH], uint16 FRside[MAX_SCAN_NUMBER][ELEC_SIDES], uint16 SAside[MAX_SCAN_NUMBER][ELEC_SIDES], uint16 ss_cp_mode[])
#define MODIS_E_GEO_FORMATTER
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_BAD_INPUT_ARG
MOD_PR01 Production producing one five minute granule of output data in each run It can be configured to produce as many as three five minute granules per run Each execution with one construction record and one date file for each dataset In normal these are created by which splits them out of the hour datasets For LANCE they are created by which merges all session MODIS L0 datasets overlapping the requested time and extracts from the merged data those packets which fall within that time period Each scan of data is stored in the L1A granule that covers the start time of that scan
Definition: MOD_PR01_pr.txt:19
int16_t * l1a_data
Definition: l1a_seawifs.c:84
#define MODIS_E_GEO
#define MODIS_E_GEO_SCANNO_INPUT
const int SECTOR_LENGTH
#define CHAN_A
focal_plane_geometry_struct geometry_params
int num_impulse[MAX_SCAN_NUMBER]
#define ELEC_SIDES
Definition: GEO_geo.h:108
#define MODIS_E_GEO_WRONG_PLATFORM
int GEO_read_L1Aspecific_metadata(MODFILE *const l1a_file, l1a_metadata_struct *const granule_metadata, int *const number_of_scans)
#define CHAN_B
int GEO_read_L1Ascan_metadata(MODFILE *const l1a_file, int const number_of_scans, l1a_metadata_struct const *const granule_metadata, frame_data_struct frame_data[MAX_SCAN_NUMBER], int16 mirr_side[MAX_SCAN_NUMBER])
PGSt_SMF_status GEO_prepare_mirr_data(uint16[MAX_SCAN_NUMBER][ENCODER_LENGTH], int16[MAX_SCAN_NUMBER][SECTOR_LENGTH], const mirror_preparation_struct *const, double const, l1a_data_struct *)
const int MAX_SCAN_NUMBER
PGSt_SMF_status GEO_prepare_l1a_data(MODFILE *const l1a_file, GEO_param_struct const *const geo_params, l1a_data_struct *const l1a_data)
mirror_preparation_struct mirror_prep_params
#define ENCODER_LENGTH
Definition: GEO_geo.h:111
int GEO_read_L1AECS_metadata(MODFILE *const l1a_file, ECS_metadata_struct *const ECS_metadata)