OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
read_a_packet.c
Go to the documentation of this file.
1 #include "PGS_IO.h"
2 #include "PGS_SMF.h"
3 #include "PGS_MODIS_35005.h"
4 #include "PH_pkt_hdr.h"
5 #include "PC_pcf_info.h"
6 #include "PD_pkt_data.h"
7 #include "L1A_prototype.h"
8 
9 PGSt_SMF_status read_a_packet (PGSt_IO_L0_VirtualDataSet *L0_file,
10  PGSt_IO_L0_Packet *pkt)
11 
12 /*
13 !C************************************************************************
14 
15 !Description: This function reads a packet of data from the L0 file.
16 
17 !Input Parameters:
18  None
19 
20 !Output Parameters:
21  PGSt_IO_L0_Packet *pkt ** L0 data packet **
22 
23 !Input/Output Parameters:
24  PGSt_IO_L0_VirtualDataSet *L0_file ** L0 virtual data set **
25 
26 Return Values:
27  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
28  MODIS_F_PKT_READ_FAILED (PGS_MODIS_35005.h)
29  MODIS_W_NO_MORE_PACKETS (PGS_MODIS_35005.h)
30 
31 Externally Defined:
32  PGSt_SMF_status (PGS_SMF.h)
33  PGSt_IO_L0_Packet (PGS_IO.h)
34  PGSt_IO_L0_VirtualDataSet (PGS_IO.h)
35  PGSt_Logical (PGS_TYPES)
36  PGS_TRUE (PGS_SMF.h)
37  PGS_FALSE (PGS_SMF.h)
38  PC_PRIOR_L0_PCF_ID (PC_pcf_info.h)
39  PC_CURRENT_L0_PCF_ID (PC_pcf_info.h)
40  PD_PKT_BUF_MAX (PD_pkt_data.h)
41  global_L0_logical (level1a)
42  PGSIO_W_L0_END_OF_VIRTUAL_DS (PGS_IO.h)
43  PGSIO_M_L0_HEADER_CHANGED (PGS_IO.h)
44  PGSIO_W_L0_PKT_BUF_TRUNCATE (PGS_IO.h)
45 
46 Called By:
47  process_a_packet
48  load_eng_data
49 
50 Routines Called:
51  PGS_SMF_TestSuccessLevel
52  PGS_IO_L0_GetPacket
53  PGS_IO_L0_Close
54  get_valid_L0_file
55  validate_L0_header
56  log_fmt_msg
57 
58 !Revision History:
59  Revision 2.3 2000/07026
60  John Seaton
61  Added aqua compatability modifications.
62 
63  Revision 2.2 2000/03/21 11:52
64  John Seaton (seaton@ltpmail.gsfc.nasa.gov)
65  Added check for packet truncate return code from
66  PGS_IO_L0_GetPacket. This will cause the PGE to continue
67  processing instead of failing exit code 1.
68 
69  Revision 2.1 1997/08/27 10:50
70  Tom Johnson (johnson@ltpmail.gsfc.nasa.gov)
71  Incorporate PDL walkthru comments
72 
73  Revision 2.0 1997/07/24 15:30
74  Tom Johnson/GSC (johnson@ltpmail.gsfc.nasa.gov)
75  Updated from Version 1 to Version 2
76 
77  Revision 1.0 1997/06/18 16:40 EDT
78  Timi Adelekan/GSC (adelekan@ltpmail.gsfc.nasa.gov)
79  Baseline from Version 1.
80 
81 !Team-unique Header:
82  This software is developed by the MODIS Science
83  Data Support Team (SDST) for the National Aeronautics
84  and Space Administration (NASA), Goddard Space Flight
85  Center (GSFC), under contract NAS5-32373.
86 
87 !References and Credits:
88  None
89 
90 !Design Notes:
91  The details for the packet data locations were taken from
92  Santa Barbara Remote Sensing (SBRS) Contract Data Requirement
93  List (CDRL)305, MODIS Engineering Telemetry Description,
94  Tables T30-5A, T30-5B, T30-5C, T30-5D, and T30-5E.
95 
96 
97 !END*************************************************************************
98 */
99 
100 {
101  /***************************************************************************/
102  /* */
103  /* Declare Global Variables */
104  /* */
105  /***************************************************************************/
106 
107  extern PGSt_PC_Logical global_L0_logical;
108  /* L0 logical file unit number */
109 
110  /***************************************************************************/
111  /* */
112  /* Declare and Initialize Local Variables */
113  /* */
114  /***************************************************************************/
115 
116  static PGSt_SMF_status lastStatus = MODIS_S_SUCCESS;
117 
118  PGSt_SMF_status returnStatus; /* SMF-style message returned by function */
119  PGSt_SMF_status L1A_status; /* SMF-style message returned by function */
120  PGSt_SMF_status PGS_status; /* SMF-style message returned by function */
121  char *routine = "read_a_packet";
122  char msg[300];
123  PGSt_double L0_start_time;
124  PGSt_double L0_stop_time;
125 
126 
127  /***************************************************************************/
128 
129 
130  /***************************************************************************/
131  /* */
132  /* Set returnStatus equal to MODIS_S_SUCCESS */
133  /* */
134  /* set routine to "read_a_packet" (done during declaration) */
135  /* */
136  /***************************************************************************/
137 
138  returnStatus = MODIS_S_SUCCESS;
139 
140 
141  /***************************************************************************/
142  /* */
143  /* IF lastStatus is not equal to MODIS_S_SUCCESS */
144  /* THEN */
145  /* */
146  /* Set returnStatus to lastStatus */
147  /* */
148  /* Set msg to "no more packets in current L0 file" */
149  /* CALL log_fmt_msg to report that there are no more packets */
150  /* in the L0 file */
151  /* INPUTS: returnStatus, routine, msg */
152  /* OUTPUTS: None */
153  /* RETURN: None */
154  /* */
155  /***************************************************************************/
156 
157  if (lastStatus != MODIS_S_SUCCESS)
158  {
159  returnStatus = lastStatus;
160  sprintf(msg, "L0 LUN: %d", global_L0_logical);
162  }
163 
164 
165  /***************************************************************************/
166  /* */
167  /* ELSE */
168  /* */
169  /* CALL PGS_IO_L0_GetPacket to retrieve a packet of data from the */
170  /* L0 file */
171  /* INPUTS: L0_file, pkt_buff_size */
172  /* OUTPUTS: pkt */
173  /* RETURN: returnStatus */
174  /* */
175  /***************************************************************************/
176 
177  else
178  {
179  PGS_status = PGS_IO_L0_GetPacket(*L0_file, PD_PKT_BUF_MAX, pkt);
180 
181 
182  /************************************************************************/
183  /* */
184  /* SWITCH (PGS_status) */
185  /* CASE PGSIO_W_L0_END_OF_VIRTUAL_DS */
186  /* */
187  /* IF global_L0_logical equals PRIOR_L0_PCF_ID */
188  /* THEN */
189  /* CALL PGS_IO_L0_Close to close the prior L0 file */
190  /* INPUTS: L0_file */
191  /* OUTPUTS: None */
192  /* RETURN: returnStatus */
193  /* */
194  /* CALL PGS_SMF_TestSuccessLevel to determine if the prior */
195  /* L0 file was closed */
196  /* INPUTS: returnStatus */
197  /* OUTPUTS: None */
198  /* RETURN: result */
199  /* */
200  /* IF result is equal to PGS_FALSE */
201  /* THEN */
202  /* set msg to "unable to close the prior L0 file" */
203  /* CALL log_fmt_msg to report that the prior L0 file */
204  /* could not be closed */
205  /* INPUTS: returnStatus, routine, msg */
206  /* OUTPUTS: None */
207  /* RETURN: None */
208  /* ENDIF */
209  /* */
210  /* Set global_L0_logical to CURRENT_L0_PCF_ID */
211  /* */
212  /* NOTE: Modis timestamps on both instruments, Terra and Aqua, */
213  /* use segmented timestamps. Therefore, no change is needed for */
214  /* Aqua delivery to read packet times. The Terra toolkit macros */
215  /* PGSd_EOS_AM1 are used so L0 files are opened using the */
216  /* toolkit routines which read segmented time. */
217  /* */
218  /* CALL get_valid_L0_file to open and validate the current */
219  /* L0 file */
220  /* INPUTS: spacecraft_tag */
221  /* OUTPUTS: L0_file, L0_start_time, L0_stop_time */
222  /* RETURN: returnStatus */
223  /* */
224  /* IF returnStatus is not equal to MODIS_S_SUCCESS */
225  /* THEN */
226  /* Set msg to "unable to open the current L0 file" */
227  /* CALL log_fmt_msg to report that the current L0 file */
228  /* could not be opened */
229  /* INPUTS: returnStatus, routine, msg */
230  /* OUTPUTS: None */
231  /* RETURN: None */
232  /* Set returnStatus to MODIS_F_PKT_READ_FAILED */
233  /* ENDIF */
234  /* ELSE */
235  /* set lastStatus to MODIS_W_NO_MORE_PACKETS */
236  /* ENDIF */
237  /************************************************************************/
238 
239  switch (PGS_status)
240  {
241  case PGSIO_W_L0_END_OF_VIRTUAL_DS:
243  {
244  PGS_status = PGS_IO_L0_Close (*L0_file);
245  if (PGS_SMF_TestSuccessLevel(PGS_status) == PGS_FALSE)
247  "Unable to close the prior L0 file");
248 
250  L1A_status = get_valid_L0_file(PGSd_EOS_AM1,
251  L0_file,
252  &L0_start_time,
253  &L0_stop_time);
254 
255  if (L1A_status != MODIS_S_SUCCESS)
256  {
257  sprintf(msg, "L0 LUN: %d", global_L0_logical);
259  lastStatus = MODIS_F_PKT_READ_FAILED;
260  }
261  }
262  else
263  {
264  lastStatus = MODIS_W_NO_MORE_PACKETS;
265  }
266  break;
267 
268 
269  /************************************************************************/
270  /* */
271  /* CASE PGSIO_M_L0_HEADER_CHANGED */
272  /* CALL validate_L0_header to validate the L0 header */
273  /* INPUT: L0_file */
274  /* OUTPUT: None */
275  /* RETURN: L1A_status */
276  /* */
277  /* IF L1A_status is not equal to MODIS_S_SUCCESS */
278  /* THEN */
279  /* Set returnStatus to MODIS_F_PKT_READ_FAILED */
280  /* Set msg to "unable to validate the L0 header */
281  /* successfully" */
282  /* CALL log_fmt_msg to report that the L0 header could not */
283  /* be validated successfully */
284  /* INPUT: L1A_status, routine, msg */
285  /* OUTPUT: None */
286  /* RETURN: None */
287  /* ENDIF */
288  /* */
289  /************************************************************************/
290 
291  case PGSIO_M_L0_HEADER_CHANGED:
292  L1A_status = validate_L0_header (*L0_file);
293  if (L1A_status != MODIS_S_SUCCESS)
294  {
295  returnStatus = MODIS_F_PKT_READ_FAILED;
296  sprintf(msg, "Unable to validate the L0 header successfully L0 LUN: %d",
299  }
300  break;
301 
302 
303  /************************************************************************/
304  /* */
305  /* CASE PGS_S_SUCCESS or PGSIO_W_L0_PKT_BUF_TRUNCATE */
306  /* The return code PGSIO_W_L0_PKT_BUF_TRUNCATE is returned when */
307  /* the Toolkit routine reads a packet that is too large to fit */
308  /* in the allocated packet space. The oversize portion of the */
309  /* packet is truncated. This prevents the PGE from exiting 1 as it */
310  /* would do if this return code went into the default case. */
311  /* Break */
312  /* */
313  /************************************************************************/
314 
315  case PGS_S_SUCCESS:
316  case PGSIO_W_L0_PKT_BUF_TRUNCATE:
317  break;
318 
319 
320  /************************************************************************/
321  /* */
322  /* DEFAULT */
323  /* Set returnStatus to MODIS_F_PKT_READ_FAILED */
324  /* END-SWITCH */
325  /* */
326  /************************************************************************/
327 
328  default:
329  returnStatus = MODIS_F_PKT_READ_FAILED;
330  }
331 
332 
333  /***************************************************************************/
334  /* */
335  /* ENDIF */
336  /* */
337  /***************************************************************************/
338 
339  }
340 
341  /***************************************************************************/
342  /* */
343  /* RETURN returnStatus */
344  /* */
345  /***************************************************************************/
346 
347  return (returnStatus);
348 
349 }
int validate_L0_header(PGSt_IO_L0_VirtualDataSet L0_file)
#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)
PGSt_SMF_status read_a_packet(PGSt_IO_L0_VirtualDataSet *L0_file, PGSt_IO_L0_Packet *pkt)
Definition: read_a_packet.c:9
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define MODIS_S_SUCCESS
#define MODIS_W_NO_MORE_PACKETS
#define MODIS_F_PKT_READ_FAILED
string msg
Definition: mapgen.py:227
#define PC_PRIOR_L0_PCF_ID
Definition: PC_pcf_info.h:51
#define MODIS_E_PGS_IO_LO_CLOSE
#define PD_PKT_BUF_MAX
Definition: PD_pkt_data.h:69