OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
create_L1A_granule.c
Go to the documentation of this file.
1 #include "L1A_prototype.h"
2 #include "hdf.h"
3 #include "PGS_MODIS_35005.h"
4 #include "EN_eng_data.h"
5 #include "PC_pcf_info.h"
6 #include "mapi.h"
7 #include "PGS_PC.h"
8 #include "PGS_SMF.h"
9 
10 PGSt_SMF_status create_L1A_granule (EN_VDATA_TYPE_t *eng_data,
11  int16 nscans,
12  MODFILE **L1A_file_ptr)
13 /*
14 !C*****************************************************************************
15 
16 !Description: Function create_L1A_granule opens an L1A file for output, and
17  initializes all SDSs and Vdata structures for writing.
18 
19 !Input Parameters:
20  EN_VDATA_TYPE_t eng_data ** Engineering data **
21  int16 nscans ** Number of scans in a granule **
22 
23 !Output Parameters:
24  MODFILE **L1A_file_ptr ** Address of L1A file pointer **
25 
26 Returns Values:
27  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
28  MODIS_E_CREATE_L1A_GRANULE (PGS_MODIS_35005.h)
29 
30 Externally Defined:
31  MODFILE (mapi.h)
32  PC_L1A_PROD_PCF_ID (PC_pcf_info.h)
33 
34 Called By:
35  process_a_granule
36 
37 Routines Called:
38  PGS_SMF_TestSuccessLevel (PGS_SMF.h)
39  log_fmt_msg
40  PGS_PC_GetReference (PGS_PC.h)
41  openMODISfile (mapi.h)
42  init_L1A_HDF_vdatas
43  init_L1A_HDF_sdss
44 
45 !Revision History:
46  revision 1.0 1997/08/25 17:30:00
47  Qi Huang/RDC (qhuang@ltpmail.gsfc.nasa.gov)
48  Original development
49 
50 !Team-unique Header:
51  This software is developed by the MODIS Science Data Support Team
52  Team (SDST) for the National Aeronautics and Space Administration
53  (NASA), Goddard Space Flight Center (GSFC), under contract
54  NAS5-32373.
55 
56 !References and Credits:
57  None
58 
59 !Design Notes:
60  None
61 
62 !END*************************************************************************
63 */
64 {
65  /*************************************************************************/
66  /* */
67  /* Define and Initialize Local Variables */
68  /* */
69  /*************************************************************************/
70 
71  char *routine = "create_L1A_granule";
72  char msg[300];
73  PGSt_SMF_status returnStatus;
74  PGSt_SMF_status PGS_status;
75  PGSt_integer L1A_version_num;
76  static PGSt_integer version = 0;
77  char L1A_filename[256];
78 
79  /*************************************************************************/
80  /* */
81  /* Set routine to "create_L1A_granule" */
82  /* */
83  /* Set returnStatus to MODIS_S_SUCCESS */
84  /* */
85  /*************************************************************************/
86 
87  returnStatus = MODIS_S_SUCCESS;
88 
89 
90  /*************************************************************************/
91  /* */
92  /* CALL PGS_PC_GetReference to retrieve the L1A file name */
93  /* INPUT: L1A_PROD_PCF_ID, L1A_version_num */
94  /* OUTPUT: L1A_filename, L1A_version_num */
95  /* RETURN: PGS_status */
96  /* */
97  /*************************************************************************/
98 
99  version ++;
100  L1A_version_num = version;
101  PGS_status = PGS_PC_GetReference(PC_L1A_PROD_PCF_ID, &L1A_version_num,
102  L1A_filename);
103 
104 
105  /***************************************************************************/
106  /* */
107  /* CALL PGS_SMF_TestSuccessLevel to determine if the retrieve is */
108  /* successful */
109  /* INPUT: PGS_status */
110  /* ONTPUT: None */
111  /* RETURN: TestStatus */
112  /* */
113  /* IF TestStatus is not equal to PGS_TRUE */
114  /* THEN */
115  /* Set returnStatus to MODIS_E_CREATE_L1A_GRANULE */
116  /* Set msg to "The L1A_filename could not be retrieved from the PCF */
117  /* file" */
118  /* CALL log_fmt_msg to report that the L1A_filename was not retrieved */
119  /* INPUT: PGS_status, routine, msg */
120  /* OUTPUT: None */
121  /* RETURN: None */
122  /* ELSE */
123  /* */
124  /* Set access_mode to "w" (write only) */
125  /* CALL openMODISfile to open the L1A file */
126  /* INPUT: filename, access_mode */
127  /* OUPUT: None */
128  /* RETURN: L1A_file_ptr */
129  /* */
130  /* IF L1A_file_ptr is equal to NULL */
131  /* THEN */
132  /* Set returnStatus to MODIS_E_CREATE_L1A_GRANULE */
133  /* Set msg to "The L1A granule could not be opened for granule */
134  /* (L1A_filename)" */
135  /* CALL log_fmt_msg to report that the opening L1A file failed */
136  /* INPUT: routine, msg, filename */
137  /* OUTPUT: None */
138  /* RETURN: None */
139  /* ELSE */
140  /* */
141  /* CALL init_L1A_HDF_vdatas to initialize the HDF vdatas in the */
142  /* L1A file */
143  /* INPUT: L1A_file_ptr, eng_data */
144  /* OUTPUT: None */
145  /* RETURN: PGS_status */
146  /* */
147  /* IF L1A_status is not equal to MODIS_S_SUCCESS */
148  /* THEN */
149  /* Set returnStatus to MODIS_E_CREATE_L1A_GRANULE */
150  /* Set msg to "The L1A HDF vdatas could not be created for */
151  /* granule (L1A_filename)" */
152  /* CALL log_fmt_msg to report that the initializing L1A HDF */
153  /* vdatas failed */
154  /* INPUT: L1A_status, routine, msg */
155  /* OUTPUT: None */
156  /* RETURN: None */
157  /* */
158  /* CALL completeMODISfile to close the L1A granule */
159  /* INPUT: L1A_file_ptr, NULL, NULL, 0 */
160  /* OUTPUT: None */
161  /* RETURN: mapi_status */
162  /* */
163  /* IF mapi_status is MFAIL */
164  /* THEN */
165  /* Set returnStatus to MODIS_E_CREATE_L1A_GRANULE */
166  /* Set msg to "The L1A granule could not be closed properly" */
167  /* CALL log_fmt_msg to report that closing the L1A file */
168  /* was not successful */
169  /* INPUT: returnStatus, routine, msg */
170  /* OUTPUT: None */
171  /* RETURN: None */
172  /* ENDIF */
173  /* ELSE */
174  /* */
175  /* CALL init_L1A_HDF_sdss to initialize the HDF sdss in the */
176  /* L1A file */
177  /* INPUT: L1A_file_ptr, nscans */
178  /* OUTPUT: None */
179  /* RETURN: PGS_status */
180  /* */
181  /* IF L1A_status is not equal to MODIS_S_SUCCESS */
182  /* THEN */
183  /* Set returnStatus to MODIS_E_CREATE_L1A_GRANULE */
184  /* Set msg to "The L1A HDF sdss could not be created for */
185  /* granule (L1A_filename)" */
186  /* CALL log_fmt_msg to report that the initializing L1A */
187  /* HDF sdss failed */
188  /* INPUT: L1A_status, routine, msg */
189  /* OUTPUT: None */
190  /* RETURN: None */
191  /* */
192  /* CALL completeMODISfile to close the L1A granule */
193  /* INPUT: L1A_file_ptr, NULL, NULL, 0 */
194  /* OUTPUT: None */
195  /* RETURN: mapi_status */
196  /* */
197  /* IF mapi_status is MFAIL */
198  /* THEN */
199  /* Set returnStatus to MODIS_E_CREATE_L1A_GRANULE */
200  /* Set msg to "The L1A granule could not be closed */
201  /* properly" */
202  /* CALL log_fmt_msg to report that closing the L1A file */
203  /* was not successful */
204  /* INPUT: returnStatus, routine, msg */
205  /* OUTPUT: None */
206  /* RETURN: None */
207  /* ENDIF */
208  /* ENDIF */
209  /* ENDIF */
210  /* ENDIF */
211  /* ENDIF */
212  /* */
213  /***************************************************************************/
214 
215  if (PGS_SMF_TestSuccessLevel(PGS_status) != PGS_TRUE)
216  {
217  returnStatus = MODIS_E_CREATE_L1A_GRANULE;
219  "The L1A filename could not be retrieved from the PCF file");
220  }
221 
222  else
223  {
224  *L1A_file_ptr = openMODISfile(L1A_filename,"w");
225  if (*L1A_file_ptr == NULL)
226  {
227  returnStatus = MODIS_E_CREATE_L1A_GRANULE;
228  sprintf(msg,"The L1A filename %s could not be opened", L1A_filename);
230  }
231  else
232  {
233  if ((PGS_status = init_L1A_HDF_vdatas(eng_data, *L1A_file_ptr))
234  != MODIS_S_SUCCESS)
235  {
236  returnStatus = MODIS_E_CREATE_L1A_GRANULE;
237  sprintf(msg,"The L1A HDF vdatas could not be created for file: %s",
238  L1A_filename);
240  if (completeMODISfile(L1A_file_ptr, NULL, NULL,
241  0) == MFAIL)
242  {
243  returnStatus = MODIS_E_CREATE_L1A_GRANULE;
244  sprintf(msg,"The L1A file: %s could not be closed properly",
245  L1A_filename);
247  }
248  }
249  else
250  {
251  if ((PGS_status = init_L1A_HDF_sdss(*L1A_file_ptr, nscans))
252  != MODIS_S_SUCCESS)
253  {
254  returnStatus = MODIS_E_CREATE_L1A_GRANULE;
255  sprintf(msg,"The L1A HDF sdss could not be created for file: %s",
256  L1A_filename);
258  if (completeMODISfile(L1A_file_ptr, NULL, NULL,
259  0) == MFAIL)
260  {
261  returnStatus = MODIS_E_CREATE_L1A_GRANULE;
262  sprintf(msg,"The L1A file: %s could not be closed properly",
263  L1A_filename);
265  }
266  }
267  }
268  }
269  }
270 
271  /************************/
272  /* RETURN returnStatus */
273  /************************/
274  return (returnStatus);
275 }
integer, parameter int16
Definition: cubeio.f90:3
PGSt_SMF_status create_L1A_granule(EN_VDATA_TYPE_t *eng_data, int16 nscans, MODFILE **L1A_file_ptr)
#define MODIS_E_CREATE_L1A_GRANULE
#define NULL
Definition: decode_rs.h:63
PGSt_SMF_status init_L1A_HDF_vdatas(EN_VDATA_TYPE_t *eng_data, MODFILE *L1A_file)
#define PC_L1A_PROD_PCF_ID
Definition: PC_pcf_info.h:67
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
PGSt_SMF_status init_L1A_HDF_sdss(MODFILE *L1A_file_ptr, int16 nscans)
#define MODIS_S_SUCCESS
string msg
Definition: mapgen.py:227
version
Definition: setup.py:15