OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_l8_angles.c
Go to the documentation of this file.
1 #include "emeta_api.h" /* Enhanced metadata functionality */
2 #define MAXBAND 7
3 
14 int get_oli_angles( char *emeta_filename, int32_t npix, int32_t nscan, int32_t iscan,
15  float *solz, float *sola, float *senz, float *sena,
16  int32_t isGeomPerBand)
17 {
18  static int firstCall = 1;
19  static int nband; /* Number of bands */
20  static EMETA_FRAME frame[MAXBAND]; /* Output image frame info */
21  int band; /* User band number */
22  int band_index; /* Band index */
23  int is; /* Sample (pixel) index */
24  int status; /* Status return flag */
25  short *sat_zn; /* Satellite zenith angle */
26  short *sat_az; /* Satellite azimuth angle */
27  short *sun_zn; /* Solar zenith angle */
28  short *sun_az; /* Solar azimuth angle */
29  int isb; /* index counter for band based arrays */
30 
31  if (firstCall == 1) {
32 
33  /* Initialize the enhanced metadata package */
34  if ( (nband = emeta_init( emeta_filename )) < 1 )
35  {
36  IAS_LOG_ERROR("Initializing the enhanced metadata file %s.", emeta_filename);
37  fprintf(stderr,
38  "-E- %s line %d: Initializing the metadata file %s.\n",
39  __FILE__, __LINE__, emeta_filename);
40  exit (EXIT_FAILURE);
41  }
42  }
43  /* Allocate the intermediary buffers for calculating average over MAXBAND*/
44  if ( (sat_zn = (short *)malloc( npix*sizeof(short) )) == NULL )
45  {
46  emeta_close();
47  fprintf(stderr,
48  "-E- %s line %d: Unable to allocate satellite elevation angle array.\n",
49  __FILE__, __LINE__);
50  exit (EXIT_FAILURE);
51  }
52  if ( (sat_az = (short *)malloc( npix*sizeof(short) )) == NULL )
53  {
54  free(sat_zn);
55  emeta_close();
56  fprintf(stderr,
57  "-E- %s line %d: Unable to allocate satellite azimuth angle array.\n",
58  __FILE__, __LINE__);
59  exit (EXIT_FAILURE);
60  }
61  if ( (sun_zn = (short *)malloc( npix*sizeof(short) )) == NULL )
62  {
63  free(sat_zn);
64  free(sat_az);
65  emeta_close();
66  fprintf(stderr,
67  "-E- %s line %d: Unable to allocate solar elevation angle array.\n",
68  __FILE__, __LINE__);
69  exit (EXIT_FAILURE);
70  }
71  if ( (sun_az = (short *)malloc( npix*sizeof(short) )) == NULL )
72  {
73  free(sat_zn);
74  free(sat_az);
75  free(sun_zn);
76  emeta_close();
77  fprintf(stderr,
78  "-E- %s line %d: Unable to allocate solar azimuth angle array.\n",
79  __FILE__, __LINE__);
80  exit (EXIT_FAILURE);
81  }
82  /* Initialize nominal values */
83  for ( is=0; is<npix; is++ )
84  {
85  senz[is] = 0;
86  sena[is] = 0;
87  solz[is] = 0;
88  sola[is] = 0;
89  }
90 
91  /* Process the angles for each band */
92  for ( band_index=0; band_index<MAXBAND; band_index++ )
93  {
94  /* Get framing information for this band */
95  if ( firstCall == 1 && emeta_get_frame( band_index, &frame[band_index] ) != SUCCESS )
96  {
97  fprintf(stderr,
98  "-E- %s line %d: Unable to get emeta frame.\n",
99  __FILE__, __LINE__);
100  exit (EXIT_FAILURE);
101  }
102  band = frame[band_index].band;
103 
104  /* Loop through the L1T samples */
105  for ( is=0; is<npix; is++ )
106  {
107  isb = is*MAXBAND+band_index;
108 
109  status = emeta_calc( (int)iscan, is, band, &sat_zn[is], &sat_az[is], &sun_zn[is], &sun_az[is] );
110  if ( status != SUCCESS )
111  {
112  fprintf(stderr,
113  "-E- %s line %d: Error Evaluating angles in band %d.\n",
114  __FILE__, __LINE__,band);
115  exit (EXIT_FAILURE);
116  }
117  // Populate the nominal values as band averages
118  /* Average the bands and convert to decimal degrees */
119  if (isGeomPerBand)
120  {
121  senz[isb] = (float)sat_zn[is]/100.;
122  sena[isb] = (float)sat_az[is]/100.;
123  solz[isb] = (float)sun_zn[is]/100.;
124  sola[isb] = (float)sun_az[is]/100.;
125  } else {
126  senz[is] += (float) sat_zn[is] / (100 * MAXBAND);
127  sena[is] += (float) sat_az[is] / (100 * MAXBAND);
128  solz[is] += (float) sun_zn[is] / (100 * MAXBAND);
129  sola[is] += (float) sun_az[is] / (100 * MAXBAND);
130  }
131  }
132  }
133 
134  /* Free the angle arrays */
135  free( sat_zn );
136  free( sat_az );
137  free( sun_zn );
138  free( sun_az );
139 
140  /* Release the enhanced metadata */
141  //emeta_close(); /* Probably should close this properly somewhere after processing */
142  firstCall = 0;
143  return (SUCCESS);
144 }
#define SUCCESS
Definition: ObpgReadGrid.h:15
#define IAS_LOG_ERROR(format,...)
Definition: ias_logging.h:96
int status
Definition: l1_czcs_hdf.c:32
#define MAXBAND
Definition: get_l8_angles.c:2
#define NULL
Definition: decode_rs.h:63
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 band
this program makes no use of any feature of the SDP Toolkit that could generate such a then geolocation is calculated at that and then aggregated up to Resolved feature request Bug by adding three new int8 SDSs for each high resolution offsets between the high resolution geolocation and a bi linear interpolation extrapolation of the positions This can be used to reconstruct the high resolution geolocation Resolved Bug by delaying cumulation of gflags until after validation of derived products Resolved Bug by setting Latitude and Longitude to the correct fill resolving to support Near Real Time because they may be unnecessary if use of entrained ephemeris and attitude data is turned resolving bug report Corrected to filter out Aqua attitude records with missing status helping resolve bug MOD_PR03 will still correctly write scan and pixel data that does not depend upon the start thereby resolving MODur00108 Changed header guard macro names to avoid reserved name resolving MODur00104 Maneuver list file for Terra satellite was updated to include data from Jecue DuChateu Maneuver list files for both Terra and Aqua were updated to include two maneuvers from recent IOT weekly reports The limits for Z component of angular momentum was and to set the fourth GEO scan quality flag for a scan depending upon whether or not it occurred during one of them Added _FillValue attributes to many and changed the fill value for the sector start times from resolving MODur00072 Writes boundingcoordinate metadata to L1A archived metadata For PERCENT *ECS change to treat rather resolving GSFcd01518 Added a LogReport Changed to create the Average Temperatures vdata even if the number of scans is
Definition: HISTORY.txt:301
int32 nscan
Definition: l1_czcs_hdf.c:19
void emeta_close()
Definition: emeta_api.c:91
int emeta_init(char *emeta_filename)
Definition: emeta_api.c:5
int32_t nband
int get_oli_angles(char *emeta_filename, int32_t npix, int32_t nscan, int32_t iscan, float *solz, float *sola, float *senz, float *sena, int32_t isGeomPerBand)
Definition: get_l8_angles.c:14
int32_t iscan
int emeta_get_frame(int eband, EMETA_FRAME *frame)
Definition: emeta_api.c:18
int emeta_calc(int in_line, int in_samp, int in_band, short *sat_zn, short *sat_az, short *sun_zn, short *sun_az)
Definition: emeta_api.c:42
int npix
Definition: get_cmp.c:27