OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
emeta_geometry.c
Go to the documentation of this file.
1 /*
2  * Name: emeta_geometry.c
3  *
4  * Purpose:
5  * Source file containing the functions used to relate Level 1T pixel line/sample
6  * coordinates to the corresponding viewing and solar illumination angles. These functions
7  * operate on the EMETA data type defined in "emeta.h".
8  */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdarg.h>
13 #include <math.h>
14 #include "ias_logging.h"
15 #include "ias_const.h"
16 #include "emeta_geometry.h" /* Definition of EMETA structure and
17  function prototypes. */
18 #define PIX_BUFFER 3 /* Resampling kernel reduction in effective SCA size */
19 
21  EMETA_BAND *emeta_band, /* Enhanced metadata band structure */
22  double l1t_line, /* Input L1T line coordinate */
23  double l1t_samp, /* Input L1T sample coordinate */
24  double height, /* Input L1T height coordinate */
25  int *sca_list, /* Array of SCA numbers containing point */
26  double *l1r_line, /* Array of L1R line coordinates by SCA */
27  double *l1r_samp ) /* Array of L1R sample coordinates by SCA */
28 {
29  int nsca; /* Number of SCAs covering the point (0-2) */
30  int isca; /* SCA index */
31  double l1t_l; /* Offset L1T line coordinate */
32  double l1t_s; /* Offset L1T sample coordinate */
33  double l1t_h; /* Offset L1T height coordinate */
34  double l1r_l; /* RPC value of current L1R line */
35  double l1r_s; /* RPC value of current L1R sample */
36 
37  /* Loop through the SCAs */
38  nsca = 0;
39  for ( isca=0; isca<emeta_band->nsca; isca++ )
40  {
41  /* Evaluate the RPCs for the current SCA */
42  l1t_l = l1t_line - emeta_band->rpc[isca].mean_l1t[0];
43  l1t_s = l1t_samp - emeta_band->rpc[isca].mean_l1t[1];
44  l1t_h = height - emeta_band->rpc[isca].mean_hgt;
45  l1r_l = (emeta_band->rpc[isca].line_num[0] + emeta_band->rpc[isca].line_num[1]*l1t_l
46  + emeta_band->rpc[isca].line_num[2]*l1t_s + emeta_band->rpc[isca].line_num[3]*l1t_h
47  + emeta_band->rpc[isca].line_num[4]*l1t_l*l1t_s)
48  / (1.0 + emeta_band->rpc[isca].line_den[0]*l1t_l + emeta_band->rpc[isca].line_den[1]*l1t_s
49  + emeta_band->rpc[isca].line_den[2]*l1t_h + emeta_band->rpc[isca].line_den[3]*l1t_l*l1t_s)
50  + emeta_band->rpc[isca].mean_l1r[0];
51  l1r_s = (emeta_band->rpc[isca].samp_num[0] + emeta_band->rpc[isca].samp_num[1]*l1t_l
52  + emeta_band->rpc[isca].samp_num[2]*l1t_s + emeta_band->rpc[isca].samp_num[3]*l1t_h
53  + emeta_band->rpc[isca].samp_num[4]*l1t_l*l1t_s)
54  / (1.0 + emeta_band->rpc[isca].samp_den[0]*l1t_l + emeta_band->rpc[isca].samp_den[1]*l1t_s
55  + emeta_band->rpc[isca].samp_den[2]*l1t_h + emeta_band->rpc[isca].samp_den[3]*l1t_l*l1t_s)
56  + emeta_band->rpc[isca].mean_l1r[1];
57  /* See if this is a valid point for the current SCA */
58  if ( l1r_l >= PIX_BUFFER && l1r_l <= (emeta_band->l1r_lines-1-PIX_BUFFER) &&
59  l1r_s >= PIX_BUFFER && l1r_s <= (emeta_band->l1r_samps-1-PIX_BUFFER) )
60  {
61  if ( nsca > 1 )
62  {
63  IAS_LOG_ERROR("Too many valid SCAs found.");
64  return(0);
65  }
66  l1r_line[nsca] = l1r_l;
67  l1r_samp[nsca] = l1r_s;
68  sca_list[nsca] = emeta_band->rpc[isca].sca_num;
69  nsca++;
70  }
71  }
72 
73  return(nsca);
74 }
75 
77  EMETA *emeta, /* Input enhanced metadata info */
78  int band ) /* Input band number */
79 {
80  int i; /* Loop index */
81  int band_index; /* Index corresponding to input band number */
82 
83  /* Look for the input band number in the metadata band list */
84  band_index = -1;
85  for ( i=0; i<emeta->num_band; i++ )
86  {
87  if ( band == emeta->band_emeta[i].band )
88  {
89  band_index = i;
90  break;
91  }
92  }
93 
94  return(band_index);
95 }
96 
#define PIX_BUFFER
#define IAS_LOG_ERROR(format,...)
Definition: ias_logging.h:96
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 num_band
Definition: emeta.h:107
double mean_l1t[2]
Definition: emeta.h:34
double samp_num[NUM_RPC_COEF]
Definition: emeta.h:38
double samp_den[NUM_RPC_COEF-1]
Definition: emeta.h:39
int l1r_samps
Definition: emeta.h:86
int emeta_band_number_to_index(EMETA *emeta, int band)
double mean_l1r[2]
Definition: emeta.h:33
EMETA_BAND band_emeta[IAS_MAX_NBANDS]
Definition: emeta.h:108
Definition: emeta.h:102
double line_num[NUM_RPC_COEF]
Definition: emeta.h:36
double line_den[NUM_RPC_COEF-1]
Definition: emeta.h:37
double mean_hgt
Definition: emeta.h:35
EMETA_IMG_RPC rpc[IAS_MAX_NSCAS]
Definition: emeta.h:93
int emeta_l1t_to_l1r(EMETA_BAND *emeta_band, double l1t_line, double l1t_samp, double height, int *sca_list, double *l1r_line, double *l1r_samp)
int i
Definition: decode_rs.h:71
int sca_num
Definition: emeta.h:32
int nsca
Definition: emeta.h:82
int l1r_lines
Definition: emeta.h:85
int band
Definition: emeta.h:81