OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_create_swath.c
Go to the documentation of this file.
1 #include "PGS_MODIS_35251.h"
2 #include "GEO_output.h"
3 #include "GEO_product.h"
4 #include "HdfEosDef.h"
5 #include "GEO_geo.h"
6 #include "smfio.h"
7 
8 PGSt_SMF_status GEO_create_swath(
9  int const number_of_scans,
10  int const num_detectors,
11  int32 const swfid
12 )
13 
14 /*
15 ***********************************************************************
16 !C
17 !Description:
18  Routine in Output group of the Level-1A geolocation software to
19  initialize the HDF-EOS objects in the output product for subsequent
20  scan-by-scan output. It calls HDF-EOS routines to initialize the
21  geolocation metadata.
22 
23 !Input Parameters:
24  number_of_scans the number of scans.
25  num_detectors the number of detectors per sample.
26  swfid swath file id.
27 
28 !Output Parameters:
29  None
30 
31 Return Values:
32  MODIS_E_BAD_INPUT_ARG If any input parameter is invalid
33  MODIS_E_GEO If any subroutine fails
34  PGS_S_SUCCESS Otherwise
35 
36 
37 Externally Defined:
38  DETECTORS_1KM "GEO_geo.h"
39  DFNT_FLOAT32 "hdf.h"
40  DFNT_INT16 "hdf.h"
41  DFNT_UINT16 "hdf.h"
42  DFNT_UINT8 "hdf.h"
43  FAIL "hdf.h"
44  GFLAGS "GEO_product.h"
45  HDFE_NOMERGE "HdfEosDef.h"
46  HEIGHT "GEO_product.h"
47  HEIGHT_OFFSET "GEO_product.h"
48  LAND_SEAMASK "GEO_product.h"
49  LATITUDE "GEO_product.h"
50  LONGITUDE "GEO_product.h"
51  MAX_FRAMES "GEO_geo.h"
52  MFRAMES "GEO_product.h"
53  MFRAMES_2 "GEO_product.h"
54  MFRAMES_4 "GEO_product.h"
55  MODIS_E_BAD_INPUT_ARG "PGS_MODIS_35251.h"
56  MODIS_E_GEO "PGS_MODIS_35251.h"
57  NSCANS "GEO_product.h"
58  NSCANS_10 "GEO_product.h"
59  NSCANS_20 "GEO_product.h"
60  NSCANS_40 "GEO_product.h"
61  PGS_S_SUCCESS "PGS_SMF.h"
62  RANGE "GEO_product.h"
63  SCAN_OFFSET "GEO_product.h"
64  SEN_ZENITH "GEO_product.h"
65  SEN_AZIMUTH "GEO_product.h"
66  SOL_ZENITH "GEO_product.h"
67  SOL_AZIMUTH "GEO_product.h"
68  SUCCEED "hdf.h"
69  SWATH_NAME "GEO_product.h"
70  TRACK_OFFSET "GEO_product.h"
71  WATER_PRESENT "GEO_product.h"
72 
73 Called by:
74  GEO_initialize_product "GEO_output.h"
75 
76 Routines Called:
77  modsmf "smfio.h"
78  SWcreate "HdfEosDef.h"
79  SWdefdatafield "HdfEosDef.h"
80  SWdefdim "HdfEosDef.h"
81  SWdefdimmap "HdfEosDef.h"
82  SWdefgeofield "HdfEosDef.h"
83  SWdetach "HdfEosDef.h"
84 
85 !Revision History:
86  * $Log: GEO_create_swath.c,v $
87  * Revision 6.9 2011/02/11 21:20:34 kuyper
88  * Added WaterPresent SDS.
89  *
90  * Revision 6.8 2010/06/23 17:55:37 kuyper
91  * Removed attitude and ephemeris quality flags from swath.
92  *
93  * Revision 6.7 2010/06/18 20:46:40 kuyper
94  * Corrected formation of message about SWdefdimmap() failure.
95  *
96  * Revision 6.6 2010/05/17 18:01:07 kuyper
97  * Helped resolve Bug 2472 by adding attitude and ephemeris quality as
98  * datafields.
99  *
100  * James Kuyper Jr. James.R.Kuyper@NASA.gov
101  *
102  * Revision 6.5 2009/06/12 18:51:34 kuyper
103  * Corrected the comparison used to determine whether dimension maps need to
104  * be created.
105  *
106  * Revision 6.4 2009/05/31 21:06:42 kuyper
107  * Corrected handling of the dimension list for the offsets Datafields.
108  * Corrected setting of the 1km scan dimension.
109  *
110  * Revision 6.3 2009/05/31 01:47:12 ltan
111  * Minor corrections.
112  *
113  * Revision 6.2 2009/05/31 01:28:36 ltan
114  * Minor corrections.
115  *
116  * Revision 6.1 2009/05/29 15:44:41 ltan
117  * Changed to match code by specifying use of macros for swath, dimension, and field names.
118  * Changed length of MFRAMES dimension to MAX_FRAMES, and NSCANS_10 dimension to DETECTORS_1KM.
119  * Added high resolution offsets, corresponding dimensions, and corresponding dimension maps.
120  * Clarified where default zero-initialization is being relied upon.
121  *
122  * Revision 4.1 2003/02/21 20:25:16 kuyper
123  * Simplified confusion notation used for dimlist fields.
124  *
125  * Revision 3.1 2002/06/13 22:47:26 kuyper
126  * Removed unnecessary NCSA acknowledgment.
127  *
128  * Revision 2.4 1999/02/02 18:03:23 kuyper
129  * Make an implicit conversion explicit.
130  *
131  * Revision 2.3 1998/02/08 22:20:07 jjb
132  * Merged from V2.0 DAAC delivery.
133  *
134  1997/12/20 Liqun Ma
135  Added NCSA acknowledgement
136 
137  * Revision 2.2 1997/10/24 13:13:59 kuyper
138  * Included header file which declares GEO_create_swath().
139  *
140  * Revision 2.1 1997/10/21 18:16:22 kuyper
141  * Returned from ClearCase
142  *
143  * Revision GEO_create_swath.c@@/main/GEO_V2_DEV/1
144  * "version 2 development"
145  *
146 # Revision 2.1 1997/07/07 18:36:25 fshaw
147 # made changes reported by 7/3/97 W/T
148 #
149 # Revision 2.0 1997/07/07 17:06:09 fshaw
150 # Initial version
151 #
152 !Requirements:
153  PR03-I-4
154 
155 !Team-unique Header:
156  This software is developed by the MODIS Science Data Support
157  Team for the National Aeronautics and Space Administration,
158  Goddard Space Flight Center, under contract NAS5-32373.
159 !END
160 *************************************************************************
161 */
162 {
163  /* Declare local variables */
164 
165  int32 swathID;
166  PGSt_SMF_status return_status = PGS_S_SUCCESS;
167  int32 dim, fld;
168  uint16 N_samp = num_detectors/DETECTORS_1KM;
169  int32 dimensions =4;
170  int32 startfield = 0;
171  char msgbuf[256];
172 
173  static struct{
174  char *fieldname;
175  int32 dim;
176  int32 offset;
177  int32 increment;
178  }Swath_Dimname[] =
179  {
180  {NSCANS_10, 0, 0, 0},
181  {MFRAMES, MAX_FRAMES, 0, 0},
182  {NULL,0,0,0},
183  {NULL,0,0,0},
184  };
185 
186  static struct{
187  char *fieldname;
188  char *dimlist;
189  int32 datatype;
190  }Swath_Geofields[] =
193  };
194 
195  static char offsets_dimlist[] = NSCANS_20","MFRAMES_2;
196  static struct{
197  char *fieldname;
198  char *dimlist;
199  int32 datatype;
200  }Swath_Datafields[] =
201  { {SCAN_OFFSET, offsets_dimlist, DFNT_INT8},
202  {TRACK_OFFSET, offsets_dimlist, DFNT_INT8},
203  {HEIGHT_OFFSET, offsets_dimlist, DFNT_INT8},
207  {RANGE, NSCANS_10 "," MFRAMES, DFNT_UINT16},
210  {LAND_SEAMASK, NSCANS_10 "," MFRAMES, DFNT_UINT8},
211  {WATER_PRESENT, NSCANS_10 "," MFRAMES, DFNT_UINT8},
212  {GFLAGS, NSCANS_10 "," MFRAMES, DFNT_UINT8},
213  };
214 
215  char filefunc[] = __FILE__ ",GEO_create_swath";
216 
217  if( number_of_scans == 0)
218  return PGS_S_SUCCESS;
219 
220  if ( (number_of_scans < 0) || (num_detectors <= 0 )
221  || (swfid == FAIL ))
222  {
223  sprintf(msgbuf, "\n number_of_scans = %d,\n"
224  " num_detectors = %d,\n swfid = %ld\n",
225  number_of_scans, num_detectors, (long)swfid);
226  modsmf(MODIS_E_BAD_INPUT_ARG, msgbuf,
227  "GEO_create_swath, GEO_create_swath.c");
228  return MODIS_E_BAD_INPUT_ARG;
229  }
230 
231  if (N_samp == 1)
232  {
233  dimensions = 2;
234  startfield = 3;
235  }
236  else if(N_samp == 2)
237  {
238  Swath_Dimname[2].fieldname = NSCANS_20;
239  Swath_Dimname[2].dim = number_of_scans*20;
240  Swath_Dimname[2].increment = 2;
241  Swath_Dimname[3].fieldname = MFRAMES_2;
242  Swath_Dimname[3].dim = MAX_FRAMES*2;
243  Swath_Dimname[3].increment = 2;
244  }
245  else if(N_samp == 4)
246  {
247  Swath_Dimname[2].fieldname = NSCANS_40;
248  Swath_Dimname[2].dim = number_of_scans*40;
249  Swath_Dimname[2].offset = 1;
250  Swath_Dimname[2].increment = 4;
251  Swath_Dimname[3].fieldname = MFRAMES_4;
252  Swath_Dimname[3].dim = MAX_FRAMES*4;
253  Swath_Dimname[3].increment = 4;
254 
255  strncpy(offsets_dimlist, NSCANS_40","MFRAMES_4, sizeof offsets_dimlist);
256  }
257 
258  /* Create the Swath */
259 
260  if ((swathID = SWcreate(swfid, SWATH_NAME)) == FAIL){
261  modsmf(MODIS_E_GEO,
262  "SWcreate(\""SWATH_NAME"\")",
263  filefunc);
264  return MODIS_E_GEO;
265  }
266 
267  /* Name the Swath dimensions */
268 
269  Swath_Dimname[0].dim = number_of_scans * DETECTORS_1KM;
270 
271  for(dim=0; dim<dimensions; dim++ ){
272  if (SWdefdim(swathID,
273  Swath_Dimname[dim].fieldname,
274  Swath_Dimname[dim].dim) != SUCCEED){
275  /* call SDP SMF function to report error */
276  sprintf(msgbuf, "SWdefdim(\"%s\")", Swath_Dimname[dim].fieldname);
277  modsmf(MODIS_E_GEO, msgbuf, filefunc);
278  return_status = MODIS_E_GEO;
279  }
280  }
281 
282  if (N_samp >1) {
283  for(dim=0; dim < 2; dim++){
284  if (SWdefdimmap(swathID,
285  Swath_Dimname[dim].fieldname,
286  Swath_Dimname[dim+2].fieldname,
287  Swath_Dimname[dim+2].offset,
288  Swath_Dimname[dim+2].increment) != SUCCEED){
289  /* call SDP SMF function to report error */
290  sprintf(msgbuf, "SWdefdimmap(\"%s\",\"%s\",\"%ld\",\"%ld\")",
291  Swath_Dimname[dim].fieldname,
292  Swath_Dimname[dim+2].fieldname,
293  (long)Swath_Dimname[dim+2].offset,
294  (long)Swath_Dimname[dim+2].increment);
295  modsmf(MODIS_E_GEO, msgbuf, filefunc);
296  return_status = MODIS_E_GEO;
297  }
298  }
299  }
300 
301  /* Set up Geolocation Fields */
302 
303  for(fld=0; fld<(int)(sizeof Swath_Geofields/sizeof Swath_Geofields[0]); fld++){
304  if (SWdefgeofield(swathID,
305  Swath_Geofields[fld].fieldname,
306  Swath_Geofields[fld].dimlist,
307  Swath_Geofields[fld].datatype,
308  HDFE_NOMERGE) != SUCCEED){
309  /* call SDP SMF function to report error */
310  sprintf(msgbuf, "SWdefgeofield(\"%s\")", Swath_Geofields[fld].fieldname);
311  modsmf(MODIS_E_GEO, msgbuf, filefunc);
312  return_status = MODIS_E_GEO;
313  }
314  }
315 
316  for(fld=startfield; fld<(int)(sizeof Swath_Datafields/sizeof Swath_Datafields[0]); fld++){
317  if (SWdefdatafield(swathID,
318  Swath_Datafields[fld].fieldname,
319  Swath_Datafields[fld].dimlist,
320  Swath_Datafields[fld].datatype,
321  HDFE_NOMERGE) != SUCCEED){
322  /* call SDP SMF function to report error */
323  sprintf(msgbuf, "SWdefdatafield(\"%s\")", Swath_Datafields[fld].fieldname);
324  modsmf(MODIS_E_GEO, msgbuf,filefunc);
325  return_status = MODIS_E_GEO;
326  }
327  }
328 
329  /* Detach swath */
330 
331  if( SWdetach(swathID) != SUCCEED){
332  /* call SDP SMF function to report error */
333  modsmf(MODIS_E_GEO,
334  "SWdetach()",
335  filefunc);
336  return_status = MODIS_E_GEO;
337  }
338 
339  return(return_status);
340 
341 }
#define SOL_ZENITH
Definition: GEO_product.h:235
#define HEIGHT
Definition: GEO_product.h:231
#define NSCANS_40
Definition: GEO_product.h:188
#define NSCANS_20
Definition: GEO_product.h:187
#define FAIL
Definition: ObpgReadGrid.h:18
PGSt_SMF_status GEO_create_swath(int const number_of_scans, int const num_detectors, int32 const swfid)
#define SOL_AZIMUTH
Definition: GEO_product.h:236
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_BAD_INPUT_ARG
#define MAX_FRAMES
Definition: GEO_geo.h:79
#define LONGITUDE
Definition: GEO_product.h:229
#define WATER_PRESENT
Definition: GEO_product.h:238
#define SWATH_NAME
Definition: GEO_product.h:146
#define GFLAGS
Definition: GEO_product.h:239
#define MODIS_E_GEO
#define MFRAMES_4
Definition: GEO_product.h:191
#define HEIGHT_OFFSET
Definition: GEO_product.h:244
#define SEN_AZIMUTH
Definition: GEO_product.h:233
#define TRACK_OFFSET
Definition: GEO_product.h:243
#define SEN_ZENITH
Definition: GEO_product.h:232
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT16
#define DETECTORS_1KM
Definition: GEO_geo.h:85
#define RANGE
Definition: GEO_product.h:234
#define MFRAMES
Definition: GEO_product.h:189
PARAM_TYPE_NONE Default value No parameter is buried in the product name name_prefix is case insensitive string compared to the product name PARAM_TYPE_VIS_WAVE The visible wavelength bands from the sensor are buried in the product name The product name is compared by appending and name_suffix ie aph_412_giop where prod_ix will be set to PARAM_TYPE_IR_WAVE same search method as PARAM_TYPE_VIS_WAVE except only wavelength above are looped through but prod_ix is still based ie aph_2_giop for the second and prod_ix set to PARAM_TYPE_INT name_prefix is compared with the beginning of the product name If name_suffix is not empty the it must match the end of the product name The characters right after the prefix are read as an integer and prod_ix is set to that number strncpy(l2prod->name_prefix, "myprod", UNITLEN)
l2prod offset
#define LAND_SEAMASK
Definition: GEO_product.h:237
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_FLOAT32
#define SCAN_OFFSET
Definition: GEO_product.h:242
#define LATITUDE
Definition: GEO_product.h:230
#define MFRAMES_2
Definition: GEO_product.h:190
#define NSCANS_10
Definition: GEO_product.h:186