OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
accumulate_failed_packets.c
Go to the documentation of this file.
1 #include "L1A_prototype.h"
2 #include "PGS_IO.h"
3 #include "PGS_SMF.h"
4 #include "PGS_MODIS_35005.h"
5 #include "hdfi.h"
6 #include "PD_pkt_data.h"
7 #include "FP_failed_pkt_queue.h"
8 
9 PGSt_SMF_status accumulate_failed_packets (PGSt_IO_L0_Packet *pkt,
10  FP_QUEUE_t failed_pkts)
11 
12 /*
13 !C************************************************************************
14 
15 !Description: This function puts the failed packet "pkt" on the failed
16  packets queue "failed_pkts".
17 
18 !Input Parameters:
19  PGSt_IO_LO_Packet *pkt ** The MODIS packet **
20 
21 !Output Parameters:
22  None
23 
24 !Input/Output Parameters:
25  FP_QUEUE_t failed_pkts ** The failed pkt queue **
26 
27 Return Values:
28  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
29  MODIS_E_ENQUEUE (PGS_MODIS_35005.h)
30  MODIS_E_MALLOC_FAILED (PGS_MODIS_35005.h)
31 
32 Externally Defined:
33  FP_QUEUE_t (FP_failed_pkt_queue.h)
34  PGSt_IO_L0_Packet (PGS_IO.h)
35  PD_PKT_BUF_MAX (PD_pkt_data.h)
36  PGSt_SMF_status (PGS_SMF.h)
37  int8 (hdfi.h)
38 
39 Called By:
40  process_a_scan
41 
42 Routines Called:
43  log_fmt_msg
44  enqueue
45 
46 !Revision History:
47  Revision 2.0 1997/08/27 10:00
48  Tom Johnson (johnson@ltpmail.gsfc.nasa.gov)
49  Incorporate PDL walkthru comments
50 
51  Revision 1.0 1997/07/14 15:58 EDT
52  David Catozzi/SAIC/GSC (cato@ltpmail.gsfc.nasa.gov)
53  Original design.
54 
55 !Team-unique Header:
56  This software is developed by the MODIS Science
57  Data Support Team (SDST) for the National Aeronautics
58  and Space Administration (NASA), Goddard Space Flight
59  Center (GSFC), under contract NAS5-32373.
60 
61 !References and Credits:
62  None
63 
64 !Design Notes:
65  None
66 
67 !END************************************************************************
68 */
69 
70 {
71  /***************************************************************************/
72  /* Declare and Initialize Local Variables */
73  /***************************************************************************/
74 
75  PGSt_SMF_status returnStatus; /* SMF-style message returned by function */
76  char *routine = "accumulate_failed_packets";
77  int8 *copy_of_packet;
78  int i;
79 
80  /***************************************************************************/
81 
82 
83  /***************************************************************************/
84  /* */
85  /* Set returnStatus equal to MODIS_S_SUCCESS */
86  /* */
87  /* set routine to "accumulate_failed_packets" (done during declaration) */
88  /* */
89  /***************************************************************************/
90 
91  returnStatus = MODIS_S_SUCCESS;
92 
93 
94  /***************************************************************************/
95  /* */
96  /* dynamically allocate 650 bytes of memory for the failed packet */
97  /* */
98  /* IF ( unable to allocate memory for the failed packet ) */
99  /* THEN */
100  /* */
101  /* Set returnStatus to MODIS_E_MALLOC_FAILED */
102  /* CALL log_fmt_msg to report that memory could not be allocated for */
103  /* the failed packet */
104  /* INPUTS: MODIS_E_MALLOC_FAILED, msg, "memory allocation error" */
105  /* OUTPUTS: None */
106  /* RETURN: None */
107  /* */
108  /***************************************************************************/
109 
110  copy_of_packet = (int8 *) malloc(650);
111 
112  if (copy_of_packet == NULL)
113  {
114  returnStatus = MODIS_E_MALLOC_FAILED;
116  "Need an additional 650 bytes to store the failed packet data");
117  }
118 
119 
120  /***************************************************************************/
121  /* */
122  /* ELSE */
123  /* DO FOR ( i = 0 to 649 ) */
124  /* IF (i < PD_PKT_BUF_MAX) */
125  /* THEN */
126  /* Set copy_of_packet[i] to pkt[i] */
127  /* ELSE */
128  /* Set copy_of_packet[i] to 0 */
129  /* ENDIF */
130  /* END DO */
131  /* */
132  /* CALL enqueue to put the failed packet on the queue */
133  /* INPUTS: copy_of_packet, failed_pkts */
134  /* OUTPUTS: None */
135  /* RETURN: returnStatus */
136  /* */
137  /* IF ( returnStatus is MODIS_E_MALLOC_FAILED ) */
138  /* THEN */
139  /* Set msg to "failed packet could not be put in the queue" */
140  /* Set logStatus to MODIS_E_ENQUEUE */
141  /* CALL log_fmt_msg to report that the failed packet could not be */
142  /* put in the queue */
143  /* INPUTS: logStatus, routine, msg */
144  /* OUTPUTS: None */
145  /* RETURN: None */
146  /* ENDIF */
147  /* */
148  /* ENDIF */
149  /* */
150  /***************************************************************************/
151 
152  else
153  {
154  memset (copy_of_packet, 0, 650);
155  for (i=0; i<PD_PKT_BUF_MAX; i++)
156  copy_of_packet[i] = pkt[i];
157 
158  returnStatus = enqueue ((char *)copy_of_packet, failed_pkts);
159 
160  if (returnStatus == MODIS_E_MALLOC_FAILED)
161  log_fmt_msg (MODIS_E_ENQUEUE, routine,
162  "Could not allocate the failed packets linked list node");
163  }
164 
165 
166  /***************************************************************************/
167  /* */
168  /* RETURN returnStatus */
169  /* */
170  /***************************************************************************/
171 
172  return (returnStatus);
173 
174 }
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_MALLOC_FAILED
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
PGSt_SMF_status enqueue(char *item, FP_QUEUE_t Q)
Definition: enqueue.c:7
#define MODIS_S_SUCCESS
#define MODIS_E_ENQUEUE
int i
Definition: decode_rs.h:71
#define PD_PKT_BUF_MAX
Definition: PD_pkt_data.h:69
PGSt_SMF_status accumulate_failed_packets(PGSt_IO_L0_Packet *pkt, FP_QUEUE_t failed_pkts)