OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
write_scan.c
Go to the documentation of this file.
1 #include "L1A_prototype.h"
2 #include "mapi.h"
3 #include "PGS_MODIS_35005.h"
4 #include "SC_scan.h"
5 #include "hdf.h"
6 #include "MD_metadata.h"
7 #include "EN_eng_data.h"
8 #include "FP_failed_pkt_queue.h"
9 #include "PGS_SMF.h"
10 #include "hfile.h"
11 
12 PGSt_SMF_status write_scan ( MODFILE *L1A_file_ptr,
13  SC_SCAN_DATA_t *L1A_scan,
14  MD_SCAN_MET_t *scan_meta,
15  SC_PIXEL_QUALITY_DATA_t *pix_qual,
16  FP_QUEUE_t failed_pkts,
17  EN_VDATA_TYPE_t *eng_data )
18 
19 /*
20 !C**********************************************************************
21 
22 !Description: This function is a driver for other 'write' functions.
23 
24 !Input Parameters:
25  MODFILE *L1A_file_ptr ** A pointer to the L1A
26  file **
27  SC_SCAN_DATA_t *L1A_scan ** L1A scan data for
28  this scan **
29  MD_SCAN_MET_t scan_meta ** Scan metadata for
30  this scan **
31  SC_PIXEL_QUALITY_DATA_t pix_qual ** The pixel quality
32  data for this scan **
33  FP_QUEUE_t failed_pkts ** The discarded packets
34  for this scan **
35  EN_VDATA_TYPE_t eng_data ** Engineering data for
36  this scan **
37 
38 !Output Parameters:
39  None
40 
41 Return Values:
42  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
43  MODIS_E_WRITE_SCAN_FAIL (PGS_MODIS_35005.h)
44  MODIS_F_WRITE_ENG_DATA_F (PGS_MODIS_35005.h)
45 
46 Externally Defined:
47  PGSt_SMF_status (PGS_SMF.h)
48  MODFILE (mapi.h)
49  SC_SCAN_DATA_t (SC_scan.h)
50  SC_PIXEL_QUALITY_DATA_t (SC_scan.h)
51  MD_SCAN_MET_t (MD_metadata.h)
52  EN_VDATA_TYPE_t (EN_eng_data.h)
53  FP_QUEUE_t (FP_failed_pkt_queue.h)
54 
55 Called By:
56  process_a_granule
57 
58 Routines Called:
59  write_scan_metadata
60  write_pix_qual
61  write_scan_data
62  write_failed_packets
63  write_eng_data
64  log_fmt_msg
65 
66 !Revision History:
67  Revision 2.0 1999/08/20 11:33:00
68  John Seaton/SAIC/GSC (seaton@ltpmail.gsfc.nasa.gov)
69  Added code to not write past the vdata block limit for
70  the discarded packet vdata, and free memory used by
71  non-written discarded packets.
72 
73  revision 1.0 1997/08/29 17:30:00
74  Qi Huang/RDC (qhuang@ltpmail.gsfc.nasa.gov)
75  Original development
76 
77 !Team-unique Header:
78  This software is developed by the MODIS Science
79  Data Support Team (SDST) for the National Aeronautics
80  and Space Administration (NASA), Goddard Space Flight
81  Center (GSFC), under contract NAS5-32373.
82 
83 !References and Credits:
84  None
85 
86 !Design Notes:
87  None
88 
89 !END************************************************************************
90 */
91 {
92  PGSt_SMF_status returnStatus;
93  char *routine = "write_scan";
94  char msg[300];
95  int temp_status;
96  int scan_num;
97 
98  /**********************************************************************************/
99  /* */
100  /* set returnStatus to MODIS_S_SUCCESS */
101  /* */
102  /**********************************************************************************/
103 
104  returnStatus = MODIS_S_SUCCESS;
105 
106 
107  /**********************************************************************************/
108  /* */
109  /* CALL write_scan_metadata to write out the Scan Level Metadata (section 2 of */
110  /* the MODIS Level 1A Data Product Format) */
111  /* INPUTS: L1A_file_ptr, MD_SCAN_MET_t */
112  /* OUTPUTS: None */
113  /* RETURN: temp_status */
114  /* */
115  /**********************************************************************************/
116 
117  temp_status = write_scan_metadata(L1A_file_ptr, scan_meta);
118 
119 
120  /**********************************************************************************/
121  /* */
122  /* IF temp_status is not equal to MODIS_S_SUCCESS */
123  /* THEN */
124  /* set msg to "The Scan Level Metadata could not be written to the L1A */
125  /* granule for scan number (number)" */
126  /* CALL log_fmt_msg to report that the Scan Level Metadata could not be */
127  /* written to the L1A file */
128  /* INPUTS: temp_status, routine, msg */
129  /* OUTPUT: None */
130  /* RETURN: None */
131  /* set returnStatus to MODIS_E_WRITE_SCAN_FAIL */
132  /* ENDIF */
133  /* */
134  /**********************************************************************************/
135 
136  if (temp_status != MODIS_S_SUCCESS)
137  {
138  sprintf(msg,"The Scan Level Metadata could not be written to the L1A granule: %s scan number: %d",
139  L1A_file_ptr->filename, scan_meta->scan_num);
141  returnStatus = MODIS_E_WRITE_SCAN_FAIL;
142  }
143 
144 
145  /**********************************************************************************/
146  /* */
147  /* set scan_num to MD_SCAN_MET_t.scan_num */
148  /* */
149  /**********************************************************************************/
150 
151  scan_num = scan_meta->scan_num;
152 
153 
154  /**********************************************************************************/
155  /* */
156  /* CALL write_pix_qual to write out the Pixel Quality Data (section 3 of the */
157  /* MODIS Level 1A Data Product Format) */
158  /* INPUTS: L1A_file_ptr, SC_PIXEL_QUALITY_DATA_t, scan_num */
159  /* OUTPUTS: None */
160  /* RETURN: temp_status */
161  /* */
162  /* IF temp_status is not equal to MODIS_S_SUCCESS */
163  /* THEN */
164  /* set msg to "The Pixel Quality Data could not be written to the L1A granule */
165  /* for scan number (number)" */
166  /* CALL log_fmt_msg to report that the Pixel Quality Data could not */
167  /* be written to the L1A file */
168  /* INPUTS: temp_status, routine, msg */
169  /* OUTPUT: None */
170  /* RETURN: None */
171  /* set returnStatus to MODIS_E_WRITE_SCAN_FAIL */
172  /* ENDIF */
173  /* */
174  /**********************************************************************************/
175 
176  temp_status = write_pix_qual(L1A_file_ptr, pix_qual, scan_num);
177 
178  if (temp_status != MODIS_S_SUCCESS)
179  {
180  sprintf(msg,"The Pixel Quality Data could not be written to the L1A granule: %s scan number %d",
181  L1A_file_ptr->filename, scan_num);
183  returnStatus = MODIS_E_WRITE_SCAN_FAIL;
184  }
185 
186 
187  /**********************************************************************************/
188  /* */
189  /* CALL write_scan_data to write out the Scan Data (section 4 of the */
190  /* MODIS Level 1A Data Product Format) */
191  /* INPUTS: L1A_file_ptr, SC_SCAN_DATA_t, scan_num */
192  /* OUTPUTS: None */
193  /* RETURN: temp_status */
194  /* */
195  /* IF temp_status is not equal to MODIS_S_SUCCESS */
196  /* THEN */
197  /* set msg to "The Scan Data could not be written to the L1A granule for */
198  /* scan number (number)" */
199  /* CALL log_fmt_msg to report that the Scan Data could not be written to the */
200  /* L1A file */
201  /* INPUTS: temp_status, routine, msg */
202  /* OUTPUT: None */
203  /* RETURN: None */
204  /* set returnStatus to MODIS_E_WRITE_SCAN_FAIL */
205  /* ENDIF */
206  /* */
207  /**********************************************************************************/
208 
209  temp_status = write_scan_data(L1A_file_ptr, L1A_scan, scan_num, scan_meta->scan_type);
210 
211  if (temp_status != MODIS_S_SUCCESS)
212  {
213  sprintf(msg,"The Scan Data could not be written to the L1A granule: %s scan number: %d",
214  L1A_file_ptr->filename, scan_num);
216  returnStatus = MODIS_E_WRITE_SCAN_FAIL;
217  }
218 
219  /**********************************************************************************/
220  /* */
221  /* CALL write_failed_packets to write out the Discarded Packets (section 5 of the */
222  /* MODIS Level 1A Data Product Format) */
223  /* INPUTS: L1A_file_ptr, failed_pkts */
224  /* OUTPUTS: None */
225  /* RETURN: temp_status */
226  /* */
227  /**********************************************************************************/
228 
229  temp_status = write_failed_packets(failed_pkts);
230 
231  /**********************************************************************************/
232  /* */
233  /* IF temp_status is not equal to MODIS_S_SUCCESS */
234  /* THEN */
235  /* set msg to "The Discarded Packets could not be written to the L1A granule */
236  /* for scan number (number)" */
237  /* CALL log_fmt_msg to report that the Discarded Packets could not be written */
238  /* to the L1A file */
239  /* INPUTS: temp_status, routine, msg */
240  /* OUTPUT: None */
241  /* RETURN: None */
242  /* set returnStatus to MODIS_E_WRITE_SCAN_FAIL */
243  /* ENDIF */
244  /* */
245  /**********************************************************************************/
246 
247  if (temp_status != MODIS_S_SUCCESS)
248  {
249  sprintf(msg,"The Discarded Packets could not be written to the L1A granule: %s scan number: %d",
250  L1A_file_ptr->filename, scan_num);
252  returnStatus = MODIS_E_WRITE_SCAN_FAIL;
253  }
254 
255 
256  /**********************************************************************************/
257  /* */
258  /* CALL write_eng_data to write out the Engineering Data (section 6 of the MODIS */
259  /* Level 1A Data Product Format) */
260  /* INPUTS: L1A_file_ptr, eng_data */
261  /* OUTPUTS: None */
262  /* RETURN: temp_status */
263  /* */
264  /* IF temp_status is not equal to MODIS_S_SUCCESS */
265  /* THEN */
266  /* set routine to "write_scan" */
267  /* set msg to "The Engineering Data could not be written to the L1A granule */
268  /* for scan number (number)" */
269  /* CALL log_fmt_msg to report that the Engineering Data could not be written */
270  /* to the L1A file */
271  /* INPUTS: temp_status, routine, msg */
272  /* OUTPUT: None */
273  /* RETURN: None */
274  /* set returnStatus to temp_status */
275  /* ENDIF */
276  /* */
277  /**********************************************************************************/
278 
279  temp_status = write_eng_data(eng_data);
280 
281  if (temp_status != MODIS_S_SUCCESS)
282  {
283  sprintf(msg,"The Engineering Data could not be written to the L1A granule: %s scan number %d",
284  L1A_file_ptr->filename, scan_num);
286  returnStatus = temp_status;
287  }
288 
289 
290  /**********************************************************************************/
291  /* */
292  /* return returnStatus */
293  /* */
294  /**********************************************************************************/
295 
296  return (returnStatus);
297 }
298 
299 
300 
301 
302 
PGSt_SMF_status write_scan(MODFILE *L1A_file_ptr, SC_SCAN_DATA_t *L1A_scan, MD_SCAN_MET_t *scan_meta, SC_PIXEL_QUALITY_DATA_t *pix_qual, FP_QUEUE_t failed_pkts, EN_VDATA_TYPE_t *eng_data)
Definition: write_scan.c:12
PGSt_SMF_status write_failed_packets(FP_QUEUE_t failed_pkts)
PGSt_SMF_status write_eng_data(EN_VDATA_TYPE_t *eng_data)
PGSt_SMF_status write_scan_data(MODFILE *L1A_file_ptr, SC_SCAN_DATA_t *L1A_scan, int16 scan_num, char *scan_type)
PGSt_SMF_status write_scan_metadata(MODFILE *L1A_file_ptr, MD_SCAN_MET_t *scan_meta)
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define MODIS_E_ARRAY_OUTPUT_ERR
#define MODIS_E_WRITE_SCAN_FAIL
#define MODIS_F_WRITE_ENG_DATA_FAIL
#define MODIS_S_SUCCESS
string msg
Definition: mapgen.py:227
PGSt_SMF_status write_pix_qual(MODFILE *L1A_file_ptr, SC_PIXEL_QUALITY_DATA_t *pix_qual, int16 scan_num)
char scan_type[10]
Definition: MD_metadata.h:220