OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
set_start_position.c
Go to the documentation of this file.
1 #include "PGS_IO.h"
2 #include "PGS_TD.h"
3 #include "PGS_SMF.h"
4 #include "PGS_TYPES.h"
5 #include "PGS_MODIS_35005.h"
6 #include "PC_pcf_info.h"
7 #include "L1A_prototype.h"
8 
9 
10 PGSt_SMF_status set_start_position (PGSt_IO_L0_VirtualDataSet L0_file,
11  PGSt_double *preload_start_time,
12  PGSt_double start_time,
13  PGSt_double stop_time)
14 
15 /*
16 !C************************************************************************
17 
18 !Description: This function sets a pointer in the L0 file to start reading
19  data at a specific time (preload_start_time).
20 
21 
22 !Input Parameters:
23  PGSt_IO_L0_VirtualDataSet L0_file
24  ** L0 virtual data set **
25 
26  PGSt_double preload_start_time ** Start time for **
27  ** preloading Eng data **
28 
29 !Output Parameters:
30  None
31 
32 Return Values:
33  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
34  MODIS_F_L0_SETSTART_FAILED (PGS_MODIS_35005.h)
35 
36 Externally Defined:
37  PGSt_SMF_status (PGS_SMF.h)
38  PGS_TRUE (PGS_SMF.h)
39  PGS_FALSE (PGS_SMF.h)
40  PGSt_SMF_boolean (PGS_SMF.h)
41  PGSt_IO_L0_VirtualDataSet (PGS_IO.h)
42  PGSd_EOS_AM1 (PGS_TD.h)
43  PGSt_Logical (PGS_TYPES.h)
44 
45 Called By:
46  initialize_level1a
47 
48 Routines Called:
49  PGS_IO_L0_SetStart
50  PGS_IO_L0_Close
51  get_valid_L0_file
52  validate_L0_header
53  log_fmt_msg
54 
55 !Revision History:
56  Revision 2.2 2000/07/14
57  John Seaton/SAIC/GSC (seaton@ltpmail.gsfc.nasa.gov)
58  Added code for Aqua instrument.
59 
60  Revision 2.1 2000/04/06 11:54
61  John Seaton/GSC (seaton@ltpmail.gsfc.nasa.gov)
62  Fix to change start/stop times when trying to process L0 file
63  in LUN 599002. Call to get_valid_L0_file was using local vars
64  to store start/stop times. These variables were never used in
65  the comparison under case PGSIO_W_L0_TIME_NOT_FOUND. Thus the
66  pre-load start time was not getting set and processing fails
67  with return code 1.
68 
69  Revision 2.0 1997/08/28 02:23
70  Timi Adelekan/GSC/SAIC (adelekan@ltpmail.gsfc.nasa.gov)
71  Original design
72 
73  Revision 1.0 1997/07/24 15:30
74  Tom Johnson/GSC (johnson@ltpmail.gsfc.nasa.gov)
75  Original design
76 
77 !Team-unique Header:
78  This software is developed by the MODIS Science
79  Data Support Team (SDST) for the National Aeronautics
80  and Space Administration (NASA), Goddard Space Flight
81  Center (GSFC), under contract NAS5-32373.
82 
83 !References and Credits:
84  None
85 
86 !Design Notes:
87  The details for the packet data locations were taken from
88  Santa Barbara Remote Sensing (SBRS) Contract Data Requirement
89  List (CDRL)305, MODIS Engineering Telemetry Description,
90  Tables T30-5A, T30-5B, T30-5C, T30-5D, and T30-5E.
91 
92 
93 !END*************************************************************************
94 */
95 
96  {
97  /**************************************************************************/
98  /* */
99  /* Define Global Variables */
100  /* */
101  /**************************************************************************/
102 
103  extern PGSt_double global_first_gran_start_time;
104  /* Start time for the first L1A */
105  /* output granule to be created */
106 
107  extern PGSt_PC_Logical global_L0_logical;
108  /* L0 logical file unit number */
109 
110  /**************************************************************************/
111  /* Define and Initialize Local Variables */
112  /**************************************************************************/
113  /* */
114  /* set returnStatus equal to MODIS_S_SUCCESS */
115  /* Set continue_trying to PGS_TRUE */
116  /* */
117  /**************************************************************************/
118 
119  char *routine = "set_start_position";
120  PGSt_SMF_status returnStatus; /* SMF-style message returned by function */
121  PGSt_SMF_status PGSstatus; /* SMF-style message returned by function */
122  PGSt_SMF_status L1Astatus; /* SMF-style message returned by function */
123  PGSt_SMF_boolean continue_trying; /* Boolean variable */
124 
125 
126  L1Astatus = MODIS_S_SUCCESS;
127  PGSstatus = MODIS_S_SUCCESS;
128  returnStatus = MODIS_S_SUCCESS;
129  continue_trying = PGS_TRUE;
130 
131 
132  /**************************************************************************/
133  /* */
134  /* DO-WHILE continue_trying */
135  /* */
136  /* CALL PGS_IO_L0_SetStart to set the virtual file pointer to the */
137  /* first available packet after the preload_start_time */
138  /* INPUTS: L0_file, preload_start_time */
139  /* OUTPUTS: None */
140  /* RETURN: PGSstatus */
141  /* */
142  /**************************************************************************/
143 
144  while (continue_trying) {
145  PGSstatus = PGS_IO_L0_SetStart (L0_file, *preload_start_time);
146 
147 
148  /**************************************************************************/
149  /* */
150  /* SWITCH (PGSstatus) */
151  /* CASE PGSIO_W_L0_TIME_NOT_FOUND */
152  /* IF stop_time is greater than or equal to */
153  /* global_first_gran_start_time */
154  /* THEN */
155  /* Set preload_start_time to start_time */
156  /* ELSE */
157  /* IF global_L0_logical equals PRIOR_L0_PCF_ID */
158  /* THEN */
159  /* CALL PGS_IO_L0_Close to close the prior L0 file */
160  /* INPUTS: L0_file */
161  /* OUTPUTS: None */
162  /* RETURN: PGSstatus */
163  /* */
164  /**************************************************************************/
165 
166  switch (PGSstatus) {
167  case PGSIO_W_L0_TIME_NOT_FOUND:
168  if (stop_time >= global_first_gran_start_time)
169  *preload_start_time = start_time;
170  else {
172  PGSstatus = PGS_IO_L0_Close (L0_file);
173 
174 
175  /**************************************************************************/
176  /* */
177  /* CALL PGS_SMF_TestSuccessLevel to determine if the prior */
178  /* L0 file was closed */
179  /* INPUTS: PGSstatus */
180  /* OUTPUTS: None */
181  /* RETURN: result */
182  /* */
183  /* IF result is equal to PGS_FALSE */
184  /* THEN */
185  /* CALL log_fmt_msg to report that the prior L0 file */
186  /* could not be closed */
187  /* INPUTS: PGSstatus, routine, msg */
188  /* OUTPUTS: None */
189  /* RETURN: None */
190  /* ENDIF */
191  /* */
192  /* Set global_L0_logical to CURRENT_L0_PCF_ID */
193  /* */
194  /* NOTE: Modis timestamps on both instruments, Terra and Aqua, */
195  /* use segmented timestamps. Therefore, no change is needed for */
196  /* Aqua delivery to read packet times. The Terra toolkit macros */
197  /* PGSd_EOS_AM1 are used so L0 files are opened using the */
198  /* toolkit routines which read segmented time. */
199  /* */
200  /* CALL get_valid_L0_file */
201  /* INPUTS: PGSd_EOS_AM1 */
202  /* OUTPUTS: L0_file, start_time, stop_time */
203  /* RETURNS: L1Astatus */
204  /* ENDIF */
205  /* */
206  /**************************************************************************/
207 
208  if (!PGS_SMF_TestSuccessLevel(PGSstatus))
210  "unable to close the prior L0 file");
211 
213 
214  L1Astatus = get_valid_L0_file ( PGSd_EOS_AM1,
215  &L0_file,
216  &start_time,
217  &stop_time);
218 
219  /**************************************************************************/
220  /* */
221  /* IF L1Astatus is not equal to MODIS_S_SUCCESS */
222  /* THEN */
223  /* CALL log_fmt_msg to report that the current L0 file */
224  /* could not be opened */
225  /* INPUTS: L1Astatus, routine, */
226  /* "unable to open the current L0 file" */
227  /* OUTPUTS: None */
228  /* RETURN: None */
229  /* */
230  /* Set returnStatus to MODIS_F_L0_SETSTART_FAILED */
231  /* Set continue_trying to PGS_FALSE */
232  /* ENDIF */
233  /* */
234  /**************************************************************************/
235 
236  if (L1Astatus != MODIS_S_SUCCESS) {
238  "unable to open the current L0 file");
239 
240  returnStatus = MODIS_F_L0_SETSTART_FAILED;
241  continue_trying = PGS_FALSE;
242  }
243  }
244 
245 
246 
247  /**************************************************************************/
248  /* */
249  /* ELSE */
250  /* Set continue_trying to PGS_FALSE */
251  /* Set returnStatus to MODIS_F_L0_SETSTART_FAILED */
252  /* CALL log_fmt_msg to report that the preload start time */
253  /* is outside of the current L0 file */
254  /* INPUTS: returnStatus, routine, */
255  /* "preload start time outside of current L0 file" */
256  /* OUTPUTS: None */
257  /* RETURN: None */
258  /* ENDIF */
259  /* ENDIF */
260  /* */
261  /**************************************************************************/
262 
263  else {
264  continue_trying = PGS_FALSE;
265  returnStatus = MODIS_F_L0_SETSTART_FAILED;
267  "preload start time outside of current L0 file");
268  }
269  }
270 
271  break;
272 
273  /**************************************************************************/
274  /* If call to PGS_IO_L0_SetStart returns PGSIO_E_L0_SEEK_PACKET, the */
275  /* start position could not be found in the L0 file. This may be due to */
276  /* missing data in the L0 file. When this value is returned and the */
277  /* current working L0 file is stored in LUN 599001, the process should */
278  /* try to open the 599002 LUN and see if its data is valid. */
279  /**************************************************************************/
280 
281  case PGSIO_E_L0_SEEK_PACKET:
282 
283  /**************************************************************************/
284  /* If global_L0_logical == PC_PRIOR_L0_PCF_ID (599001) then */
285  /* CALL PGS_IO_L0_Close to close the 599001 L0 file */
286  /* INPUTS: L0_file */
287  /* OUTPUTS: None */
288  /* RETURNS: PGSstatus */
289  /**************************************************************************/
290 
292  PGSstatus = PGS_IO_L0_Close (L0_file);
293 
294  /**************************************************************************/
295  /* If the call to PGS_IO_L0_Close to close the 599001 L0 file fails, then */
296  /* CALL log_fmt_msg to report that the file could not be closed */
297  /* INPUTS: MODIS_E_PGS_IO_LO_CLOSE, routine, */
298  /* "unable to close the prior L0 file" */
299  /* OUTPUTS: None */
300  /* RETURNS: None */
301  /**************************************************************************/
302 
303  if (!PGS_SMF_TestSuccessLevel(PGSstatus))
305  "unable to close the prior L0 file");
306 
307  /**************************************************************************/
308  /* set the global_L0_logical = PC_CURRENT_L0_PCF_ID (599002) */
309  /* */
310  /* NOTE: Modis timestamps on both instruments, Terra and Aqua, */
311  /* use segmented timestamps. Therefore, no change is needed for */
312  /* Aqua delivery to read packet times. The Terra toolkit macros */
313  /* PGSd_EOS_AM1 are used so L0 files are opened using the */
314  /* toolkit routines which read segmented time. */
315  /* */
316  /* CALL get_valid_L0_file */
317  /* INPUTS: PGSd_EOS_AM1 */
318  /* OUTPUTS: L0_file, start_time, stop_time */
319  /* RETURNS: L1Astatus */
320  /* ENDIF */
321  /**************************************************************************/
322 
324 
325  L1Astatus = get_valid_L0_file ( PGSd_EOS_AM1,
326  &L0_file,
327  &start_time,
328  &stop_time);
329 
330  /**************************************************************************/
331  /* If the return from get_valid_L0_file is not MODIS_S_SUCCESS then */
332  /* CALL log_fmt_msg to report that the L0 file could not be opened */
333  /* INPUTS: MODIS_E_GET_VALID_L0_FILE, routine, */
334  /* "unable to open the current L0 file" */
335  /* OUTPUTS: None */
336  /* RETURNS: None */
337  /* */
338  /* set returnStatus = MODIS_F_L0_SETSTART_FAILED */
339  /* set continue_trying = PGS_FALSE */
340  /**************************************************************************/
341 
342  if (L1Astatus != MODIS_S_SUCCESS) {
344  "unable to open the current L0 file");
345 
346  returnStatus = MODIS_F_L0_SETSTART_FAILED;
347  continue_trying = PGS_FALSE;
348  }
349  }
350 
351  /***************************************************************************/
352  /* The current L0 file is sotred in LUN 599002 already and processing */
353  /* should be halted. */
354  /* else */
355  /* set continue_trying = PGS_FALSE */
356  /* set returnStatus = MODIS_F_L0_SETSTART_FAILED */
357  /* CALL log_fmt_msg to report that the start time is outside of the */
358  /* current L0 file */
359  /* INPUTS: MODIS_F_L0_SETSTART_FAILED, routine, */
360  /* "preload start time outside of current L0 file" */
361  /* OUTPUTS: None */
362  /* RETURNS: None */
363  /* ENDIF */
364  /***************************************************************************/
365  else {
366  continue_trying = PGS_FALSE;
367  returnStatus = MODIS_F_L0_SETSTART_FAILED;
369  "preload start time outside of current L0 file");
370  }
371 
372  break;
373 
374 
375 
376 
377 
378  /**************************************************************************/
379  /* */
380  /* CASE PGSIO_M_L0_HEADER_CHANGED */
381  /* CALL validate_L0_header to validate the L0 header */
382  /* INPUT: L0_file */
383  /* OUTPUT: None */
384  /* RETURN: L1A_status */
385  /* */
386  /* IF L1A_status is not equal to MODIS_S_SUCCESS */
387  /* THEN */
388  /* Set returnStatus to MODIS_F_L0_SETSTART_FAILED */
389  /* CALL log_fmt_msg to report that the L0 file header could */
390  /* not be validated */
391  /* INPUT: L1A_status, routine, msg */
392  /* OUTPUT: None */
393  /* RETURN: None */
394  /* ENDIF */
395  /* */
396  /* Set continue_trying to PGS_FALSE */
397  /* */
398  /**************************************************************************/
399 
400  case PGSIO_M_L0_HEADER_CHANGED:
401  /* Comment out for now; use "inhouse" tools another time.
402  L1Astatus = validate_L0_header (L0_file);
403 
404  if (L1Astatus != MODIS_S_SUCCESS) {
405  returnStatus = MODIS_F_L0_SETSTART_FAILED;
406  log_fmt_msg (MODIS_F_L0_HEADER_VAL_FAILED, routine, "");
407  }
408 
409  continue_trying = PGS_FALSE;
410  */
411  break;
412 
413 
414 
415  /**************************************************************************/
416  /* */
417  /* CASE PGS_S_SUCCESS */
418  /* Set continue_trying to PGS_FALSE */
419  /* */
420  /* DEFAULT */
421  /* Set continue_trying to PGS_FALSE */
422  /* Set returnStatus to MODIS_F_L0_SETSTART_FAILED */
423  /* END_SWITCH */
424  /* END_WHILE */
425  /* */
426  /* RETURN returnStatus */
427  /* */
428  /**************************************************************************/
429 
430  case PGS_S_SUCCESS:
431  continue_trying = PGS_FALSE;
432  break;
433 
434  default:
435  continue_trying = PGS_FALSE;
436  returnStatus = MODIS_F_L0_SETSTART_FAILED;
437  break;
438  }
439  }
440 
441  return returnStatus;
442 
443  } /* End of routine set_start_position */
#define MODIS_E_GET_VALID_L0_FILE
PGSt_PC_Logical global_L0_logical
Definition: level1a.c:35
#define PC_CURRENT_L0_PCF_ID
Definition: PC_pcf_info.h:52
PGSt_SMF_status get_valid_L0_file(PGSt_tag spacecraft_tag, PGSt_IO_L0_VirtualDataSet *L0_file, PGSt_double *start_time, PGSt_double *stop_time)
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
PGSt_double global_first_gran_start_time
Definition: level1a.c:30
#define MODIS_S_SUCCESS
PGSt_SMF_status set_start_position(PGSt_IO_L0_VirtualDataSet L0_file, PGSt_double *preload_start_time, PGSt_double start_time, PGSt_double stop_time)
#define PC_PRIOR_L0_PCF_ID
Definition: PC_pcf_info.h:51
#define MODIS_F_L0_SETSTART_FAILED
#define MODIS_E_PGS_IO_LO_CLOSE