NASA Logo
Ocean Color Science Software

ocssw V2022
nav.c
Go to the documentation of this file.
1 #include "nav.h"
2 
3 double norm(const double* vec, size_t n) {
4  return sqrt(square(vec, n));
5 }
6 
7 double square(const double* vec, size_t n) {
8  double norm_ = 0.0;
9  for (size_t i = 0; i < n; i++) {
10  norm_ += vec[i] * vec[i];
11  }
12  return norm_;
13 }
14 
15 double dot(const double* vec1, const double* vec2, size_t n) {
16  double ans = 0;
17  for (size_t i = 0; i < n; i++) {
18  ans += vec1[i] * vec2[i];
19  }
20  return ans;
21 }
22 
23 double dmod(double a, double p) {
24  return a - ((int32_t)(a / p) * p);
25 }
26 
27 
28 
29 
30 double julian(double tin[2]) {
31  const static double d0 = 2415020.5e0, d1 = 1.e-4, d2 = 1.e-2, d3 = 24.e0, d4 = 1.44e3, d5 = 8.64e4;
32  double tout = d0;
33  int32_t iy = (int)(tin[0] * d1 - 1.9e3);
34  int32_t im = (int)(tin[0] * d2 - 1.9e5) - iy * 100;
35  int32_t id = (int)(tin[0] - 1.9e7) - iy * 10000 - im * 100;
36  int32_t ihour = (int)(tin[1] * d1);
37  int32_t imin = (int)(tin[1] * d2) - ihour * 100;
38  double sec = tin[1] - ihour * 10000 - imin * 100;
39  int32_t jd = iy * 365 + (iy - 1) / 4;
40  int32_t im1 = im - 1;
41  switch (im1) {
42  case 1:
43  jd += 31;
44  break;
45  case 2:
46  jd += 59;
47  break;
48  case 3:
49  jd += 90;
50  break;
51  case 4:
52  jd += 120;
53  break;
54  case 5:
55  jd += 151;
56  break;
57  case 6:
58  jd += 181;
59  break;
60  case 7:
61  jd += 212;
62  break;
63  case 8:
64  jd += 243;
65  break;
66  case 9:
67  jd += 273;
68  break;
69  case 10:
70  jd += 304;
71  break;
72  case 11:
73  jd += 334;
74  break;
75  default:
76  break;
77  }
78  if (iy / 4 * 4 - iy == 0 && im > 2)
79  jd += 1;
80  jd += id - 1;
81  tout += (double)jd + (double)ihour / d3 + (double)imin / d4 + sec / d5;
82  return tout;
83 }
84 
85 
86 void jdate(int jd, int* i, int* k) {
87  // c Compute days since January 0, 1900
88  int l = jd - 2415020;
89 
90  // c Compute years since 1900
91  *i = 4 * l / 1461;
92 
93  // c Compute day-of-year
94  *k = l - 1461 * (*i - 1) / 4 - 365;
95 
96  // c Add first two digits of year
97  *i = *i + 1900;
98 }
99 
100 void jddate(int jd, int* i, int* j, int* k) {
101  int l = jd + 68569;
102  int n = 4 * l / 146097;
103  l = l - (146097 * n + 3) / 4;
104  *i = 4000 * (l + 1) / 1461001;
105  l = l - 1461 * *i / 4 + 31;
106  *j = 80 * l / 2447;
107  *k = l - 2447 * *j / 80;
108  l = *j / 11;
109  *j = *j + 2 - 12 * l;
110  *i = 100 * (n - 49) + *i + l;
111 }
112 
113 void ymdhms2jul(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, double sec,
114  double* jul) {
115  *jul = jd(year, month, day) + (hour * 3600.e0 + minute * 60.e0 + sec) / 86400.e0;
116 }
117 
118 
119 int32_t jd(int32_t i, int32_t j, int32_t k) {
120  return 367 * i - 7 * (i + (j + 9) / 12) / 4 + 275 * j / 9 + k + 1721014;
121  // c This additional calculation is needed only for dates outside of the
122  // c period March 1, 1900 to February 28, 2100
123  // c jd = jd + 15 - 3*((i+(j-9)/7)/100+1)/4
124 };
void jddate(int jd, int *i, int *j, int *k)
Construct a new ddate objectC C This routine computes the calendar date corresponding to C a given Ju...
Definition: nav.c:100
int j
Definition: decode_rs.h:73
int32_t day
double norm(const double *vec, size_t n)
computes the norm of a vector
Definition: nav.c:3
int32_t im
Definition: atrem_corl1.h:161
void jdate(int jd, int *i, int *k)
Definition: nav.c:86
double square(const double *vec, size_t n)
computes the square of the norm of a vector
Definition: nav.c:7
void ymdhms2jul(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, double sec, double *jul)
c ----------------------------------------------------------— c Subroutine ymdhms2jul c c Convers fro...
Definition: nav.c:113
int32_t jd(int32_t i, int32_t j, int32_t k)
c This function converts a calendar date to the corresponding Julian day starting at noon on the cale...
Definition: nav.c:119
Definition: jd.py:1
integer, parameter double
double julian(double tin[2])
Definition: nav.c:30
double dmod(double a, double p)
Description:
Definition: nav.c:23
int i
Definition: decode_rs.h:71
double dot(const double *vec1, const double *vec2, size_t n)
computes the scalar/dot product of two vectors
Definition: nav.c:15
PGE01 indicating that PGE02 PGE01 V6 for and PGE01 V2 for MOD03 were used to produce the granule By convention adopted in all MODIS Terra PGE02 code versions are The fourth digit of the PGE02 version denotes the LUT version used to produce the granule The source of the metadata environment variable ProcessingCenter was changed from a QA LUT value to the Process Configuration A sign used in error in the second order term was changed to a
Definition: HISTORY.txt:424
int k
Definition: decode_rs.h:73
float p[MODELMAX]
Definition: atrem_corl1.h:131