OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_nitrate.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <math.h>
3 #include "l12_proto.h"
4 #include "get_nitrate.h"
5 
6 /*
7  * Calculating Global and Basin Scale Maps of Sea surface Nitrate from Chlorophyll and SST using Empirical Algorithms.
8  * Modified by Joaquim Goes - 24 Aug 2017
9  * Implemented into l2gen by Robert Lossing May 2019
10  */
11 
12 float calc_nitrate(float chl, float sst, float lat, float lon) {
13 
14 // Initiating Variables
15 
16  float no3;
17  float nitrate = BAD_FLT;
18 
19  if (chl < 0) {
20  return nitrate;
21  }
22 
23  if (chl == BAD_FLT) {
24  return nitrate;
25  }
26 
27  no3 = 25.68 - 1.97 * sst + 0.04 * pow(sst, 2) - 1.63 * chl
28  + 0.012 * pow(chl, 2);
29 
30 // If Equatorial (Latitude: 30 degrees N and 18.33 degrees S):
31 
32  if (lat <= 30 && lat >= -18.333 && sst > 20 && chl > 0.24 && chl < 10) {
33  no3 = 345.41 - 23.4 * sst + 0.4 * pow(sst, 2) + 0.012 * chl
34  - pow(chl, 2) * 0.00048;
35  }
36 
37 // If Tropical Gyres:
38 
39  if (sst > 28 && chl >= 0.3 && chl <= 2) {
40  no3 = 90.12 - 6.02 * sst + 0.09 * pow(sst, 2) - .05 * chl;
41  }
42 
43 // If Antartic (latitude) * and Arctic (latitude):
44 
45  if (sst < 2 && chl <= 2.2 && chl >= 0.1) {
46  no3 = 12.98 - 13.61 * sst - 4.16 * pow(sst, 2) - 4.97 * chl
47  + 0.267 * pow(chl, 2);
48  }
49 
50 // Condition 4 (Arabian Sea 45 degrees E and 86.666 E )
51 
52  if (lon >= 45 && lon <= 86.666 && lat <= 30 && lat >= 5) {
53  no3 = 119.14 - 8.38 * sst + 0.15 * pow(sst, 2) - .2 * chl;
54  }
55 
56 // All other regions:
57 
58  nitrate = no3;
59 
60  if (nitrate < 0) {
61  nitrate = 0;
62  }
63  if (nitrate > 40) {
64  nitrate = 40;
65  }
66  return nitrate;
67 
68 }
69 
70 void get_nitrate(l2str *l2rec, l2prodstr *p, float prod[]) {
71  int i;
72  int16_t year, day;
73  double sec;
74  unix2yds(l2rec->l1rec->scantime, &year, &day, &sec);
75 
76  l1str *l1rec = l2rec->l1rec;
77  l2rec->sst = get_sst(l2rec);
78 
79  for (i = 0; i < l1rec->npix; i++) {
80  if (l2rec->chl[i] == BAD_FLT) {
81  prod[i] = BAD_FLT;
82  continue;
83  }
84 
85  switch (p->cat_ix) {
86 
87  case CAT_nitrate:
88  prod[i] = calc_nitrate(l2rec->chl[i], l2rec->sst[i], l1rec->lat[i], l1rec->lon[i]);
89  break;
90 
91  default:
92  printf("get_nitrate.c can not produce product %s\n",
93  p->algorithm_id);
94  exit(1);
95  }
96 
97  if (isnan(prod[i])) {
98  prod[i] = BAD_FLT;
99  l1rec->flags[i] |= PRODFAIL;
100 
101  }
102  }
103 }
int32_t day
read l1rec
float * lat
#define PRODFAIL
Definition: l2_flags.h:41
#define CAT_nitrate
Definition: l2prod.h:388
float * get_sst(l2str *l2rec)
Definition: sst.c:7606
void unix2yds(double usec, short *year, short *day, double *secs)
void get_nitrate(l2str *l2rec, l2prodstr *p, float prod[])
Definition: get_nitrate.c:70
#define BAD_FLT
Definition: jplaeriallib.h:19
float calc_nitrate(float chl, float sst, float lat, float lon)
Definition: get_nitrate.c:12
float * lon
int i
Definition: decode_rs.h:71
float p[MODELMAX]
Definition: atrem_corl1.h:131