OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
load_eng_data.c
Go to the documentation of this file.
1 #include "PGS_MODIS_35005.h"
2 #include "PGS_IO.h"
3 #include "PGS_SMF.h"
4 #include "PGS_TYPES.h"
5 #include "PH_pkt_hdr.h"
6 #include "EN_eng_data.h"
7 #include "L1A_prototype.h"
8 
9 
10 PGSt_SMF_status load_eng_data (PGSt_double scan_rate,
11  EN_VDATA_TYPE_t *eng_data,
12  PGSt_IO_L0_Packet *pkt,
13  PH_PACKET_HEADER_t *pkt_header,
14  PGSt_IO_L0_VirtualDataSet L0_file)
15 
16 /*
17 !C************************************************************************
18 
19 !Description: This routine will populate the engineering data lists with
20  data from any engineering packets that are encountered.
21 
22 !Input Parameters:
23  PGSt_IO_L0_VirtualDataSet L0_file
24  ** Virtual data set - L0 file **
25 
26  PGSt_double scan_rate
27  ** The length of each scan in **
28  ** seconds **
29 
30 !Output Parameters:
31  PGSt_IO_L0_Packet *pkt ** Packet buffer which contains **
32  ** packed packet **
33 
34  PH_PACKET_HEADER_t *pkt_header
35  ** Buffer that contains the pkt **
36  ** header info of the packet **
37 
38 !Input/Output Parameters:
39  EN_VDATA_TYPE_t *eng_data
40  ** The structure containing the **
41  ** engineering data **
42 
43 Return Values:
44  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
45  MODIS_W_PRELOAD_ENG_DATA (PGS_MODIS_35005.h)
46  MODIS_F_PKT_READ_FAILED (PGS_MODIS_35005.h)
47  MODIS_W_NO_MORE_PACKETS (PGS_MODIS_35005.h)
48  MODIS_E_CORRUPT_PKT_HDR (PGS_MODIS_35005.h)
49  MODIS_E_CHECKSUM_NOT_VALID (PGS_MODIS_35005.h)
50 
51 Externally Defined:
52  PGSt_SMF_status (PGS_SMF.h)
53  PGS_TRUE (PGS_SMF.h)
54  PGS_FALSE (PGS_SMF.h)
55  PGSt_double (PGS_TYPES.h)
56  PGSt_IO_L0_Packet (PGS_IO.h)
57  PGSt_IO_L0_VirtualDataSet (PGS_IO.h)
58  PH_SEC_PKT_TYPE_ENG1_GROUP (PH_pkt_hdr.h)
59  PH_SEC_PKT_TYPE_ENG2_GROUP (PH_pkt_hdr.h)
60  PH_PACKET_HEADER_t (PH_pkt_hdr.h)
61  EN_VDATA_TYPE_t (EN_eng_data.h)
62 
63 Called By:
64  initialize_level1a
65 
66 Routines Called:
67  read_a_packet
68  log_fmt_msg
69  unpack_packet_header
70  unpack_packet_contents
71  check_checksum
72  process_eng_packet
73  compute_SD_start_time
74 
75 !Revision History:
76  Revision 2.1 1997/08/27 22:20 EDT
77  Timi Adelekan/SAIC/GSC (adelekan@ltpmail.gsfc.nasa.gov)
78  Originated Code.
79 
80  Revision 2.0 1997/07/15 11:20 EDT
81  Timi Adelekan/SAIC/GSC (adelekan@ltpmail.gsfc.nasa.gov)
82  Created Module for version 2 based on load_decom_data.pdl
83  of version 1.
84 
85  Revision 1.0 1997/06/18 16:40 EDT
86  Timi Adelekan/SAIC/GSC (adelekan@ltpmail.gsfc.nasa.gov)
87  Baseline from Version 1.
88 
89 !Team-unique Header:
90  This software is developed by the MODIS Science
91  Data Support Team (SDST) for the National Aeronautics
92  and Space Administration (NASA), Goddard Space Flight
93  Center (GSFC), under contract NAS5-32373.
94 
95 !References and Credits:
96  None
97 
98 !Design Notes:
99  The CODE was written in C language.
100 
101 !END**********************************************************************
102 */
103 
104  {
105  /**************************************************************************/
106  /* Define Global Variables */
107  /* */
108  /**************************************************************************/
109 
110  extern PGSt_double global_first_gran_start_time;
111  /* Start time for the first L1A */
112  /* output granule to be created */
113 
114 
115  /*************************************************************************/
116  /* Define and Initialize Local Variables */
117  /* */
118  /*************************************************************************/
119  /* set returnStatus equal to MODIS_S_SUCCESS */
120  /* set first_time_in_loop to PGS_TRUE */
121  /* set next_scan_start_time to -1.0 */
122  /* set continue_processing equal to PGS_TRUE */
123  /* set scan_num to 0 */
124  /* */
125  /*************************************************************************/
126 
127  char *routine = "load_eng_data";
128  PGSt_SMF_status returnStatus; /* SMF-style message returned by function */
129  PGSt_SMF_status tempStatus; /* SMF-style message returned by function */
130  PGSt_SMF_boolean first_time_in_loop;
131  /* loop control variable */
132  PGSt_SMF_boolean continue_processing;
133  /* loop control variable */
134  PGSt_double next_scan_start_time;/* variable that holds the next scan */
135  /* start time */
136  PGSt_double current_scan_start_time;
137  /* variable that holds the current scan */
138  /* start time */
139  uint16 pkt_contents[PD_NUM_ELMTS_IN_DATA_FIELD_DAY_PKT +
141  /* The current packet, with the 12-bit */
142  /* words unpacked into 16-bit integers */
143  int scan_num; /* Scan counter */
144 
145 
146  tempStatus = MODIS_S_SUCCESS;
147  returnStatus = MODIS_S_SUCCESS;
148  first_time_in_loop = PGS_TRUE;
149  continue_processing = PGS_TRUE;
150  next_scan_start_time = -1.0;
151  current_scan_start_time = 0.0;
152  scan_num = 0;
153 
154 
155  /*************************************************************************/
156  /* DO_WHILE (continue_processing equals PGS_TRUE) */
157  /* CALL read_a_packet to read a packet of data from the L0 virtual */
158  /* data set */
159  /* INPUTS: L0_file */
160  /* OUTPUTS: L0_file, pkt */
161  /* RETURN: returnStatus */
162  /* */
163  /* IF returnStatus is equal to MODIS_S_SUCCESS */
164  /* THEN */
165  /* CALL unpack_packet_header to unpack the packet's header */
166  /* information to determine what kind of packet it is */
167  /* INPUTS: pkt, PH_PACKET_HEADER_t */
168  /* OUTPUTS: NONE */
169  /* RETURN: tempStatus */
170  /* */
171  /* IF tempStatus is equal to MODIS_S_SUCCESS */
172  /* THEN */
173  /* IF (PH_PACKET_HEADER_t.pkt_TAI_time is greater than or equal */
174  /* to first_gran_start_time) */
175  /* THEN */
176  /* */
177  /*************************************************************************/
178 
179  while (continue_processing == PGS_TRUE) {
180  returnStatus = read_a_packet (&L0_file, pkt);
181 
182  if (returnStatus == MODIS_S_SUCCESS) {
183  tempStatus = unpack_packet_header (pkt, pkt_header);
184 
185  if (tempStatus == MODIS_S_SUCCESS) {
186 
187  if (pkt_header->pkt_TAI_time >= global_first_gran_start_time) {
188 
189 
190 
191  /*************************************************************************/
192  /* IF (next_scan_start_time < 0) -> { this is to ensure that */
193  /* this block of code */
194  /* is executed only once }*/
195  /* THEN */
196  /* CALL compute_SD_start_time to calculate the start time */
197  /* for the current scan of the current packet */
198  /* INPUTS: PH_PACKET_HEADER_t */
199  /* OUTPUTS: current_scan_start_time */
200  /* RETURN: NONE */
201  /* */
202  /* set next_scan_start_time to current_scan_start_time + */
203  /* scan_rate */
204  /* ENDIF */
205  /* */
206  /*************************************************************************/
207 
208  if (next_scan_start_time < 0.0) {
209  compute_SD_start_time (pkt_header, &current_scan_start_time);
210  next_scan_start_time = current_scan_start_time + scan_rate;
211  }
212 
213 
214 
215  /*************************************************************************/
216  /* IF (current_scan_start_time is greater than or equal to */
217  /* the first_gran_start_time) */
218  /* THEN */
219  /* set continue_processing equal to PGS_FALSE */
220  /* IF first_time_in_loop is equal to PGS_TRUE */
221  /* -> { this is the first time in */
222  /* while loop } */
223  /* THEN */
224  /* set returnStatus to MODIS_W_PRELOAD_ENG_DATA */
225  /* CALL log_fmt_msg to report warning in preloading */
226  /* eng data */
227  /* INPUTS: returnStatus, routine, msg */
228  /* OUTPUT: None */
229  /* RETURN: None */
230  /* ENDIF */
231  /* ELSE */
232  /* IF (packet's time is greater than or equal to the */
233  /* next_scan_start_time) */
234  /* THEN */
235  /* set continue_processing equal to PGS_FALSE */
236  /* ENDIF */
237  /* ENDIF */
238  /* ENDIF */
239  /* */
240  /*************************************************************************/
241 
242  if (current_scan_start_time >= global_first_gran_start_time) {
243  continue_processing = PGS_FALSE;
244 
245  if (first_time_in_loop) {
246  returnStatus = MODIS_W_PRELOAD_ENG_DATA;
247  log_fmt_msg (MODIS_W_PRELOAD_ENG_DATA, routine, "");
248  }
249  }
250  else
251  if (pkt_header->pkt_TAI_time >= next_scan_start_time)
252  continue_processing = PGS_FALSE;
253  }
254 
255 
256 
257  /*************************************************************************/
258  /* IF ( (continue_processing equals PGS_TRUE) AND */
259  /* (PH_PACKET_HEADER_t.pkt_type is equal to */
260  /* PH_SEC_PKT_TYPE_ENG1_GROUP OR */
261  /* PH_SEC_PKT_TYPE_ENG2_GROUP) ) */
262  /* THEN */
263  /* CALL unpack_packet_contents to unpack the packet contents */
264  /* of the virtual data set */
265  /* INPUTS: pkt */
266  /* OUTPUTS: pkt_contents */
267  /* RETURN: None */
268  /* */
269  /* CALL check_checksum to check the packet checksum */
270  /* INPUTS: pkt_contents, PH_PACKET_HEADER_t */
271  /* OUTPUTS: NONE */
272  /* RETURN: tempStatus */
273  /* */
274  /*************************************************************************/
275 
276  if ( (continue_processing == PGS_TRUE) &&
277  ((pkt_header->pkt_type == PH_SEC_PKT_TYPE_ENG1_GROUP) ||
278  (pkt_header->pkt_type == PH_SEC_PKT_TYPE_ENG2_GROUP)) ) {
279  unpack_packet_contents (pkt, pkt_header, pkt_contents);
280  tempStatus = check_checksum (*pkt_header, pkt_contents);
281 
282 
283 
284  /*************************************************************************/
285  /* IF tempStatus is equal to MODIS_S_SUCCESS */
286  /* THEN */
287  /* CALL process_eng_packet to process the Eng data from */
288  /* the Eng packets and store it in the Eng data */
289  /* structure */
290  /* INPUTS: PH_PACKET_HEADER_t, scan_number, pkt, */
291  /* eng_data */
292  /* OUTPUTS: eng_data */
293  /* RETURN: NONE */
294  /* ELSE */
295  /* set tempStatus to MODIS_E_CHECKSUM_NOT_VALID */
296  /* set msg equal to "descrepancy in packet checksum" */
297  /* CALL log_fmt_msg to report error in checksum */
298  /* descrepancy */
299  /* INPUTS: Status, routine, msg */
300  /* OUTPUT: None */
301  /* RETURN: None */
302  /* ENDIF */
303  /* ENDIF */
304  /* */
305  /*************************************************************************/
306 
307  if (tempStatus == MODIS_S_SUCCESS)
308  process_eng_packet (eng_data, scan_num, pkt_header, pkt);
309  else {
310  tempStatus = MODIS_E_CHECKSUM_NOT_VALID;
312  }
313  }
314  }
315 
316 
317 
318  /*************************************************************************/
319  /* ELSE */
320  /* set tempStatus to MODIS_E_CORRUPT_PKT_HDR */
321  /* CALL log_fmt_msg to report error in unpacking packet header */
322  /* INPUTS: Status, routine, msg */
323  /* OUTPUT: None */
324  /* RETURN: None */
325  /* ENDIF */
326  /* */
327  /*************************************************************************/
328 
329  else {
330  tempStatus = MODIS_E_CORRUPT_PKT_HDR;
331  log_fmt_msg (MODIS_E_CORRUPT_PKT_HDR, routine, "");
332  }
333  }
334 
335  /*************************************************************************/
336  /* ELSE */
337  /* set continue_processing equal to PGS_FALSE */
338  /* set msg equal to "error received in getting packet from virtual */
339  /* data set" */
340  /* CALL log_fmt_msg to report error in getting packet from virtual */
341  /* data set" */
342  /* INPUTS: returnStatus, routine, msg */
343  /* OUTPUT: None */
344  /* RETURN: None */
345  /* ENDIF */
346  /* */
347  /* set first_time_in_loop to PGS_FALSE */
348  /* */
349  /* END_WHILE */
350  /* */
351  /* return returnStatus */
352  /* */
353  /*************************************************************************/
354 
355  else {
356  continue_processing = PGS_FALSE;
357  log_fmt_msg (returnStatus, routine,
358  "error received in getting packet from virtual data set");
359  }
360 
361  first_time_in_loop = PGS_FALSE;
362  }
363 
364  return returnStatus;
365 
366  } /* End of routine load_eng_data */
#define PD_NUM_ELMTS_IN_DATA_FIELD_DAY_PKT
Definition: PD_pkt_data.h:79
PGSt_SMF_status read_a_packet(PGSt_IO_L0_VirtualDataSet *L0_file, PGSt_IO_L0_Packet *pkt)
Definition: read_a_packet.c:9
#define MODIS_E_CORRUPT_PKT_HDR
void compute_SD_start_time(PH_PACKET_HEADER_t *pkt_header, PGSt_double *SD_start_time)
void unpack_packet_contents(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *pkt_header, uint16 *pkt_contents)
PGSt_SMF_status unpack_packet_header(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *packet_header)
#define MODIS_E_CHECKSUM_NOT_VALID
#define PH_SEC_PKT_TYPE_ENG2_GROUP
Definition: PH_pkt_hdr.h:164
#define PH_NUM_12BIT_WORDS_IN_HEADER
Definition: PH_pkt_hdr.h:78
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
PGSt_SMF_status check_checksum(PH_PACKET_HEADER_t pkt_header, uint16 *pkt_contents)
Definition: check_checksum.c:9
PGSt_double pkt_TAI_time
Definition: PH_pkt_hdr.h:251
PGSt_double global_first_gran_start_time
Definition: level1a.c:30
#define PH_SEC_PKT_TYPE_ENG1_GROUP
Definition: PH_pkt_hdr.h:163
#define MODIS_W_PRELOAD_ENG_DATA
#define MODIS_S_SUCCESS
PGSt_SMF_status load_eng_data(PGSt_double scan_rate, EN_VDATA_TYPE_t *eng_data, PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *pkt_header, PGSt_IO_L0_VirtualDataSet L0_file)
Definition: load_eng_data.c:10
void process_eng_packet(EN_VDATA_TYPE_t *eng_data, int scan_number, PH_PACKET_HEADER_t *pkt_header, PGSt_IO_L0_Packet *pkt)