OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_get_bounding_coords.c
Go to the documentation of this file.
1 #include "PGS_MODIS_35251.h"
2 #include "GEO_global_arrays.h"
3 #include "GEO_output.h"
4 
5 
6 #define MAX_ANGLE (PGS_PI/2.0)
7 
9  double terrain_sample_position[MAX_DETECTORS][MAX_SCAN_SAMPLE][3],
10  unsigned char pixel_flags[MAX_DETECTORS][MAX_SCAN_SAMPLE],
11  int const num_detectors,
12  int const num_frames,
13  GEO_bcoord_struct * const bounding_coords )
14 /*
15 !C*****************************************************************************
16 !Description:
17  Routine in Output group of the Level-1A geolocation
18  software to calculate the granule bounding coordinates
19  for the ECS Core Metadata.
20 
21  Every pixel in the granule is inspected for bounding
22  coordinates, scan by scan. Track is kept of the most
23  eastern and western coordinates in both the Eastern
24  and Western Hemisphere. These four longitudes are
25  then compared to identify the granule's most eastern
26  and western bounding coordinates. If the granule is
27  found to lie in both Eastern and Western hemispheres
28  and near both the 0 and 180 meridians, it is identified
29  as a 'polar' granule with the east bounding and west
30  bounding coordinates set to +PI and -PI, respectively,
31  but the north and south bounding coordinates are still
32  set from the coordinates of the northern-most and southern-
33  most pixels found in the granule.
34 
35  The bounding_coords structure must be initialized to
36  the following state prior to beginning the granule's
37  bounding coordinate search:
38 
39  northcoord = -PI/2
40  southcoord = PI/2
41  eastcoord = PI
42  westcoord = -PI
43  easthemi_ebc = 0
44  easthemi_wbc = PI
45  westhemi_ebc = -PI
46  westhemi_wbc = 0
47 
48 !Input Parameters:
49  terrain_sample_position[MAX_DETECTORS][MAX_SCAN_SAMPLE][3]
50  - computed geodetic coordinates for pixels
51  (radians, meters)
52  pixel_flags[MAX_DETECTORS][MAX_SCAN_SAMPLE] - geolocation
53  pixel quality flags.
54  num_detectors - the number of detectors per sample
55  (usually 10). Each scan has
56  num_detectors scan lines.
57  num_frames - the number of (sample) frames in the scan.
58 
59 
60 !Output Parameters:
61  bounding_coords - structure of the granules bounding coordinates
62 
63 Return parameter:
64  SUCCESS if all bounding coordinates are identified,
65  FAIL otherwise.
66 
67 Global variables: None
68 
69 Call functions:
70  modsmf(MODIS_X_MNEMONIC_STRING, "user message string",
71  "function, GEO_write_parameters.c");
72 
73 !Revision History:
74  * $Log: GEO_get_bounding_coords.c,v $
75  * Revision 2.2 1997/11/06 23:18:17 kuyper
76  * Changed pixel_flags to unsigned char, to match gflags.
77  *
78  * Revision 2.1 1997/10/21 18:16:22 kuyper
79  * Returned from ClearCase
80  *
81  * Revision 1.5.1.1 1997/07/21 22:20:17 kuyper
82  * Merged in out-of-sequence changes.
83  *
84  * Revision 1.5 1997/07/21 16:24:34 kuyper
85  * Baselined Version 1
86  *
87  *Parallel Development:
88  * Revision 1.7 1997/04/15 19:38:46 fhliang
89  * added file name (L.1);
90  * fixed prolog: '!Input Parameter' --> '!Input Parameters', and
91  * '!Output Parameter' --> '!Output Parameters'.
92  *
93  * Revision 1.6 1997/04/10 19:35:30 fhliang
94  * Initial revision of SDST re-delivery of GEO_get_bounding_coords.c.
95  *
96  * Revision 1.5 1997/04/08 22:16:23 kuyper
97  * Fixed program prologue.
98  *
99  * Revision 1.4 1997/03/26 18:05:17 fhliang
100  * Initial revision of SDST delivery of GEO_get_bounding_coords.c.
101  *
102  Revision 1.3 1997/01/21 21:02:37 kuyper
103  Merged seed files.
104 
105  Revision 1.3 1997/01/21 21:02:37 kuyper
106  Merged seed files.
107 
108  Revision 1.2 1997/01/15 13:01:17 fshaw
109  updated walkthrough corrections
110 
111 
112 Requirements:
113  PR03-F-4.1-1
114  PR03-F-4.1-2
115 
116 !Team-unique Header:
117  This software is developed by the MODIS Science Data Support
118  Team for the National Aeronautics and Space Administration,
119  Goddard Space Flight Center, under contract NAS5-32373.
120 
121 !END***************************************************************************
122 */
123 {
124 
125  int detector, frame;
126 
127  if ((terrain_sample_position == NULL) || (pixel_flags == NULL)
128  || (bounding_coords == NULL) || (num_detectors < 0)
129  || (num_detectors > MAX_DETECTORS) || (num_frames < 0)
130  || (num_frames > MAX_SCAN_SAMPLE)){
131  modsmf(MODIS_E_BAD_INPUT_ARG, "",
132  "GEO_get_bounding_coords, GEO_get_bounding_coords.c():");
133  return FAIL;
134  }
135 
136  for(detector = 0; detector < num_detectors; detector++){
137  for( frame = 0; frame < num_frames; frame++){
138 
139  if (( (pixel_flags[detector][frame] & INVALID_INPUT_DATA) == 0) &&
140  ( (pixel_flags[detector][frame] & NO_ELLIPSE_INTERSECT) == 0)){
141 
142  if ( terrain_sample_position[detector][frame][LAT_IDX] >
143  bounding_coords->northcoord)
144  bounding_coords->northcoord =
145  terrain_sample_position[detector][frame][LAT_IDX];
146 
147  if( terrain_sample_position[detector][frame][LAT_IDX] <
148  bounding_coords->southcoord)
149  bounding_coords->southcoord =
150  terrain_sample_position[detector][frame][LAT_IDX];
151 
152  if( terrain_sample_position[detector][frame][LON_IDX] > 0.0 ){
153  /* ( it is in the eastern hemisphere) */
154  if( terrain_sample_position[detector][frame][LON_IDX] >
155  bounding_coords->easthemi_ebc)
156  bounding_coords->easthemi_ebc =
157  terrain_sample_position[detector][frame][LON_IDX];
158 
159  if( terrain_sample_position[detector][frame][LON_IDX] <
160  bounding_coords->easthemi_wbc)
161  bounding_coords->easthemi_wbc =
162  terrain_sample_position[detector][frame][LON_IDX];
163 
164  }else { /* (it's in the western hemisphere)*/
165 
166  if( terrain_sample_position[detector][frame][LON_IDX] >
167  bounding_coords->westhemi_ebc)
168  bounding_coords->westhemi_ebc =
169  terrain_sample_position[detector][frame][LON_IDX];
170 
171  if( terrain_sample_position[detector][frame][LON_IDX] <
172  bounding_coords->westhemi_wbc)
173  bounding_coords->westhemi_wbc =
174  terrain_sample_position[detector][frame][LON_IDX];
175  }
176  }
177  }
178  }
179  /* update eastern and western bounding coordinates */
180  if (bounding_coords->westhemi_wbc > bounding_coords->westhemi_ebc){
181  /* (the inspected portion of the granule is not in the Western hemisphere) */
182 
183  bounding_coords->eastcoord = bounding_coords->easthemi_ebc;
184  bounding_coords->westcoord = bounding_coords->easthemi_wbc;
185 
186  } else if( bounding_coords->easthemi_wbc > bounding_coords->easthemi_ebc){
187  /* (the inspected portion of the granule is not in the Eastern hemisphere) */
188 
189  bounding_coords->eastcoord = bounding_coords->westhemi_ebc;
190  bounding_coords->westcoord = bounding_coords->westhemi_wbc;
191 
192  } else if( (bounding_coords->easthemi_wbc - bounding_coords->westhemi_ebc) <
193  MAX_ANGLE){
194  /* (the granule lies in both hemispheres or neither) */
195 
196  if( 2.0 * PGS_PI - (bounding_coords->easthemi_ebc -
197  bounding_coords->westhemi_wbc) < MAX_ANGLE){
198  /* (the granule straddles both 0 and 180 meridians; it is 'polar') */
199 
200  bounding_coords->eastcoord = PGS_PI;
201  bounding_coords->westcoord = -PGS_PI;
202  bounding_coords->easthemi_ebc = PGS_PI;
203  bounding_coords->westhemi_wbc = -PGS_PI;
204  bounding_coords->easthemi_wbc = 0.0;
205  bounding_coords->westhemi_ebc = 0.0;
206 
207  } else{ /* (the granule straddles the 0 meridian) */
208  bounding_coords->eastcoord = bounding_coords->easthemi_ebc;
209  bounding_coords->westcoord = bounding_coords->westhemi_wbc;
210  bounding_coords->easthemi_wbc = 0.0;
211  bounding_coords->westhemi_ebc = 0.0;
212  }
213  } else if( 2.0 * PGS_PI - (bounding_coords->easthemi_ebc -
214  bounding_coords->westhemi_wbc) < MAX_ANGLE){
215  /* (the granule straddles the 180 meridian) */
216 
217  bounding_coords->eastcoord = bounding_coords->westhemi_ebc;
218  bounding_coords->westcoord = bounding_coords->easthemi_wbc;
219  bounding_coords->easthemi_ebc = PGS_PI;
220  bounding_coords->westhemi_wbc = -PGS_PI;
221  }
222  return SUCCESS;
223 }
#define SUCCESS
Definition: ObpgReadGrid.h:15
double westhemi_ebc
Definition: GEO_geo.h:190
#define FAIL
Definition: ObpgReadGrid.h:18
#define NULL
Definition: decode_rs.h:63
int GEO_get_bounding_coords(double terrain_sample_position[MAX_DETECTORS][MAX_SCAN_SAMPLE][3], unsigned char pixel_flags[MAX_DETECTORS][MAX_SCAN_SAMPLE], int const num_detectors, int const num_frames, GEO_bcoord_struct *const bounding_coords)
#define MODIS_E_BAD_INPUT_ARG
double westhemi_wbc
Definition: GEO_geo.h:192
#define PGS_PI
Definition: GEO_geo.h:172
const unsigned char NO_ELLIPSE_INTERSECT
const int MAX_SCAN_SAMPLE
double westcoord
Definition: GEO_geo.h:185
#define MAX_ANGLE
const int MAX_DETECTORS
double easthemi_ebc
Definition: GEO_geo.h:186
double southcoord
Definition: GEO_geo.h:184
@ LON_IDX
double eastcoord
Definition: GEO_geo.h:183
@ LAT_IDX
double easthemi_wbc
Definition: GEO_geo.h:188
double northcoord
Definition: GEO_geo.h:182
const unsigned char INVALID_INPUT_DATA