OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_location_main.c
Go to the documentation of this file.
1 #include "imsl_wrap.h"
2 #include "GEO_DEM.h"
3 #include "GEO_main.h"
4 #include "GEO_main_func.h"
5 #include "GEO_earth.h"
6 #include "version.h"
7 
8 int main (void)
9 /*****************************************************************************
10 !C
11 
12 !Description:
13  Routine in Main group of the Level-1A geolocation software to call
14  routines to read the parameter file, retrieve the file/path name for
15  each input/output file pair, and sequence through each granule.
16 
17 !Input Parameters:
18  None
19 
20 !Output Parameters:
21  None
22 
23 Return Values:
24  EXIT_SUCCESS if all granules processed and output successfully,
25  EXIT_FAIL otherwise
26 
27 Externally Defined:
28  __DATE__ defined by compiler
29  __TIME__ defined by compiler
30  DEM_resolutions "GEO_DEM.h"
31  EXIT_FAIL "GEO_basic.h"
32  FAIL "hdf.h"
33  geoID "GEO_main.h"
34  l1aID "GEO_main.h"
35  MAKEFILE_REVISION MOD_PR03.mk
36  MODIS_E_GEO "PGS_MODIS_35251.h"
37  MODIS_U_GEO_BEGIN "PGS_MODIS_35251.h"
38  MODIS_U_GEO_END "PGS_MODIS_35251.h"
39  PGS_S_SUCCESS "PGS_SMF.h"
40  PGSd_DEM_WATER_LAND "PGS_DEM.h"
41  PGSd_DEM_30ARC "PGS_DEM.h"
42  PGSd_PC_LINE_LENGTH_MAX "PGS_PC.h"
43  PGSd_PC_FILE_PATH_MAX "PGS_PC.h"
44  RESOLUTIONS "GEO_DEM.h"
45  TERRAIN_CORRECT_LUN "GEO_geo.h"
46  TERRAIN_CORRECT "GEO_geo.h"
47 
48 Called by:
49  None
50 
51 Routines called:
52  imsl_error_options "imsl_wrap.h"
53  modsmf "smfio.h"
54  PGS_DEM_Close "PGS_DEM.h"
55  PGS_DEM_Open "PGS_DEM.h"
56  PGS_PC_GetConfigData "PGS_PC.h"
57  PGS_PC_GetNumberOfFiles "PGS_PC.h"
58  PGS_PC_GetReference "PGS_PC.h"
59  GEO_close_DEM "GEO_earth.h"
60  GEO_initialize_DEM "GEO_earth.h"
61  GEO_locate_one_granule "GEO_main_func.h"
62  GEO_read_param_file "GEO_main_func.h"
63 
64 !Revision History:
65 GEO_location_main.c,v
66 Revision 6.2 2010/08/03 20:12:34 kuyper
67 Changed to use 15 arc second DEM files, falling back to 30 arc second if
68  necessary.
69 Changed to use GEO_DEM.h
70 Changed to expect a status code from GEO_initialize_DEM().
71 
72 Revision 6.1 2010/06/18 19:54:27 kuyper
73 Helped resolve Bug 2470 by removing an obsolete structure and the function
74  that filled it in.
75 Changed point of definition for many objects, to restrict their scope.
76 
77 Revision 5.2 2006/01/20 16:08:55 kuyper
78 Reinstated Revision keyword.
79 
80 Revision 5.1 2004/10/03 22:18:32 vlin
81  Created a maneuver_list, filled it in with a call to GEO_read_maneuver_file,
82 and passed it on to GEO_locate_one_granule.
83 vlin@saicmodis.com
84 
85 Revision 4.3 2003/12/10 22:30:56 kuyper
86 Corrected typo.
87 
88 Revision 4.2 2003/08/13 18:12:03 kuyper
89 Added more information to startup message.
90 Changed to use imsl_wrap.h.
91 
92 Revision 4.1 2002/06/11 13:33:30 vlin
93 Updated according to v4.1 GEO_location_main.PDL
94 
95 Requirements:
96  Call's PR03-CSC-2 through 34 and 46, either directly or
97  indirectly, to meet requirements.
98 
99 !Team-unique Header:
100 
101  This software is developed by the MODIS Science Data Support
102  Team for the National Aeronautics and Space Administration,
103  Goddard Space Flight Center, under contract NAS5-32373.
104 
105 !END**************************************************************************/
106 {
107  GEO_param_struct geo_params; /* Geolocation parameters. */
108  int returnStatus = EXIT_SUCCESS; /* Value to be returned by this program. */
109  char msgbuf[PGSd_PC_FILE_PATH_MAX];
110  char filefunc[] = __FILE__ ", main";
111 
112  modsmf(MODIS_U_GEO_BEGIN, "6.2 compiled on " __DATE__ " at "
113  __TIME__ " using makefile " MAKEFILE_REVISION , filefunc);
114 
116  IMSL_SET_PRINT, IMSL_WARNING, 0,
117  IMSL_SET_PRINT, IMSL_FATAL, 0,
118  IMSL_SET_PRINT, IMSL_TERMINAL, 0,
119  IMSL_SET_STOP, IMSL_FATAL, 0,
120  IMSL_SET_STOP, IMSL_TERMINAL, 0,
121  0);
122 
123  setlinebuf (stdout);
124  printf("MODIS GEO version %s, built %s %s\n",
125  PROCESSVERSION, __DATE__, __TIME__);
126 
127  /* Execute GEO_read_param_file */
128  if (GEO_read_param_file(&geo_params) != PGS_S_SUCCESS) {
129  modsmf(MODIS_E_GEO, "GEO_read_param_file()", filefunc);
130  returnStatus = EXIT_FAIL;
131  }
132  else
133  {
134  /* Resolution of Digital Elevation Model */
135  PGSt_integer land_sea_layer=PGSd_DEM_WATER_LAND; /* land/sea mask tag */
136  PGSt_integer numFiles; /* Number of L1A input files to be processed.*/
137  char correct_terrain[PGSd_PC_LINE_LENGTH_MAX]=TERRAIN_CORRECT;
138 
139  if (PGS_DEM_Open(DEM_resolutions, RESOLUTIONS, &land_sea_layer, 1)
140  != PGS_S_SUCCESS)
141  modsmf(MODIS_E_GEO, "PGS_DEM_Open() for land-sea mask", filefunc);
142 
143  if (PGS_PC_GetConfigData(TERRAIN_CORRECT_LUN, correct_terrain)
144  !=PGS_S_SUCCESS)
145  {
146  sprintf(msgbuf,"PGS_PC_GetConfigData(%ld)",
147  (long)TERRAIN_CORRECT_LUN);
148  modsmf(MODIS_E_GEO, msgbuf, filefunc);
149  }
150 
151  if ( /* Check if terrain correction is to be performed */
152  strncmp(correct_terrain, TERRAIN_CORRECT, sizeof(TERRAIN_CORRECT))==0
153  && GEO_initialize_DEM() != PGS_S_SUCCESS)
154  {
155  modsmf(MODIS_E_GEO, "GEO_initialize_DEM()", filefunc);
156  returnStatus = EXIT_FAIL;
157  }
158  /* Get number of level 1a input files */
159  else if (PGS_PC_GetNumberOfFiles(l1aID, &numFiles)!=PGS_S_SUCCESS)
160  {
161  sprintf(msgbuf,"PGS_PC_GetNumberOfFiles(%ld)", (long)l1aID);
162  modsmf(MODIS_E_GEO, msgbuf, filefunc);
163  returnStatus = EXIT_FAIL;
164  }
165  else
166  {
167  PGSt_integer version; /* L1A input file version. */
168 
169  for (version = 1; version <= numFiles; version++)
170  {
171  /* PGS_PC_GetReference changes copy_vers */
172  PGSt_integer copy_vers = version; /* copy of version. */
173  /* Input/Output file name. */
174  char l1a_file_name[PGSd_PC_FILE_PATH_MAX];
175 
176  /* Get level 1A file names (Product Input) */
177  if (PGS_PC_GetReference(l1aID, &copy_vers, l1a_file_name)
178  != PGS_S_SUCCESS)
179  {
180  sprintf(msgbuf,"PGS_PC_GetReference(%ld,%ld)",(long)l1aID,
181  (long)version);
182  modsmf(MODIS_E_GEO, msgbuf, filefunc);
183  returnStatus = EXIT_FAIL;
184  }
185  else
186  {
187  /* Output file name. */
188  char geo_file_name[PGSd_PC_FILE_PATH_MAX];
189 
190  copy_vers = version;
191  /* PGS_PC_GetReference() changes copy_vers */
192 
193  /* Get geolocation file names (Product Output) */
194  if (PGS_PC_GetReference(geoID, &copy_vers, geo_file_name)
195  != PGS_S_SUCCESS)
196  {
197  sprintf(msgbuf, "PGS_PC_GetReference(%ld,%ld)",
198  (long)geoID, (long)version);
199  modsmf(MODIS_E_GEO, msgbuf, filefunc);
200  returnStatus = EXIT_FAIL;
201  }
202 
203  /* Execute GEO_locate_one_granule */
204  else if(GEO_locate_one_granule(l1a_file_name, geo_file_name,
205  &geo_params, version) != PGS_S_SUCCESS)
206  {
207  sprintf(msgbuf, "GEO_locate_one_granule(%s,%s)",
208  l1a_file_name, geo_file_name);
209  modsmf(MODIS_E_GEO, msgbuf, filefunc);
210  returnStatus = EXIT_FAIL;
211  }
212 
213  modsmf(MODIS_U_GEO_GRANULE_ID, l1a_file_name, filefunc);
214  } /* Else get l1a_file_name succeeded. */
215  } /* for each version */
216  } /* Else GetNumFiles worked. */
217 
218  if (strncmp(correct_terrain, TERRAIN_CORRECT, sizeof(TERRAIN_CORRECT))
219  ==0 && GEO_close_DEM() != PGS_S_SUCCESS)
220  modsmf(MODIS_E_GEO, "GEO_close_DEM()", filefunc);
221 
222  if (PGS_DEM_Close(DEM_resolutions, RESOLUTIONS, &land_sea_layer, 1)
223  !=PGS_S_SUCCESS)
224  modsmf(MODIS_E_GEO, "PGS_DEM_Close(land_sea_layer)", filefunc);
225 
226  } /* Else parameter file read in OK. */
227 
228  sprintf(msgbuf, " = %d", returnStatus);
229  modsmf(MODIS_U_GEO_END, msgbuf, filefunc);
230  return returnStatus;
231 }
232 
#define EXIT_SUCCESS
Definition: GEO_basic.h:72
#define l1aID
Definition: GEO_main.h:67
#define MODIS_E_GEO
int setlinebuf(FILE *stream)
PGSt_SMF_status GEO_read_param_file(GEO_param_struct *const param)
#define TERRAIN_CORRECT
Definition: GEO_geo.h:125
#define PROCESSVERSION
Definition: version.h:112
#define TERRAIN_CORRECT_LUN
Definition: GEO_geo.h:95
int GEO_close_DEM(void)
Definition: GEO_DEM.c:1093
PGSt_DEM_Tag DEM_resolutions[RESOLUTIONS]
Definition: GEO_DEM.c:62
#define MODIS_U_GEO_BEGIN
PGSt_SMF_status GEO_initialize_DEM(void)
Definition: GEO_DEM.c:134
PGSt_SMF_status GEO_locate_one_granule(char l1a_file_name[PGSd_PC_FILE_PATH_MAX], char geo_file_name[PGSd_PC_FILE_PATH_MAX], GEO_param_struct const *geo_params, int const version)
int main(void)
#define MODIS_U_GEO_GRANULE_ID
#define EXIT_FAIL
Definition: GEO_basic.h:71
#define MODIS_U_GEO_END
void IMSL_DECL imsl_error_options(int arg,...)
Definition: imsl_error.c:81
#define geoID
Definition: GEO_main.h:68
version
Definition: setup.py:15
#define RESOLUTIONS
Definition: GEO_DEM.h:52