Due to the lapse in federal government funding, NASA is not updating this website. We sincerely regret this inconvenience.
NASA Logo
Ocean Color Science Software

ocssw V2022
sunangs.c
Go to the documentation of this file.
1 //
2 // Created by alex on 11/25/23.
3 //
4 #include "libnav.h"
5 #include "nav.h"
6 #include "sun2000.h"
25 void sunangs_(int *iyr, int *iday, float *gmt, float *xlon, float *ylat, float *sunz, float *suna) {
26  // Compute sun vector
27  // Compute unit sun vector in geocentric inertial coordinates
28  double sec = *gmt * 3600.0e0;
29  float rs, suni[3], sung[3], up[3], ea[3], no[3];
30  sun2000(*iyr, *iday, sec, suni, &rs);
31  double day = *iday + sec / 3600.00 / 24.0;
32  double gha;
33  // Get Greenwich mean sidereal angle
34  gha2000(*iyr, day, &gha);
35  const double ghar = gha / radeg;
36  // Transform Sun vector into geocentric rotating frame
37  sung[0] = suni[0] * cos(ghar) + suni[1] * sin(ghar);
38  sung[1] = suni[1] * cos(ghar) - suni[0] * sin(ghar);
39  sung[2] = suni[2];
40  // c Convert geodetic lat/lon to Earth-centered, earth-fixed (ECEF)
41  // c vector (geodetic unit vector)
42  const double rlon = *xlon / radeg;
43  const double rlat = *ylat / radeg;
44  const double cosy = cos(rlat);
45  const double siny = sin(rlat);
46  const double cosx = cos(rlon);
47  const double sinx = sin(rlon);
48  up[0] = cosy * cosx;
49  up[1] = cosy * sinx;
50  up[2] = siny;
51  // c
52  // c Compute the local East and North unit vectors
53  const double upxy = sqrt(up[0] * up[0] + up[1] * up[1]);
54  ea[0] = -up[1] / upxy;
55  ea[1] = up[0] / upxy;
56  ea[2] = 0.0e0;
57  no[0] = up[1] * ea[2] - up[2] * ea[1]; // !cross product
58  no[1] = up[2] * ea[0] - up[0] * ea[2];
59  no[2] = up[0] * ea[1] - up[1] * ea[0];
60  // c Compute components of spacecraft and sun vector in the
61  // c vertical (up), North (no), and East (ea) vectors frame
62  double sunv = 0.0;
63  double sunn = 0.0;
64  double sune = 0.0;
65  for (int j = 0; j < 3; j++) {
66  sunv = sunv + sung[j] * up[j];
67  sunn = sunn + sung[j] * no[j];
68  sune = sune + sung[j] * ea[j];
69  }
70  // c
71  // c Compute the solar zenith and azimuth
72  *sunz = radeg * atan2(sqrt(sunn * sunn + sune * sune), sunv);
73  // c Check for zenith close to zero
74  if (*sunz > 0.05e0)
75  *suna = radeg * atan2(sune, sunn);
76  else
77  *suna = 0.0e0;
78  if (*suna < 0.0e0)
79  *suna = *suna + 360.0e0;
80 }
int j
Definition: decode_rs.h:73
int32_t day
float ylat[LAC_PIXEL_NUM]
Definition: l1a_seawifs.c:92
int gha2000(int32_t iyr, double day, double &gha)
int sun2000(size_t sdim, int32_t iyr, int32_t idy, double *sec, orb_array *sun)
float xlon[LAC_PIXEL_NUM]
Definition: l1a_seawifs.c:93
void sunangs_(int *iyr, int *iday, float *gmt, float *xlon, float *ylat, float *sunz, float *suna)
Definition: sunangs.c:25
int32_t iyr
Definition: atrem_corl1.h:161