OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
init_L1A_scan_data_HDF_sdss.c
Go to the documentation of this file.
1 #include "L1A_prototype.h"
2 #include "hdf.h"
3 #include "mapi.h"
4 #include "mapiL1A.h"
5 #include "PGS_MODIS_35005.h"
6 #include "PGS_SMF.h"
7 #include "SC_scan.h"
8 #include "PD_pkt_data.h"
9 #include "PH_pkt_hdr.h"
10 
11 
12 PGSt_SMF_status init_L1A_scan_data_HDF_sdss (MODFILE *mfile,
13  int nscans)
14 
15 /*
16 !C***************************************************************************
17 
18 !Description: Function init_L1A_scan_data_HDF_sdss creates all the scan
19  SDSs (arrays) that will be written to by L1A processing.
20 
21 !Input Parameters:
22  mfile ** Pointer to MODFILE structure **
23  nscans ** Number of scans **
24 !Output Parameters:
25  None
26 
27 
28 Return Values:
29  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
30  MODIS_E_SDS_CREATE_FAILED (PGS_MODIS_35005.h)
31 
32 Externally Defined:
33  PGSt_SMF_status (PGS_SMF.h)
34  MO1SD_250M (mapiL1A.h)
35  MO1SD_500M (mapiL1A.h)
36  MO1SD_1KM_DA (mapiL1A.h)
37  MO1SD_1KM_NITE (mapiL1A.h)
38  MO1SRCA_250M (mapiL1A.h)
39  MO1SRCA_500M (mapiL1A.h)
40  MO1SRCA_1KM_DAY (mapiL1A.h)
41  MO1SRCA_1KM_NITE (mapiL1A.h)
42  M01BB_250M (mapiL1A.h)
43  M01BB_500M (mapiL1A.h)
44  M01BB_1KM_DAY (mapiL1A.h)
45  M01BB_1KM_NITE (mapiL1A.h)
46  M01SV_250M (mapiL1A.h)
47  M01SV_500M (mapiL1A.h)
48  M01SV_1KM_DA (mapiL1A.h)
49  M01SV_1KM_NITE (mapiL1A.h)
50  M01EV_250M (mapiL1A.h)
51  M01EV_500M (mapiL1A.h)
52  M01EV_1KM_DAY (mapiL1A.h)
53  M01EV_1KM_NITE (mapiL1A.h)
54  M01RAW_MIR_ENC (mapiL1A.h)
55  M01RAW_VS_DEF (mapiL1A.h)
56  M01RAW_VS_ACT (mapiL1A.h)
57  M01RAW_SC_ANCIL (mapiL1A.h)
58  M01FPA_AEM_CONFIG (mapiL1A.h)
59  M01SCIENCE_STATE (mapiL1A.h)
60  M01SCIENCE_ABNORMAL (mapiL1A.h)
61  M01FPA_DCR_OFFSET (mapiL1A.h)
62  M01RAW_SCI_ENG (mapiL1A.h)
63  M01RAW_HK_TELEM (mapiL1A.h)
64  M01RAW_PARAM (mapiL1A.h)
65  M01RAW_PV_GAINS (mapiL1A.h)
66  MFAIL (mapi.h)
67  MODFILE (mapi.h)
68  DATATYPELENMAX (mapi.h)
69  I16 (mapi.h)
70  I8 (mapi.h)
71  PH_MOD_SOURCE_ID_CAL_FRAME_CNT_MAX (PH_pkt_hdr.h)
72  PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_LIMIT (PH_pkt_hdr.h)
73  PH_MOD_FPA_AEM_CONFIG_NUM_ELEMENTS (PH_pkt_hdr.h)
74  SC_NUM_SCI_ENG_BYTES_IN_SDS (SC_scan.h)
75  PD_E1P1_NUM_FPA_DCR_OFFSETS (PD_pkt_data.h)
76  PD_E1P2_NUM_EARTH_ENCODER_TIMES (PD_pkt_data.h)
77  PD_E1P2_NUM_VIEW_SECTOR_DEFINITIONS (PD_pkt_data.h)
78  PD_E1P2_NUM_VIEW_SECTOR_ACTUALS (PD_pkt_data.h)
79  PD_E2P1_NUM_HK_TELEM_BYTES (PD_pkt_data.h)
80  PD_E2P1_NUM_SC_ANCIL_WORDS (PD_pkt_data.h)
81  PD_E2P1_NUM_PARAM_BYTES (PD_pkt_data.h)
82  PD_E2P2_NUM_PV_GAINS (PD_pkt_data.h)
83  PD_DN_NUM_250M_DETECTORS (PD_pkt_data.h)
84  PD_DN_NUM_250M_BANDS (PD_pkt_data.h)
85  PD_DN_BAND_RATIO_250M (PD_pkt_data.h)
86  PD_DN_NUM_500M_DETECTORS (PD_pkt_data.h)
87  PD_DN_NUM_500M_BANDS (PD_pkt_data.h)
88  PD_DN_BAND_RATIO_500M (PD_pkt_data.h)
89  PD_DN_NUM_1KMDAY_DETECTORS (PD_pkt_data.h)
90  PD_DN_NUM_1KMDAY_BANDS (PD_pkt_data.h)
91  PD_DN_BAND_RATIO_1KM (PD_pkt_data.h)
92  PD_DN_NUM_1KMNIGHT_DETECTORS (PD_pkt_data.h)
93  PD_DN_NUM_1KMNIGHT_BANDS (PD_pkt_data.h)
94 
95 
96 Called By:
97  init_L1A_HDF_sdss
98 
99 Routines Called:
100  log_fmt_msg
101  createMODISarray
102  putMODISarinfo
103 
104 !Revision History:
105 $Log: init_L1A_scan_data_HDF_sdss.c,v $
106 Revision 5.1 2004/09/23 18:41:06 seaton
107 Collection 5 changes.
108 Added code to set a _FillValue attribute for all SDSs in the output product.
109 seaton@saicmodis.com
110 
111 
112  Revision 3.0 2001/04/13
113  John Seaton SAIC/GSC
114  Set raw_mir_enc to type UI16
115 
116  Revision 1.1 1999/10/18 12:03:00
117  John Seaton/GSC (seaton@ltpmail.gsfc.nasa.gov)
118  Modified to initialize in a loop and to set the fill value for
119  some SDSs to -1 as specified in the L1A filespec.
120 
121  Revision 1.0 1997/09/09 17:30:00
122  Qi Huang/RDC (qhuang@ltpmail.gsfc.nasa.gov)
123  Original development
124 
125 !Team-unique Header:
126  This software is developed by the MODIS Science Data Support
127  Team (SDST) for the National Aeronautics and Space Administration
128  (NASA), Goddard Space Flight Center (GSFC), under contract
129  NAS5-32373.
130 
131 !References and Credits:
132  None
133 
134 !Design Notes:
135  None
136 
137 !END***************************************************************************
138 */
139 
140 #define SDS_SECTOR_DATA_INDEX 20
141 #define NUM_SDSS 32
142 
143 {
144 /******************************************************************************/
145 /* Define and Initialize Local Variables */
146 /******************************************************************************/
147 
148  char *routine = "init_L1A_HDF_scan_data_sdss";
149  char msg[300];
150  PGSt_SMF_status returnStatus;
151  int i;
152 
153 /******************************************************************************/
154 /* Initialize sds structure storing sds names, datatype, rank and dimensions */
155 /* for all Scan data as specified in Section 4 of the L1A filespec. The first */
156 /* index of the dimension member is initially set to zero. It is initialized */
157 /* to the correct value later in thie routine. It cannot be initialized here */
158 /* because the number of scans is needed to compute that size, and nscans is */
159 /* not a constant, therefore, it cannot be used in the initialization of these*/
160 /* SDSs here. */
161 /******************************************************************************/
162 
163  struct {
164  char *sds_name;
165  char datatype[DATATYPELENMAX];
166  long int rank;
167  long int dimensions[3];
168  } sds_info[] = {
189  {M01FPA_AEM_CONFIG, I8, 2, {0, PH_MOD_FPA_AEM_CONFIG_NUM_ELEMENTS, 0}},
190  {M01SCIENCE_STATE, I8, 1, {0, 0, 0}},
191  {M01SCIENCE_ABNORM, I8, 1, {0, 0, 0}},
192  {M01FPA_DCR_OFFSET, I8, 2, {0, PD_E1P1_NUM_FPA_DCR_OFFSETS, 0}},
193  {M01RAW_MIR_ENC, I16, 2, {0, PD_E1P2_NUM_EARTH_ENCODER_TIMES, 0}},
194  {M01RAW_VS_DEF, I16, 2, {0, PD_E1P2_NUM_VIEW_SECTOR_DEFINITIONS, 0}},
195  {M01RAW_VS_ACT, I16, 2, {0, PD_E1P2_NUM_VIEW_SECTOR_ACTUALS, 0}},
196  {M01RAW_SCI_ENG, I8, 2, {0, SC_NUM_SCI_ENG_BYTES_IN_SDS, 0}},
197  {M01RAW_HK_TELEM, I8, 2, {0, PD_E2P1_NUM_HK_TELEM_BYTES, 0}},
198  {M01RAW_SC_ANCIL, I16, 2, {0, PD_E2P1_NUM_SC_ANCIL_WORDS, 0}},
199  {M01RAW_PARAM, I8, 2, {0, PD_E2P1_NUM_PARAM_BYTES, 0}},
200  {M01RAW_PV_GAINS, I8, 2, {0, PD_E2P2_NUM_PV_GAINS, 0}}
201  };
202 
203 /******************************************************************************/
204 /* Set the fill value variable to -1 for future calls to API routines */
205 /******************************************************************************/
206 
207  int16 fill16[1] = {-1};
208  int8 fill8[1] = {-1};
209 
210 /******************************************************************************/
211 /* Set the first dimension for the SDSs as they could not be initialized due */
212 /* to the fact that the nscans variable is not a constant. */
213 /******************************************************************************/
214 
215  sds_info[0].dimensions[0] = nscans * PD_DN_NUM_250M_DETECTORS;
216  sds_info[1].dimensions[0] = nscans * PD_DN_NUM_500M_DETECTORS;
217  sds_info[2].dimensions[0] = nscans * PD_DN_NUM_1KMDAY_DETECTORS;
218  sds_info[3].dimensions[0] = nscans * PD_DN_NUM_1KMNIGHT_DETECTORS;
219  sds_info[4].dimensions[0] = nscans * PD_DN_NUM_250M_DETECTORS;
220  sds_info[5].dimensions[0] = nscans * PD_DN_NUM_500M_DETECTORS;
221  sds_info[6].dimensions[0] = nscans * PD_DN_NUM_1KMDAY_DETECTORS;
222  sds_info[7].dimensions[0] = nscans * PD_DN_NUM_1KMNIGHT_DETECTORS;
223  sds_info[8].dimensions[0] = nscans * PD_DN_NUM_250M_DETECTORS;
224  sds_info[9].dimensions[0] = nscans * PD_DN_NUM_500M_DETECTORS;
225  sds_info[10].dimensions[0] = nscans * PD_DN_NUM_1KMDAY_DETECTORS;
226  sds_info[11].dimensions[0] = nscans * PD_DN_NUM_1KMNIGHT_DETECTORS;
227  sds_info[12].dimensions[0] = nscans * PD_DN_NUM_250M_DETECTORS;
228  sds_info[13].dimensions[0] = nscans * PD_DN_NUM_500M_DETECTORS;
229  sds_info[14].dimensions[0] = nscans * PD_DN_NUM_1KMDAY_DETECTORS;
230  sds_info[15].dimensions[0] = nscans * PD_DN_NUM_1KMNIGHT_DETECTORS;
231  sds_info[16].dimensions[0] = nscans * PD_DN_NUM_250M_DETECTORS;
232  sds_info[17].dimensions[0] = nscans * PD_DN_NUM_500M_DETECTORS;
233  sds_info[18].dimensions[0] = nscans * PD_DN_NUM_1KMDAY_DETECTORS;
234  sds_info[19].dimensions[0] = nscans * PD_DN_NUM_1KMNIGHT_DETECTORS;
235  sds_info[20].dimensions[0] = nscans;
236  sds_info[21].dimensions[0] = nscans;
237  sds_info[22].dimensions[0] = nscans;
238  sds_info[23].dimensions[0] = nscans;
239  sds_info[24].dimensions[0] = nscans;
240  sds_info[25].dimensions[0] = nscans;
241  sds_info[26].dimensions[0] = nscans;
242  sds_info[27].dimensions[0] = nscans;
243  sds_info[28].dimensions[0] = nscans;
244  sds_info[29].dimensions[0] = nscans;
245  sds_info[30].dimensions[0] = nscans;
246  sds_info[31].dimensions[0] = nscans;
247 
248 
249  returnStatus = MODIS_S_SUCCESS;
250 
251 /******************************************************************************/
252 /* Loop through the above defined structure, creating the SDSs. */
253 /******************************************************************************/
254 
255  for (i=0; i < NUM_SDSS; i++) {
256 
257 /******************************************************************************/
258 /* call createMODISarray for each SDS defined above. If return from */
259 /* createMODISarrray fails, then print LogStatus message stating that the */
260 /* named SDS could not be created and set returnStatus to */
261 /* MODIS_E_SDS_CREATE_FAILED. */
262 /******************************************************************************/
263 
264  if ( createMODISarray(mfile, sds_info[i].sds_name,
265  NULL,
266  sds_info[i].datatype,
267  sds_info[i].rank,
268  sds_info[i].dimensions) != MAPIOK) {
269  returnStatus = MODIS_E_SDS_CREATE_FAILED;
270  sprintf(msg, "SDS Name: %s", sds_info[i].sds_name);
272  }
273 
274 
275 /******************************************************************************/
276 /* Then call putMODISarinfo to set its fill value to -1. If this call fails */
277 /* then print an appropriate error message in the LogStatus file and set the */
278 /* returnStatus to MODIS_E_SDS_CREATE_FAILED. */
279 /******************************************************************************/
280 
281  if (strncmp(sds_info[i].datatype, I16, sizeof(I16)) == 0) {
282  if (putMODISarinfo(mfile, sds_info[i].sds_name,
283  NULL, MFILL_VALUE,
284  sds_info[i].datatype, 1, &fill16) != MAPIOK) {
285  returnStatus = MODIS_E_SDS_CREATE_FAILED;
286  sprintf(msg, "Could not initialize SDS to -1 for SDS Name: %s", sds_info[i].sds_name);
288  }
289 
290  } /* end if i = I16 */
291  else {
292  if (putMODISarinfo(mfile, sds_info[i].sds_name,
293  NULL, MFILL_VALUE,
294  sds_info[i].datatype, 1, &fill8) != MAPIOK) {
295  returnStatus = MODIS_E_SDS_CREATE_FAILED;
296  sprintf(msg, "Could not initialize SDS to -1 for SDS Name: %s", sds_info[i].sds_name);
298  }
299 
300  } /* end else */
301 
302  } /* end for */
303 
304  /****************************************************************************/
305  /* RETURN returnStatus */
306  /****************************************************************************/
307 
308  return (returnStatus);
309 }
#define PD_DN_NUM_500M_BANDS
Definition: PD_pkt_data.h:97
integer, parameter int16
Definition: cubeio.f90:3
#define PD_DN_NUM_1KMDAY_BANDS
Definition: PD_pkt_data.h:106
#define PD_DN_NUM_250M_BANDS
Definition: PD_pkt_data.h:90
#define NULL
Definition: decode_rs.h:63
#define PD_DN_BAND_RATIO_500M
Definition: PD_pkt_data.h:96
#define PD_E2P1_NUM_SC_ANCIL_WORDS
Definition: PD_pkt_data.h:152
#define PD_DN_NUM_250M_DETECTORS
Definition: PD_pkt_data.h:91
#define PD_E1P1_NUM_FPA_DCR_OFFSETS
Definition: PD_pkt_data.h:125
#define PD_DN_NUM_500M_DETECTORS
Definition: PD_pkt_data.h:98
#define PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_LIMIT
Definition: PH_pkt_hdr.h:195
#define PD_DN_NUM_1KMNIGHT_DETECTORS
Definition: PD_pkt_data.h:109
#define PD_E2P1_NUM_PARAM_BYTES
Definition: PD_pkt_data.h:154
#define PD_DN_NUM_1KMNIGHT_BANDS
Definition: PD_pkt_data.h:108
#define PH_MOD_SOURCE_ID_CAL_FRAME_CNT_MAX
Definition: PH_pkt_hdr.h:216
#define MODIS_E_SDS_CREATE_FAILED
#define SC_NUM_SCI_ENG_BYTES_IN_SDS
Definition: SC_scan.h:146
#define PD_E1P2_NUM_VIEW_SECTOR_DEFINITIONS
Definition: PD_pkt_data.h:136
#define PD_E1P2_NUM_EARTH_ENCODER_TIMES
Definition: PD_pkt_data.h:134
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define PD_DN_NUM_1KMDAY_DETECTORS
Definition: PD_pkt_data.h:107
#define PD_DN_BAND_RATIO_250M
Definition: PD_pkt_data.h:89
PGSt_SMF_status init_L1A_scan_data_HDF_sdss(MODFILE *mfile, int nscans)
#define PD_E1P2_NUM_VIEW_SECTOR_ACTUALS
Definition: PD_pkt_data.h:138
#define MODIS_S_SUCCESS
Extra metadata that will be written to the HDF4 file l2prod rank
#define PD_E2P2_NUM_PV_GAINS
Definition: PD_pkt_data.h:163
#define PD_E2P1_NUM_HK_TELEM_BYTES
Definition: PD_pkt_data.h:149
#define PH_MOD_FPA_AEM_CONFIG_NUM_ELEMENTS
Definition: PH_pkt_hdr.h:221
string msg
Definition: mapgen.py:227
#define PD_DN_BAND_RATIO_1KM
Definition: PD_pkt_data.h:105
int i
Definition: decode_rs.h:71
#define NUM_SDSS