OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
write_failed_packets.c
Go to the documentation of this file.
1 #include "L1A_prototype.h"
2 #include "FP_failed_pkt_queue.h"
3 #include "PGS_MODIS_35005.h"
4 #include "PGS_SMF.h"
5 #include "hdf.h"
6 #include "mapiL1A.h"
7 #include "hfile.h"
8 
9 
10 PGSt_SMF_status write_failed_packets (FP_QUEUE_t failed_pkts)
11 
12 /*
13 !C*****************************************************************************
14 
15 !Description: This function writes the failed packets for the scan to the
16  L1A file's 'Discarded Packets' Vdata.
17 
18 !Input Parameters:
19  FP_QUEUE_t failed_pkts ** The failed_pkts queue **
20 
21 !Output Parameters:
22  None
23 
24 Return Values:
25  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
26  FAIL (HDF)
27 
28 Externally Defined:
29  FP_QUEUE_t (FP_failed_pkt_queue.h)
30  PGSt_SMF_status (PGS_SMF.h)
31  MODIS_E_WRITE_VDATA (PGS_MODIS_35005.h)
32  FP_VDATA_MAX_BLOCK_NUM (FP_failed_pkt_queue.h)
33 
34 Called By:
35  write_scan
36 
37 Routines Called:
38  dequeue
39  write_Vdata
40  log_fmt_msg
41 
42 !Revision History:
43  Revision 2.0 1999/08/20 10:47
44  John Seaton/SAIC/GSC (seaton@ltpmail.gsfc.nasa.gov)
45  Added call to free the packet memory.
46 
47  Revision 1.1 1997/09/03 10:55
48  Tom Johnson/GSC (johnson@ltpmail.gsfc.nasa.gov)
49  Incorporate walkthrough 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  /* */
73  /* Define Local Variables */
74  /* */
75  /***************************************************************************/
76 
77  PGSt_SMF_status returnStatus; /* SMF-style message returned by function */
78  PGSt_SMF_status tempStatus; /* SMF-style message returned by function */
79  char *next_failed_packet;
80  char *routine = "write_failed_packets";
81  extern int32 global_H_ID;
82  filerec_t *file_rec;
83 
84 
85  /***************************************************************************/
86  /* */
87  /* set routine to "write_failed_packets" (done during declaration) */
88  /* */
89  /* set returnStatus to MODIS_S_SUCCESS */
90  /* */
91  /***************************************************************************/
92 
93  returnStatus = MODIS_S_SUCCESS;
94 
95 
96  /***************************************************************************/
97  /* */
98  /* CALL dequeue to take the first packet off the failed_pkts queue */
99  /* INPUTS: failed_pkts */
100  /* OUTPUTS: failed_pkts */
101  /* RETURN: next_failed_packet */
102  /* */
103  /***************************************************************************/
104 
105  next_failed_packet = dequeue(failed_pkts);
106 
107 
108  /***************************************************************************/
109  /* */
110  /* Call HAatom_object to get the current number of vdata blocks used */
111  /* INPUTS: global_H_ID */
112  /* OUTPUTS: None */
113  /* RETURNS: filerec_t structure (file_rec) */
114  /* */
115  /* DO_WHILE (next_failed_packet is not NULL) */
116  /* */
117  /* IF file_rec->maxref does not exceed the max number of vdata blocks */
118  /* to be safely written (FP_VDATA_MAX_BLOCK_NUM) */
119  /* */
120  /* CALL write_Vdata to write 1 record (650 bytes) for each failed */
121  /* packet to the Discarded Packets Vdata for this scan */
122  /* INPUTS: "Discarded Packets", next_failed_packet, 1 */
123  /* OUTPUTS: None */
124  /* RETURN: tempStatus */
125  /* */
126  /* IF (tempStatus is FAIL) */
127  /* THEN */
128  /* set Status to MODIS_E_WRITE_VDATA */
129  /* CALL log_fmt_msg to report that the failed packet could not be */
130  /* written to the L1A granule */
131  /* INPUTS: Status, routine, msg */
132  /* OUTPUTS: None */
133  /* RETURN: None */
134  /* set returnStatus to FAIL */
135  /* ENDIF */
136  /* ENDIF */
137  /* */
138  /***************************************************************************/
139 
140  file_rec = HAatom_object(global_H_ID);
141 
142  while (next_failed_packet != NULL)
143  {
144  if (file_rec->maxref <= FP_VDATA_MAX_BLOCK_NUM) {
145  tempStatus = write_Vdata(M01DISCARDED_PACKETS,
146  (unsigned char *) next_failed_packet, 1);
147 
148  if (tempStatus == FAIL)
149  {
150  log_fmt_msg(MODIS_E_WRITE_VDATA, routine, "Vdata Name: Discarded packets");
151  returnStatus = FAIL;
152  }
153  }
154 
155 
156  /***************************************************************************/
157  /* */
158  /* free the space for the dequeued failed packet (next_failed_packet) */
159  /* */
160  /* ----------------------------------------------------------- */
161  /* */
162  /* CALL dequeue to take the first packet off the failed_pkts queue */
163  /* INPUTS: failed_pkts */
164  /* OUTPUTS: failed_pkts */
165  /* RETURN: next_failed_packet */
166  /* */
167  /* END_WHILE */
168  /* */
169  /***************************************************************************/
170 
171  free(next_failed_packet);
172 
173  next_failed_packet = dequeue(failed_pkts);
174 
175  }
176 
177 
178  /***************************************************************************/
179  /* */
180  /* RETURN returnStatus */
181  /* */
182  /***************************************************************************/
183 
184  return (returnStatus);
185 
186 }
187 
#define FAIL
Definition: ObpgReadGrid.h:18
#define NULL
Definition: decode_rs.h:63
int32 global_H_ID
Definition: level1a.c:27
char * dequeue(FP_QUEUE_t Q)
Definition: dequeue.c:5
PGSt_SMF_status write_failed_packets(FP_QUEUE_t failed_pkts)
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define MODIS_E_WRITE_VDATA
#define MODIS_S_SUCCESS
PGSt_SMF_status write_Vdata(char *Vdata_name, unsigned char *data, int32 num_records)
Definition: write_Vdata.c:8
#define FP_VDATA_MAX_BLOCK_NUM