OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
level1a.c
Go to the documentation of this file.
1 #include <math.h>
2 #include "EN_eng_data.h"
3 #include "FP_failed_pkt_queue.h"
4 #include "hdfi.h"
5 #include "L1A_prototype.h"
6 #include "MS_misc.h"
7 #include "PC_pcf_info.h"
8 #include "PGS_IO_L0.h"
9 #include "PGS_MODIS_35005.h"
10 #include "PGS_PC.h"
11 #include "PGS_SMF.h"
12 #include "PGS_TD.h"
13 #include "PGS_TYPES.h"
14 #include "PH_pkt_hdr.h"
15 #include "VU_vdata_utility.h"
16 #include "version.h"
17 #include "smfio.h"
18 
19 /*
20  * Define Global Variables
21  */
22 
23 char global_input_pointer[MAX_INPUTS][PGSd_PC_VALUE_LENGTH_MAX];
24  /* Input file names: Eng Data List file name,
25  prior L0 file name, current L0 file name */
28  /* This is shared between the functions in this file so the
29  user of this package doesn't have to deal with it. */
30 PGSt_double global_first_gran_start_time; /* first granule start time */
31 PGSt_double global_last_gran_stop_time; /* last granule stop time */
32 PGSt_double global_time_offset_array[5];
33  /* The time offsets for each sector from
34  the beginning of the scan (ie. SD sector) */
35 PGSt_PC_Logical global_L0_logical; /* L0 file unit number */
37  /* used to store the Vdata IDs so that functions
38  need only refer to Vdatas by name */
39 
40 int main ()
41 /******************************************************************************
42 !C
43 
44 !Description: This is the main function of the MODIS Level 1A processing
45  system.
46 
47 !Input Parameters: None
48 
49 !Output Parameters: None
50 
51 Return Values:
52  MS_MT_EXIT_FATAL_FAILURE
53  MS_MT_EXIT_SUCCESS
54 
55 Externally Defined:
56  EN_NUM_VDATAS (EN_eng_data.h)
57  EN_VDATA_TYPE_t (EN_eng_data.h)
58  FALSE (hdfi.h)
59  FP_QUEUE_t (FP_failed_pkt_queue.h)
60  int32 (hdfi.h)
61  MODIS_E_INITIALIZATION_FAILED (PGS_MODIS_35005.h)
62  MODIS_E_L1A (PGS_MODIS_35005.h)
63  MODIS_E_MALLOC_FAILED (PGS_MODIS_35005.h)
64  MODIS_E_NO_SCANS_IN_PRODUCT (PGS_MODIS_35005.h)
65  MODIS_F_PROCESSAGRANULE (PGS_MODIS_35005.h)
66  MODIS_U_L1A_BEGIN (PGS_MODIS_35005.h)
67  MODIS_U_L1A_END (PGS_MODIS_35005.h)
68  MS_MT_EXIT_FATAL_FAILURE (MS_misc.h)
69  MS_MT_EXIT_SUCCESS (MS_misc.h)
70  PCF_CONFIG_t (PC_pcf_info.h)
71  PD_PKT_BUF_MAX (PD_pkt_data.h)
72  PGSd_PC_VALUE_LENGTH_MAX (PGS_PC.h)
73  PGS_SMF_MAX_MSGBUF_SIZE (PGS_SMF.h)
74  PGS_SMF_MASK_LEV_F (PGS_SMF.h)
75  PGS_TRUE (PGS_SMF.h)
76  PGSt_double (PGS_TYPES.h)
77  PGSt_IO_L0_VirtualDataSet (PGS_IO_L0.h)
78  PGSt_PC_Logical (PGS_TYPES.h)
79  PGSt_SMF_status (PGS_SMF.h)
80  PH_PACKET_HEADER_t (PH_pkt_hdr.h)
81  PROCESSVERSION (version.h)
82  VU_ID_TABLE (VU_vdata_utility.h)
83  VU_MAX_NUMBER_OF_VDATAS (VU_vdata_utility.h)
84 
85 Called By: ECS
86 
87 Routines Called:
88  PGS_SMF_TestSuccessLevel
89  initialize_level1a
90  process_a_granule
91  make_queue
92  free_queue
93  log_fmt_msg
94  close_processing_run
95 
96 !Revision History:
97  $Log: level1a.c,v $
98  Revision 5.2 2006/01/04 17:12:19 kuyper
99  Changed to avoid daylight savings time problems by using a method of
100  skipping leap seconds that works directly on the asciiUTC representation.
101 
102  Revision 5.1 2006/01/04 00:02:44 kuyper
103  Change to use minutes rather than seconds for granule sizes, for better
104  handling of leap seconds, resolving MODur00122 and GSFcd02888.
105 
106  Revision 4.3 2003/11/12 21:06:50 kuyper
107  Changed to use MAX_INPUTS macro.
108 
109  Revision 4.2 2003/04/24 18:25:02 vlin
110  updated after code walkthrough
111 
112  Revision 4.1 2003/02/24 20:21:04 kuyper
113  Removed inappropriate uses of NULL.
114 
115  Revision 4.0 2003/01/08 19:35:56 vlin
116  updated according to level1a.pdl revision 4.2
117  vlin@saicmodis.com
118 
119  Revision 2.2 2001/01/04
120  John Seaton (seaton@ltpmail.gsfc.nasa.gov)
121  Added new mnemonic for L1A version, not PGE version.
122 
123  Revision 2.1 2000/07/17
124  John Seaton (seaton@ltpmail.gsfc.nasa.gov)
125  Added changes for Aqua spacecraft
126 
127  Revision 2.0 1997/08/08 15:15 EDT
128  Timi Adelekan/SAIC/GSC (adelekan@ltpmail.gsfc.nasa.gov)
129  Remodeled PDL per Version 2 development.
130 
131 !Team-unique Header:
132 
133  This software is developed by the MODIS Science Data Support Team
134  for the National Aeronautics and Space Administration,
135  Goddard Space Flight Center, under contract NAS5-32373.
136 
137 References and Credits:
138 
139 Design Notes:
140 
141 !END
142 ******************************************************************************/
143 
144 {
145  PGSt_SMF_status Status;
146  int exitStatus = MS_MT_EXIT_SUCCESS;
147  char routine[] = "level1a";
148  PCF_CONFIG_t pcf_config;
149  PGSt_double gran_start_time;
150  PGSt_double gran_stop_time;
151  PGSt_IO_L0_VirtualDataSet L0_file; /* File containing L0 data */
152  PGSt_IO_L0_Packet pkt[PD_PKT_BUF_MAX]; /* Packet of L0 data */
153  PH_PACKET_HEADER_t pkt_header; /* Unpacked header of L0 packet */
154  EN_VDATA_TYPE_t eng_data[EN_NUM_VDATAS];/* Engineering vdata structure */
155  FP_QUEUE_t failed_pkts; /* Discarded packets queue */
156 
157  setlinebuf (stdout);
158  printf("MODIS L1A version %s, built %s %s\n",
159  PROCESSVERSION, __DATE__, __TIME__);
160 
161  log_fmt_msg(MODIS_U_L1A_BEGIN, routine, "L1A version %s built on %s, at %s",
162  PROCESSVERSION, __DATE__, __TIME__);
163  Status = initialize_level1a(&pcf_config, eng_data, pkt,
164  &pkt_header, &L0_file);
165 
166  if (PGS_SMF_TestStatusLevel(Status) < PGS_SMF_MASK_LEV_F) {
167  failed_pkts = make_queue();
168  if (failed_pkts != NULL)
169  {
170  gran_start_time = pcf_config.first_gran_start_time;
171  gran_stop_time = pcf_config.first_gran_start_time +
172  pcf_config.gran_time_length*60.0;
173 
174  while (fabs(gran_start_time - pcf_config.last_gran_stop_time) > 0.1)
175  {
176  char asciiUTC[TIMECODEASIZE];
177 
178  //gran_stop_time = gran_start_time + pcf_config.gran_time_length*60.0
179  //+ 1.0; /* to cover leapseconds, if present. */
180 
181  if(PGS_SMF_TestErrorLevel(PGS_TD_TAItoUTC(gran_stop_time, asciiUTC))
182  != PGS_FALSE)
183  {
184  log_fmt_msg(MODIS_E_L1A, routine, "PGS_TD_TAItoUTC(%.1f)",
185  gran_start_time);
186  exitStatus = MS_MT_EXIT_FATAL_FAILURE;
187  }
188  else
189  {
190  /* Cancel out the +1.0, if no leap second was present, by
191  * setting the last seconds digit to 0.
192  */
193  // JMG: This assumes that before adding the leap second above,
194  // the stop_time had a 0 in the first digit to the left
195  // of the decimal point. This assumption does not
196  // always hold.
197 
198  // I have modified the source code by commenting out
199  // the addition of the leapsec above and removing the
200  // call to UTCtoTAI just below.
201 
202  asciiUTC[sizeof "2001-01-01T00:00:"] = '0';
203 
204  /*
205  if(PGS_SMF_TestErrorLevel(PGS_TD_UTCtoTAI(asciiUTC,
206  &gran_stop_time)) != PGS_FALSE)
207  */
208  if(0)
209  {
210  log_fmt_msg(MODIS_E_L1A, routine, "PGS_TD_UTCtoTAI(\"%s\")",
211  asciiUTC);
212  exitStatus = MS_MT_EXIT_FATAL_FAILURE;
213  }
214  else if(PGS_SMF_TestStatusLevel(process_a_granule(L0_file,
215  gran_start_time, gran_stop_time, &pcf_config, eng_data,
216  &pkt_header, pkt, &failed_pkts)) != PGS_SMF_MASK_LEV_F)
217  {
220  gran_start_time = gran_stop_time;
221  if (global_input_pointer[2][0] != '\0') {
222  memset(global_input_pointer[1], '\0',
223  sizeof(global_input_pointer[1]));
225  memset(global_input_pointer[2], '\0',
226  sizeof(global_input_pointer[2]));
227  }
228  }
229  else {
231  "Fatal Error: Could not process a granule");
232  gran_start_time = pcf_config.last_gran_stop_time;
233  exitStatus = MS_MT_EXIT_FATAL_FAILURE;
234  }
235  }
236  } /* end while */
237  free_queue (failed_pkts);
238  }
239  else {
241  "unable to allocate memory for the discarded packets queue");
242  exitStatus = MS_MT_EXIT_FATAL_FAILURE;
243  }
244  }
245  else {
247  "Routine initialize_level1a failed");
248  exitStatus = MS_MT_EXIT_FATAL_FAILURE;
249  }
250 
251  close_processing_run(L0_file);
252  log_fmt_msg(MODIS_U_L1A_END, routine, "L1A return code = %d", exitStatus);
253  return exitStatus;
254 
255 }
FP_QUEUE_t make_queue(void)
Definition: make_queue.c:6
#define VU_MAX_NUMBER_OF_VDATAS
PGSt_double global_first_gran_start_time
Definition: level1a.c:30
PGSt_PC_Logical global_L0_logical
Definition: level1a.c:35
#define FALSE
Definition: rice.h:164
#define NULL
Definition: decode_rs.h:63
int main()
Definition: level1a.c:40
int32 global_H_ID
Definition: level1a.c:27
PGSt_SMF_status initialize_level1a(PCF_CONFIG_t *pcf_config, EN_VDATA_TYPE_t *eng_data, PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *pkt_header, PGSt_IO_L0_VirtualDataSet *L0_file)
#define MODIS_E_MALLOC_FAILED
#define MODIS_F_PROCESSAGRANULE
#define TIMECODEASIZE
Definition: Metadata.c:59
#define MS_MT_EXIT_FATAL_FAILURE
Definition: MS_misc.h:55
void close_processing_run(PGSt_IO_L0_VirtualDataSet L0_file)
PGSt_double first_gran_start_time
Definition: PC_pcf_info.h:81
#define MAX_INPUTS
PGSt_double global_time_offset_array[5]
Definition: level1a.c:32
int setlinebuf(FILE *stream)
VU_ID_TABLE global_VU_VDATA_ID[VU_MAX_NUMBER_OF_VDATAS]
Definition: level1a.c:36
#define MS_MT_EXIT_SUCCESS
Definition: MS_misc.h:56
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define PROCESSVERSION
Definition: version.h:112
PGSt_double global_last_gran_stop_time
Definition: level1a.c:31
char global_input_pointer[MAX_INPUTS][PGSd_PC_VALUE_LENGTH_MAX]
Definition: level1a.c:23
#define MODIS_E_L1A
int global_VU_ID_TABLE_READY
Definition: level1a.c:26
PGSt_double last_gran_stop_time
Definition: PC_pcf_info.h:82
#define EN_NUM_VDATAS
Definition: EN_eng_data.h:64
PGSt_SMF_status process_a_granule(PGSt_IO_L0_VirtualDataSet L0_file, PGSt_double gran_start_time, PGSt_double gran_end_time, PCF_CONFIG_t *pcf_config, EN_VDATA_TYPE_t *eng_data, PH_PACKET_HEADER_t *pkt_header, PGSt_IO_L0_Packet *pkt, FP_QUEUE_t *failed_pkts)
#define MODIS_U_L1A_END
PGSt_double gran_time_length
Definition: PC_pcf_info.h:83
#define fabs(a)
Definition: misc.h:93
#define MODIS_E_INITIALIZATION_FAILED
#define MODIS_U_L1A_BEGIN
void free_queue(FP_QUEUE_t Q)
Definition: free_queue.c:6
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
#define PD_PKT_BUF_MAX
Definition: PD_pkt_data.h:69