OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
b128_box_num.c
Go to the documentation of this file.
1 #include <math.h>
2 
3 int b128_box_num(float lat, float lon, float *lat_off, float *lon_off)
4 /*******************************************************************
5 
6  b128_box_num
7 
8  purpose: for the 128 / degree land mask file, find the
9  index of the degree box from the lat, lon
10 
11  Returns type: int - index (0 rel) of the 1 degree box
12 
13  Parameters: (in calling order)
14  Type Name I/O Description
15  ---- ---- --- -----------
16  float lat I latitude of point from
17  -90. to 90.
18  float lon I longitudeof point from
19  -180 to 180.
20  float * lat_off O all positive latitude used
21  during call to
22  b128_wd_bit to get mask
23  at a 128th of a degree point
24  float * lon_off O all positive longitude
25 
26  Modification history:
27  Programmer Date Description of change
28  ---------- ---- ---------------------
29  W. Robinson 8-Oct-1997 Original development
30 
31  *******************************************************************/ {
32  int box_num, lat_index, lon_index;
33  /*
34  * make positive lat and lon and check them
35  */
36  *lat_off = 90. + lat;
37  *lon_off = 180. + lon;
38 
39  if (*lat_off < 0.) *lat_off = 0.;
40  if (*lat_off > 180.) *lat_off = 180.;
41  if (*lon_off < 0.) *lon_off = 0.;
42  if (*lon_off > 360.) *lon_off = 360.;
43  /*
44  * Take care of case of 90 lat and 180 lon properly
45  */
46  lat_index = (*lat_off == 180.) ? 179 : (int) (*lat_off);
47  lon_index = (*lon_off == 360.) ? 359 : (int) (*lon_off);
48  /*
49  * compute the box #
50  */
51  box_num = lon_index + 360 * lat_index;
52 
53  return box_num;
54 }
float * lat
int b128_box_num(float lat, float lon, float *lat_off, float *lon_off)
Definition: b128_box_num.c:3
float * lon