OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_height.c
Go to the documentation of this file.
1 #include "l12_proto.h"
2 #define MAX_LAT 89.95
3 
4 /* DEM interpolation function prototypes */
5 int interp_nc_height(float *xlon, float *xlat, float *height);
6 int interp_dem_height(float *xlon, float *xlat, float *height);
7 static int (*interp_height)(float *xlon, float *xlat, float *height);
8 
9 /* Terrain correction function prototypes */
10 int get_nc_height(
11  float *lon, float *lat,
12  float *senz, float *sena,
13  float *height);
14 int get_dem_height(
15  float *lon, float *lat,
16  float *senz, float *sena,
17  float *height);
18 static int (*correct_terrain)(
19  float *lon, float *lat,
20  float *senz, float *sena,
21  float *height);
22 
31 int get_height(l1str *l1rec, int32_t ip, int terrain_corrected) {
32  static int firstCall = 1;
33  int status = 1;
34  float *xlon = &l1rec->lon [ip];
35  float *xlat = &l1rec->lat [ip];
36  float *senz = &l1rec->senz[ip];
37  float *sena = &l1rec->sena[ip];
38  float *height = &l1rec->height[ip];
39  /*
40  * for band-dependent view angles, we currently do not have a
41  * band-dependent height, which would be the exact treatment.
42  * Seeing as the view angle change is small, the height should not
43  * vary enough to be of concern. However, the nominal sensor zenith
44  * angle gets a correction and that amount of correction should be
45  * applied to the band-dependent sensor zenith angles, if applicable
46  * (see code after call to correct_terrain)
47  */
48  float senz_sav;
49 
50  /* Initial file tests */
51  if (firstCall) {
52  int ncid;
53  int netcdf_dem;
54  firstCall = 0;
55 
56  /* input file defined? */
57  if (input->demfile == NULL || input->demfile[0] == 0) {
58  fprintf(stderr, "-E- %s line %d: "
59  "Elevation file is NULL.\n",
60  __FILE__, __LINE__);
61  return 1;
62  }
63  printf("Loading DEM info from %s\n", input->demfile);
64 
65  /* test for NetCDF input file */
66  if(Hishdf(input->demfile))
67  status = NC2_ERR;
68  else
69  status = nc_open(input->demfile, NC_NOWRITE, &ncid);
70 
71  netcdf_dem = (status == NC_NOERR);
72  if (netcdf_dem) nc_close(ncid);
73 
74  /* set function pointers according to input file type */
75  if (netcdf_dem) {
76  interp_height = interp_nc_height;
77  correct_terrain = get_nc_height;
78  } else {
79  interp_height = interp_dem_height;
80  correct_terrain = get_dem_height;
81  }
82  }
83 
84  /* Interpolate DEM height if terrain correction already done,
85  or target too close to poles */
86  if (terrain_corrected
87  || (fabs((double) *xlat) > MAX_LAT)) {
88  status = interp_height(xlon, xlat, height);
89  if (status) {
90  fprintf(stderr, "-E- %s line %d: interp_height():\n",
91  __FILE__, __LINE__);
92  fprintf(stderr,
93  "xlon=%f xlat=%f height=%f\n",
94  (double) *xlon, (double) *xlat, (double) *height);
95  }
96  }
97  /* Otherwise, do terrain correction */
98  else {
99  senz_sav = *senz;
100  status = correct_terrain(xlon, xlat, senz, sena, height);
101  if (status) {
102  fprintf(stderr, "-E- %s line %d: correct_terrain():\n",
103  __FILE__, __LINE__);
104  fprintf(stderr,
105  "xlon=%f xlat=%f senz=%f sena=%f height=%f\n",
106  (double) *xlon, (double) *xlat,
107  (double) *senz, (double) *sena, (double) *height);
108  }
109  if (l1rec->geom_per_band != NULL) {
110  float senz_corr = *senz - senz_sav;
111  int32_t nwave = l1rec->l1file->nbands, iw;
112  for (iw = 0; iw < nwave; iw++) {
113  l1rec->geom_per_band->senz[ ip * nwave + iw ] += senz_corr;
114  }
115  }
116  }
117  return status;
118 }
int status
Definition: l1_czcs_hdf.c:32
int interp_dem_height(float *xlon, float *xlat, float *height)
#define MAX_LAT
Definition: get_height.c:2
int get_height(l1str *l1rec, int32_t ip, int terrain_corrected)
Definition: get_height.c:31
#define NULL
Definition: decode_rs.h:63
read l1rec
float * lat
int get_nc_height(float *lon, float *lat, float *senz, float *sena, float *height)
instr * input
int interp_nc_height(float *xlon, float *xlat, float *height)
int get_dem_height(float *lon, float *lat, float *senz, float *sena, float *height)
float xlon[LAC_PIXEL_NUM]
Definition: l1a_seawifs.c:93
#define fabs(a)
Definition: misc.h:93
float * lon