OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_oli_nom_angles.c
Go to the documentation of this file.
1 #include "smeta_api.h" /* Product metadata functionality */
2 #define MAXBAND 7
3 
14 int get_oli_nom_angles( char *meta_filename, int32_t npix, int32_t nscan, int32_t iscan,
15  float *solz, float *sola, float *senz, float *sena, short *sca_num, short *det_num,
16  int32_t isGeomPerBand)
17 {
18  static int firstCall = 1;
19  static int nband; /* Number of bands */
20  static META_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  double *sat_zn; /* Satellite zenith angle */
26  double *sat_az; /* Satellite azimuth angle */
27  double *sun_zn; /* Solar zenith angle */
28  double *sun_az; /* Solar azimuth angle */
29  int isb; /* index counter for band based arrays */
30 
31  if (firstCall == 1) {
32  /* Initialize the metadata package */
33  if ( (nband = smeta_init( meta_filename )) < 1 )
34  {
35  IAS_LOG_ERROR("Initializing the metadata file %s.", meta_filename);
36  fprintf(stderr,
37  "-E- %s line %d: Initializing the metadata file %s.\n",
38  __FILE__, __LINE__, meta_filename);
39  exit (EXIT_FAILURE);
40  }
41  }
42  /* Allocate the intermediary buffers for calculating average over MAXBAND*/
43  if ( (sat_zn = (double *)malloc( npix*sizeof(double) )) == NULL )
44  {
45  smeta_close();
46  fprintf(stderr,
47  "-E- %s line %d: Unable to allocate satellite elevation angle array.\n",
48  __FILE__, __LINE__);
49  exit (EXIT_FAILURE);
50  }
51  if ( (sat_az = (double *)malloc( npix*sizeof(double) )) == NULL )
52  {
53  free(sat_zn);
54  smeta_close();
55  fprintf(stderr,
56  "-E- %s line %d: Unable to allocate satellite azimuth angle array.\n",
57  __FILE__, __LINE__);
58  exit (EXIT_FAILURE);
59  }
60  if ( (sun_zn = (double *)malloc( npix*sizeof(double) )) == NULL )
61  {
62  free(sat_zn);
63  free(sat_az);
64  smeta_close();
65  fprintf(stderr,
66  "-E- %s line %d: Unable to allocate solar elevation angle array.\n",
67  __FILE__, __LINE__);
68  exit (EXIT_FAILURE);
69  }
70  if ( (sun_az = (double *)malloc( npix*sizeof(double) )) == NULL )
71  {
72  free(sat_zn);
73  free(sat_az);
74  free(sun_zn);
75  smeta_close();
76  fprintf(stderr,
77  "-E- %s line %d: Unable to allocate solar azimuth angle array.\n",
78  __FILE__, __LINE__);
79  exit (EXIT_FAILURE);
80  }
81 
82  /* Initialize here the nominal values requested */
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 
92  /* Process the angles for each band */
93  for ( band_index=0; band_index<MAXBAND; band_index++ )
94  {
95  /* Get framing information for this band */
96  if ( firstCall == 1 && smeta_get_frame( band_index, &frame[band_index] ) != SUCCESS )
97  {
98  fprintf(stderr,
99  "-E- %s line %d: Unable to get smeta frame.\n",
100  __FILE__, __LINE__);
101  exit (EXIT_FAILURE);
102  }
103  band = frame[band_index].band;
104  if ( (iscan) % 500 == 0 ) printf("GET_OLI_NOM_ANGLES: Band/Line %d/%d\n", band, iscan );
105 
106  /* Loop through the L1T lines and samples */
107  for ( is=0; is<npix; is++ )
108  {
109  /* Sudipta - added sca_num and det_num to smeta_calc to retrieve these for OLI */
110  isb = is*MAXBAND+band_index;
111  sca_num[isb] = 0;
112  det_num[isb] = 0;
113  status = smeta_calc( iscan, is, band, &sca_num[isb], &det_num[isb],
114  &sat_zn[is], &sat_az[is], &sun_zn[is], &sun_az[is] );
115 
116  if ( status != SUCCESS )
117  {
118  fprintf(stderr,
119  "-E- %s line %d: Error Evaluating angles in band %d.\n",
120  __FILE__, __LINE__,band);
121  exit (EXIT_FAILURE);
122  }
123  // Populate the nominal values as band averages
124  /* Average the bands and convert to decimal degrees */
125  /* printf("band=%d sat_zn[%d]=%d, sun_zn = %d\n",band, is,sat_zn[is], sun_zn[is]); */
126 
127  //printf("sat_az[%d]=%d, sena[%d]=%f\n",is,sat_az[is],is,sena[is]);
128  if (isGeomPerBand)
129  {
130  senz[isb] = sat_zn[is];
131  sena[isb] = sat_az[is];
132  solz[isb] = sun_zn[is];
133  sola[isb] = sun_az[is];
134  } else {
135  senz[is] += (float) sat_zn[is] / MAXBAND;
136  sena[is] += (float) sat_az[is] / MAXBAND;
137  solz[is] += (float) sun_zn[is] / MAXBAND;
138  sola[is] += (float) sun_az[is] / MAXBAND;
139  }
140  }
141  }
142 
143 /* for ( is=0; is<npix; is+=10) {
144  printf("sena[%d]=%f\n",is,sena[is]);
145  printf("sat_az[%d]=%d\n",is,sat_az[is]);
146  }*/
147  /* Free the angle arrays */
148  free( sat_zn );
149  free( sat_az );
150  free( sun_zn );
151  free( sun_az );
152 
153  /* Release the metadata */
154  //smeta_close(); /* Probably should close this properly somewhere after processing */
155  firstCall = 0;
156  return (SUCCESS);
157 }
#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 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
int smeta_init(char *smeta_filename)
Definition: smeta_api.c:11
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 smeta_close()
Definition: smeta_api.c:238
int get_oli_nom_angles(char *meta_filename, int32_t npix, int32_t nscan, int32_t iscan, float *solz, float *sola, float *senz, float *sena, short *sca_num, short *det_num, int32_t isGeomPerBand)
int smeta_get_frame(int band_index, META_FRAME *frame)
Definition: smeta_api.c:129
#define MAXBAND
int32_t nband
int smeta_calc(int in_line, int in_samp, int in_band, short *sca_num, short *det_num, double *sat_zn, double *sat_az, double *sun_zn, double *sun_az)
Definition: smeta_api.c:164
int32_t iscan
int npix
Definition: get_cmp.c:27