OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_get_inst_mirr_normal.c
Go to the documentation of this file.
1 /* file: GEO_get_inst_mirr_normal.c */
2 
3 #include "PGS_MODIS_35251.h"
4 #include "smfio.h"
5 #include "GEO_inst.h"
6 #include "GEO_parameters.h"
7 #include "GEO_util.h"
8 
10  const int scan_number,
11  const int sample_number,
12  double n_inst_normal[3]
13  )
14 /*
15 !C*****************************************************************************
16 !Description:
17  Routine in Instrument Model of the Level-1A geolocation
18  software to calculate the mirror normal vector for a sample.
19  It calls functions to interpolate the mirror encoder data
20  to the sample and convert the encoder value to an angle.
21  It then computes the mirror normal vector using the mirror
22  wedge angles (alpha, beta, gammaa) and axis error, and
23  transforms the vector to the instrument coordinate frame.
24  Reference Geolocation ATBD pp. 34-49.
25  (Note that spelling of gammaa avoids confusion with gamma()
26  function of math library.)
27 
28 !Input Parameters:
29  int scan_number - the scan number
30  int sample_number - the sample number in the ideal band
31 
32 !Output Parameters:
33  double n_inst_normal[3] - the unit mirr normal vector in
34  instrument coordinates
35 
36 Return parameter:
37  int err_stat - error status
38 
39 Global variables:
40  double alpha - mirr wedge error alpha
41  double beta - mirr wedge error beta
42  double gammaa - mirr wedge error gamma
43  double mirr_side1_range[2] - range of side 1 mirror angles
44  double T_mirr2inst[3][3] - transformation matrix from mirror
45  to instrument coord.
46 
47 Call functions:
48  int GEO_interp_mirr_enc(int, int, double) - interpolate mirror
49  encoder to sample time
50  int GEO_interp_mirr_ang(double, double) - compute mirror angle
51  from encoder value
52  int GEO_vec_unit3(double vec[3], vec_unit[3]) - get unit
53  vector of a vec
54  int GEO_mat_vec_mul3(double mat[3][3], double vec1[3],
55  double vec[3]) - Multiply a vector by a matrix.
56  modsmf(MODIS_X_MNEMONIC_STRING, "user message string", "function,
57  GEO_get_inst_mirr_normal.c") - writes error status messages to log
58 
59 !Revision History:
60  $Log: GEO_get_inst_mirr_normal.c,v $
61  Revision 1.7 1997/07/21 16:24:34 kuyper
62  Baselined Version 1
63 
64  * Revision 1.7 1997/03/26 18:05:45 fhliang
65  * Initial revision of SDST delivery of GEO_get_inst_mirr_normal.c.
66  *
67  Revision 1.6 1997/02/13 19:36:08 kuyper
68  Merged seed files.
69 
70  Revision 1.5 1996/09/23 19:34:56 kuyper
71  Corrected sign of gammaa in n_normal_side[0] calculation.
72 
73  Revision 1.4 1996/07/24 21:01:57 kuyper
74  Standardized order of #include files.
75  Declared arguments const.
76 
77  Revision 1.3 1996/07/23 23:06:06 kuyper
78  Inserted required '!' in comments.
79  Removed ret_val, i, j.
80 
81  Revision 1.2 1996/07/18 16:35:12 kuyper
82  Included self-checking header file.
83  Replaced extern declarations with corresponding header files.
84  Added required header files.
85  Converted int constants to double, to avoid conversion lint warnings.
86  James Kuyper kuyper@ltpmail.gsfc.nasa.gov
87 
88 
89  4/25/95
90  Ruiming Chen
91  Finished coding.
92 
93  6/12/95
94  Frederick S. Patt (patt@modis-xl.gsfc.nasa.gov)
95  Expanded description.
96 
97  6/21/95
98  Frederick S. Patt (patt@modis-xl.gsfc.nasa.gov)
99  Added mirror side angle range as a parameter.
100 
101  6/30/95
102  Tracey W. Holmes (holmes@modis-xl.gsfc.nasa.gov)
103  Added SDP error messages.
104 
105  10/10/95
106  Tracey W. Holmes
107  Added debug option.
108 
109 
110 !Team-unique Header:
111  This software is developed by the MODIS Science Data Support
112  Team for the National Aeronautics and Space Administration,
113  Goddard Space Flight Center, under contract NAS5-32373.
114 
115 !END*************************************************************************
116 */
117 {
118 
119 
120 /***************************************************************************
121 declare local variables
122 ***************************************************************************/
123 
124  double sample_mirr_ang = 0.0; /* mirr angle for the sample */
125  double sample_enc = 0.0; /* encoder number for the sample */
126  double T_rot[3][3] = {0.0}; /* The mirror rotation matrix */
127  double n_normal_side[3] = {0.0}; /* mirr normal side vector */
128  double n_mirr_normal[3] = {0.0}; /* mirr normal */
129  double n_inst[3] = {0.0}; /* mirr normal in the instrument coord. */
130 
131 
132 /***************************************************************************
133 calculation from here
134 ***************************************************************************/
135 
136  /* calculate encoder position */
137  if (GEO_interp_mirr_enc(scan_number, sample_number, &sample_enc) == FAIL) {
138  /* call SDP function to report error */
139  modsmf(MODIS_E_GEO_INT_MIRR_ENC, "",
140  "GEO_interp_mirr_enc, GEO_get_inst_mirr_normal.c");
141 
142  return FAIL;
143  }
144 
145  /* compute the scan mirror angle */
146  if (GEO_interp_mirr_ang(sample_enc, &sample_mirr_ang) == FAIL)
147  {
148  /* call SDP function to report error */
149  modsmf(MODIS_E_GEO_INT_MIRR_ANG, "",
150  "GEO_interp_mirr_ang, GEO_get_inst_mirr_normal.c");
151 
152  return FAIL;
153  }
154 
155  /* construct T_rot */
156  T_rot[0][0] = 1.0;
157  T_rot[1][1] = cos(sample_mirr_ang);
158  T_rot[1][2] = - sin(sample_mirr_ang);
159  T_rot[2][1] = sin(sample_mirr_ang);
160  T_rot[2][2] = cos(sample_mirr_ang);
161 
162  /* construct n_normal_side */
163  if (sample_mirr_ang > mirr_side1_range[0] &&
164  sample_mirr_ang <= mirr_side1_range[1]) {
165  n_normal_side[0] = - sin(beta/2.0 + gammaa);
166  n_normal_side[1] = sin(alpha/2.0) * cos(beta/2.0 + gammaa);
167  n_normal_side[2] = cos(alpha/2.0) * cos(beta/2.0 + gammaa);
168  }
169 
170  else {
171  n_normal_side[0] = - sin(beta/2.0 - gammaa);
172  n_normal_side[1] = sin(alpha/2.0) * cos(beta/2.0 - gammaa);
173  n_normal_side[2] = - cos(alpha/2.0) * cos(beta/2.0 - gammaa);
174  }
175 
176  /* get n_mirr_normal */
177  GEO_mat_vec_mul3(T_rot, n_normal_side, n_mirr_normal);
178 
179  /* get n_inst */
180  GEO_mat_vec_mul3(T_mirr2inst, n_mirr_normal, n_inst);
181 
182  /* calculate n_inst_normal */
183  if (GEO_vec_unit3(n_inst, n_inst_normal) == FAIL) {
184  /* call SDP function to report error */
185  modsmf(MODIS_E_GEO_VEC_UNIT3, "",
186  "GEO_vec_unit3, GEO_get_inst_mirr_normal.c");
187 
188  return FAIL;
189  }
190 
191  return SUCCESS;
192 }
double gammaa
#define SUCCESS
Definition: ObpgReadGrid.h:15
#define MODIS_E_GEO_VEC_UNIT3
#define FAIL
Definition: ObpgReadGrid.h:18
double T_mirr2inst[3][3]
int GEO_vec_unit3(double vec[3], double unit_vec[3])
Definition: GEO_vec_unit3.c:9
int GEO_get_inst_mirr_normal(const int scan_number, const int sample_number, double n_inst_normal[3])
#define MODIS_E_GEO_INT_MIRR_ENC
int GEO_interp_mirr_ang(double const sample_enc, double *const sample_mirr_ang)
int GEO_interp_mirr_enc(int const scan_number, int const sample_number, double *const sample_enc)
#define MODIS_E_GEO_INT_MIRR_ANG
void GEO_mat_vec_mul3(double mat[3][3], double vec1[3], double vec[3])
double beta
double mirr_side1_range[2]