NASA Logo
Ocean Color Science Software

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