OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_l57tm_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_l57tm_nom_angles( char *meta_filename, int32_t npix, int32_t nscan, int32_t iscan,
15  float *solz, float *sola, float *senz, float *sena)
16 {
17  static int firstCall = 1;
18  static int nband; /* Number of bands */
19  static META_FRAME frame[MAXBAND]; /* Output image frame info */
20  int band; /* User band number */
21  int band_index; /* Band index */
22  int is; /* Sample (pixel) index */
23  int status; /* Status return flag */
24  short *sat_zn; /* Satellite zenith angle */
25  short *sat_az; /* Satellite azimuth angle */
26  short *sun_zn; /* Solar zenith angle */
27  short *sun_az; /* Solar azimuth angle */
28 
29  if (firstCall == 1) {
30  /* Initialize the metadata package */
31  if ( (nband = smeta_init( meta_filename )) < 1 )
32  {
33  IAS_LOG_ERROR("Initializing the metadata file %s.", meta_filename);
34  fprintf(stderr,
35  "-E- %s line %d: Initializing the metadata file %s.\n",
36  __FILE__, __LINE__, meta_filename);
37  exit (EXIT_FAILURE);
38  }
39  }
40 
41 
42  /* printf("nband = %d\n", nband); we get nband = 7 */
43 
44  /* Allocate the intermediary buffers for calculating average over MAXBAND*/
45  if ( (sat_zn = (short *)malloc( npix*sizeof(short) )) == NULL )
46  {
47  smeta_close();
48  fprintf(stderr,
49  "-E- %s line %d: Unable to allocate satellite elevation angle array.\n",
50  __FILE__, __LINE__);
51  exit (EXIT_FAILURE);
52  }
53  if ( (sat_az = (short *)malloc( npix*sizeof(short) )) == NULL )
54  {
55  free(sat_zn);
56  smeta_close();
57  fprintf(stderr,
58  "-E- %s line %d: Unable to allocate satellite azimuth angle array.\n",
59  __FILE__, __LINE__);
60  exit (EXIT_FAILURE);
61  }
62  if ( (sun_zn = (short *)malloc( npix*sizeof(short) )) == NULL )
63  {
64  free(sat_zn);
65  free(sat_az);
66  smeta_close();
67  fprintf(stderr,
68  "-E- %s line %d: Unable to allocate solar elevation angle array.\n",
69  __FILE__, __LINE__);
70  exit (EXIT_FAILURE);
71  }
72  if ( (sun_az = (short *)malloc( npix*sizeof(short) )) == NULL )
73  {
74  free(sat_zn);
75  free(sat_az);
76  free(sun_zn);
77  smeta_close();
78  fprintf(stderr,
79  "-E- %s line %d: Unable to allocate solar azimuth angle array.\n",
80  __FILE__, __LINE__);
81  exit (EXIT_FAILURE);
82  }
83 
84  /* Initialize */
85  for ( is=0; is<npix; is++ )
86  {
87  senz[is] = 0;
88  sena[is] = 0;
89  solz[is] = 0;
90  sola[is] = 0;
91  }
92 
93  /* Process the angles for each band */
94  //printf("nbnd in get_l57tm_nom_angles = %d\n", nband);
95  for ( band_index=0; band_index<nband; band_index++ )
96  {
97  /* Get framing information for this band */
98  /* for Landsat 5 we need to skip band 6
99  for labndsat 7 we need to skip band 6 and 8 */
100  if ((band_index == 5) || (band_index == 7))
101  continue;
102 
103  if ( firstCall == 1 && smeta_get_frame( band_index, &frame[band_index] ) != SUCCESS )
104  {
105  fprintf(stderr,
106  "-E- %s line %d: Unable to get smeta frame.\n",
107  __FILE__, __LINE__);
108  exit (EXIT_FAILURE);
109  }
110  band = frame[band_index].band;
111  /* } */
112 
113 
114  //printf("band_index = %d, band = %d\n", band_index, band);
115 
116  //if ( (iscan) % 500 == 0 ) printf("GET_L57TM_NOM_ANGLES: Band/Line %d/%d\n", band, iscan );
117  /* Loop through the L1T lines and samples */
118  for ( is=0; is<npix; is++ )
119  {
120  status = smeta_calc_ls( (int) iscan, is, band, &sat_zn[is], &sat_az[is], &sun_zn[is], &sun_az[is] );
121  if ( status != SUCCESS )
122  {
123  fprintf(stderr,
124  "-E- %s line %d: Error Evaluating angles in band %d.\n",
125  __FILE__, __LINE__,band);
126  exit (EXIT_FAILURE);
127  }
128  /* Average the bands and convert to decimal degrees */
129  //printf("band=%d sat_zn[%d]=%d, sun_zn = %d\n",band, is,sat_zn[is], sun_zn[is]);
130  senz[is] += (float)sat_zn[is]/(100*(MAXBAND-1));
131  sena[is] += (float)sat_az[is]/(100*(MAXBAND-1));
132  solz[is] += (float)sun_zn[is]/(100*(MAXBAND-1));
133  sola[is] += (float)sun_az[is]/(100*(MAXBAND-1));
134  }
135  }
136 
137  /* for ( is=0; is<npix; is+=10)
138  {
139  printf("senz[%d]=%f\n",is,senz[is]);
140  printf("sena[%d]=%f\n",is,sena[is]);
141  printf("solz[%d]=%f\n",is,solz[is]);
142  printf("sola[%d]=%f\n",is,sola[is]);
143  } */
144 
145  /* Free the angle arrays */
146  free( sat_zn );
147  free( sat_az );
148  free( sun_zn );
149  free( sun_az );
150 
151  /* Release the metadata */
152  //smeta_close(); /* Probably should close this properly somewhere after processing */
153  firstCall = 0;
154  return (SUCCESS);
155 }
#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
#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
int get_l57tm_nom_angles(char *meta_filename, int32_t npix, int32_t nscan, int32_t iscan, float *solz, float *sola, float *senz, float *sena)
int smeta_calc_ls(int in_line, int in_samp, int in_band, short *sat_zn, short *sat_az, short *sun_zn, short *sun_az)
Definition: smeta_api.c:204
void smeta_close()
Definition: smeta_api.c:238
int smeta_get_frame(int band_index, META_FRAME *frame)
Definition: smeta_api.c:129
int32_t nband
int32_t iscan
int npix
Definition: get_cmp.c:27