OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_write_one_scan.c
Go to the documentation of this file.
1 #include "PGS_SMF.h"
2 #include "PGS_MODIS_35251.h"
3 #include "GEO_output.h"
4 #include "GEO_earth.h"
5 #include "GEO_util.h"
6 #include "GEO_validation.h"
7 
8 PGSt_SMF_status GEO_write_one_scan(
9  PGSt_double const frame_time[],
10  int const scan_number,
11  l1a_data_struct const * const l1a_data,
12  GEO_param_struct const * const geo_params,
13  double frame_to_sensor[][MAX_FRAMES][3],
14  double frame_solar_angles[][MAX_FRAMES][2],
15  double terrain_frame_position[][MAX_FRAMES][3],
16  uint8 frame_flags[][MAX_FRAMES],
17  int8 hires_offsets[][DETECTORS_QKM][SAMPLES_QKM],
18  PGSt_double const rpy[],
19  uint32 frame_quality[][MAX_FRAMES],
20  uint8 frame_landsea[][MAX_FRAMES],
21  uint8 frame_waterpresent[][MAX_FRAMES],
22  uint8 land_seamask_qaflag,
23  MODFILE * const geo_file
24 )
25 /*
26 !C*****************************************************************************
27 !Description:
28  subroutine in output group of the Level-1A geolocation
29  software to write scan-level data to the output product.
30  It calls routines to write the scan data and the scan
31  l1a_data->frame_data[scan_number].EV_frames,
32  metadata to the geolocation file.
33 
34 !Input Parameters:
35  scan_number the scan number
36  sc_ev_frame_state array of spacecraft kinematic states for each
37  Earth View frame.
38  l1a_data data read from L1A file
39  geo_params geolocation parameters read from input file
40  maneuver_list A list of spacecraft maneuvers
41  frame_to_sensor pixel-to-satellite angles and range
42  frame_solar_angles solar azimuth and zenith angles
43  terrain_frame_position terrain-corrected geodetic coordinated for
44  pixels
45  frame_flags pixel flags
46  hires_offsets High resolutions offsets from bilinearly
47  interpolated low resolution data.
48  rpy Roll, pitch, and yaw components of thermal
49  attitude correction.
50  frame_quality Ephemeris and Attitude quality flags.
51  frame_landsea Land/Water mask.
52  frame_waterpresent Sum of weights of high-resolution pixels with
53  water aggregated into low-resolution mask.
54  land_seamask_qaflag Indicates whether there were problems with the
55  Land/Water mask.
56  geo_file M-API structure for the geolocation file
57 
58 !Output Parameters:
59  None
60 
61 Return parameter:
62  MODIS_E_BAD_INPUT_ARG If input values are found to be invalid.
63  MODIS_E_GEO If any subroutine fails
64  PGS_S_SUCCESS Otherwise
65 
66 Externally Defined:
67  GOOD_DATA "GEO_validation.h"
68  MAX_FRAMES "GEO_geo.h"
69  MAX_SCAN_NUMBER "GEO_geo.h"
70  MODIS_E_BAD_INPUT_ARG "PGS_MODIS_35251.h"
71  MODIS_E_GEO "PGS_MODIS_35251.h"
72  PGS_S_SUCCESS "PGS_SMF.h"
73  SAMPLES_QKM "GEO_geo.h"
74 
75 Called by:
76  GEO_locate_one_scan
77 
78 Routines called:
79  GEO_solar_and_lunar_vectors - spacecraft, solar, and lunar
80  vector metadata.
81  GEO_write_scan_data - write scan data
82  GEO_write_scan_metadata - write scan-level data
83  modsmf - writes error status messages to log
84 
85 !Revision History:
86  * $Log: GEO_write_one_scan.c,v $
87  * Revision 6.3 2011/02/18 21:58:21 kuyper
88  * In order to resolve feature-request bug 3446, changed to receive landsea
89  * mask, rather than calling function to fill it in.
90  *
91  * Revision 6.2 2010/05/27 15:28:49 kuyper
92  * Helped resolve Bug 1969 by adding rpy as an input parameters to be passed to
93  * GEO_write_scan_metadata().
94  * Helped resolve Bug 2470 by removing a parameter.
95  * Helped resolve Bug 2472 by adding frame_quality as an input parameters to be
96  * passed to GEO_write_scan_metadata().
97  * Changed to expect status codes from GEO_write_scan_metadata().
98  *
99  * Revision 6.1 2009/05/27 14:47:05 xgeng
100  * Change to return a status code, and to expect one from GEO_write_scan_data().
101  * Pass frame_time on to GEO_solar_and_lunar_vectors().
102  * Move code for rearranging arrays to GEO_write_scan_data, where it can be
103  * combined with code that changes the value and formate of the data, avoiding
104  * need to keep a copy in scan_data.
105  * Rename pixel_flags as frame flags.
106  * Change to use DETECTORS_1KM rather than num_detectors for all loop limits.
107  * Changed MAX_SCAN_SAMPLE to MAX_FRAMES.
108  * Added frame_time, hires_offsets and terrain_frame_position as input parameters.
109  * Corrected frame_time's data type, removed sc_ev_frame_state.
110  * The above changes match with PDL revision 6.1 to 6.3.
111  *
112  * Xu Geng (xu.geng@saic.com)
113  *
114  * Revision 5.2 2004/10/27 19:55:00 vlin
115  * call to function GEO_solar_and_lunar_vectors updated.
116  * vlin@saicmodis.com
117  *
118  * Revision 5.1 2004/08/25 19:06:59 vlin
119  * Input parameters maneuver_list, sample_to_sensor, and
120  * sample_solar_angles added.
121  * Change to check for !=SUCCESS instead of ==FAIL.
122  *
123  * Revision 4.3 2004/04/09 21:01:16 kuyper
124  * Corrected typo.
125  *
126  * Revision 4.2 2003/12/30 21:21:43 kuyper
127  * Changed message for failure of GEO_solar_and_lunar_vectors.
128  * Added file information to message for GEO_write_scan_data call.
129  *
130  * Revision 4.1 2003/02/21 22:56:11 kuyper
131  * Corrected to use void* pointers with %p format code.
132 
133 Requirements:
134  PR03-F-3.5.1-1
135  PR03-F-3.5.2-1
136  PR03-F-3.5.3-1
137  PR03-F-3.5.3-2
138  PR03-F-3.6.1-1
139  PR03-F-3.6.2-1
140  PR03-F-3.6.3-2
141  PR03-F-4.3-1
142  PR03-F-4.3-2
143  PR03-F-4.4-1
144  PR03-F-4.4-2
145  CCR-319
146 
147 !Team-unique Header:
148  This software is developed by the MODIS Science Data Support
149  Team for the National Aeronautics and Space Administration,
150  Goddard Space Flight Center, under contract NAS5-32373.
151 
152 !END*************************************************************************
153 */
154 {
155  swath_elem_struct scan_data;
156  celestial_bodies_struct cb_vectors;
157  /* offsets into sensor, solar arrays. */
158  PGSt_SMF_status retval=PGS_S_SUCCESS; /* Return value for this routine. */
159  unsigned char flag; /* qaflag value for scan. */
160  char msgbuf[PGS_SMF_MAX_MSGBUF_SIZE] = "";
161  char *filefunc = __FILE__ ", GEO_write_one_scan";
162 
163  /* Begin program logic */
164  /* Only need to validate pointers dereferenced in this module. */
165  if (geo_file==NULL || l1a_data==NULL ||
166  scan_number < 0 || scan_number >= MAX_SCAN_NUMBER)
167  {
168  sprintf(msgbuf, "geo_file = %p, l1a_data = %p, scan_number = %d",
169  (void*)geo_file, (void*)l1a_data, scan_number);
170  modsmf(MODIS_E_BAD_INPUT_ARG, msgbuf, filefunc);
171 
172  return MODIS_E_BAD_INPUT_ARG;
173  }
174 
175  /* compute the celestial body vector metadata of spacecraft, sun, and moon */
176  if(GEO_solar_and_lunar_vectors(frame_time, &l1a_data->frame_data[scan_number],
177  geo_params, &l1a_data->fill_values, &cb_vectors) != PGS_S_SUCCESS) {
178  modsmf(MODIS_E_GEO, "GEO_solar_and_lunar_vectors()", filefunc);
179  retval = MODIS_E_GEO;
180  }
181 
182  /* Write scan metadata */
183  if (GEO_write_scan_metadata(scan_number, l1a_data, &cb_vectors, geo_file,
184  rpy, frame_quality) != PGS_S_SUCCESS)
185  {
186  sprintf(msgbuf, "GEO_write_scan_metadata(%d, \"%s\")", scan_number,
187  geo_file->filename);
188  modsmf(MODIS_E_GEO, msgbuf, filefunc);
189 
190  retval = MODIS_E_GEO;
191  }
192 
193  if(l1a_data->frame_data[scan_number].L1A_scan_quality[0] == 0)
194  return retval; /* nothing to write out and no functional error */
195 
196  scan_data.num_detectors = DETECTORS_1KM;
197  scan_data.num_frames = l1a_data->frame_data[scan_number].EV_frames;
198 
199  flag = (l1a_data->mirr_data[scan_number].impulse_flag!=GOOD_DATA ||
200  scan_data.num_frames==0);
201 
202  /* We have 9 seperate flags, anticipating that in the future they will
203  be set in different locations for different reasons. */
204  scan_data.lat_qaflag = flag;
205  scan_data.lon_qaflag = flag;
206  scan_data.height_qaflag = flag;
207  scan_data.sensorazimuth_qaflag = flag;
208  scan_data.sensorzenith_qaflag = flag;
209  scan_data.solarazimuth_qaflag = flag;
210  scan_data.solarzenith_qaflag = flag;
211  scan_data.range_qaflag = flag;
212  scan_data.land_seamask_qaflag = land_seamask_qaflag;
213 
214  if(flag==0)
215  {
216  /* Write geolocation scan data */
217  if (GEO_write_scan_data(geo_file, scan_number, &scan_data,
218  (GEO_param_struct *)geo_params, terrain_frame_position,
219  frame_to_sensor, frame_solar_angles, frame_flags, frame_landsea,
220  frame_waterpresent, hires_offsets)
221  != PGS_S_SUCCESS)
222  {
223  sprintf(msgbuf, "GEO_write_scan_data(\"%s\",%d)",
224  geo_file->filename, scan_number);
225  modsmf(MODIS_E_GEO, msgbuf, filefunc);
226 
227  retval = MODIS_E_GEO;
228  }
229  } /* impulse_flag == GOOD_DATA */
230 
231  return retval;
232 }
PGSt_SMF_status GEO_write_scan_data(MODFILE *const, int const, swath_elem_struct const *, GEO_param_struct const *, double[][MAX_FRAMES][3], double[][MAX_FRAMES][3], double[][MAX_FRAMES][2], uint8[][MAX_FRAMES], uint8[][MAX_FRAMES], uint8[][MAX_FRAMES], int8[3][DETECTORS_QKM][SAMPLES_QKM])
PGSt_SMF_status GEO_write_one_scan(PGSt_double const frame_time[], int const scan_number, l1a_data_struct const *const l1a_data, GEO_param_struct const *const geo_params, double frame_to_sensor[][MAX_FRAMES][3], double frame_solar_angles[][MAX_FRAMES][2], double terrain_frame_position[][MAX_FRAMES][3], uint8 frame_flags[][MAX_FRAMES], int8 hires_offsets[][DETECTORS_QKM][SAMPLES_QKM], PGSt_double const rpy[], uint32 frame_quality[][MAX_FRAMES], uint8 frame_landsea[][MAX_FRAMES], uint8 frame_waterpresent[][MAX_FRAMES], uint8 land_seamask_qaflag, MODFILE *const geo_file)
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_BAD_INPUT_ARG
#define MAX_FRAMES
Definition: GEO_geo.h:79
uint8 sensorzenith_qaflag
Definition: GEO_output.h:119
int16_t * l1a_data
Definition: l1a_seawifs.c:84
uint8 land_seamask_qaflag
Definition: GEO_output.h:125
uint8 solarzenith_qaflag
Definition: GEO_output.h:121
#define MODIS_E_GEO
PGSt_SMF_status GEO_write_scan_metadata(int const scan_number, l1a_data_struct const *const l1a_data, celestial_bodies_struct const *const cb_vectors, MODFILE *const geo_file, PGSt_double const rpy[], uint32 frame_quality[][MAX_FRAMES])
const int GOOD_DATA
#define DETECTORS_1KM
Definition: GEO_geo.h:85
const int MAX_SCAN_NUMBER
PGSt_SMF_status GEO_solar_and_lunar_vectors(PGSt_double const frame_time[], frame_data_struct const *const frame_data, GEO_param_struct const *const geo_params, fill_values_struct const *const fill_values, celestial_bodies_struct *const cb_vectors)
uint8 sensorazimuth_qaflag
Definition: GEO_output.h:118
#define SAMPLES_QKM
Definition: GEO_geo.h:83
#define DETECTORS_QKM
Definition: GEO_geo.h:87
uint8 solarazimuth_qaflag
Definition: GEO_output.h:120