OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
rd_rhos_scan.c
Go to the documentation of this file.
1 #include "viirs_sim_sdr.h"
2 #include "l12_parms.h"
3 #include <string.h>
4 #include <genutils.h>
5 
6 static h5io_str file_id, *dat_ids;
7 
8 int rd_rhos_scan(char *file, int npix, int iscn, int ndet, float **rhos)
9 /*-----------------------------------------------------------------------------
10  Program: rd_rhos_scan.c
11 
12  Description: read a scan of reflectance data
13 
14  Arguments:
15  Type Name I/O Description
16  ---- ---- --- -----------
17  char * file I file of reflectance
18  int npix I # pixels in a line
19  int iscn I scan to read
20  int ndet I # detector lines in a scan
21  float ** rhos O a scan's worth of reflectance
22 
23  Note that the reflectance in the file can be at wavelengths other than
24  the VIIRS wavelengths - the final reflectances will be interpolated to
25  VIIRS
26 
27  Modification history:
28 
29  W. Robinson, SAIC 18 Nov 2009 Original development
30  W. Robinson, SAIC 12 Mar 2010 modify for scan read
31 
32 ----------------------------------------------------------------------------*/ {
33  static float *lrhos, *out_rhos, lam_lst[30], viirs_bands[16];
34  static int first = 0, l_nlam;
35  float vec_rho[20], vec_lrho[20];
36  int ibnd, ipix, ilin, bndlist[MAX_BND], start[2], count[2];
37  int rd_rhos_open(char *, float *, int *);
38  /*
39  * for null file, clean up and exit
40  */
41  if (file == NULL) {
42  /* de-allocate storage, close file ids */
43  free(out_rhos);
44  free(lrhos);
45 
46  for (ibnd = 0; ibnd < l_nlam; ibnd++)
47  h5io_close(dat_ids + ibnd);
48  h5io_close(&file_id);
49  free(dat_ids);
50 
51  return 0;
52  }
53  /*
54  * initial time in, open the reflectance file
55  */
56  if (first == 0) {
57  first = 1;
58  /* open file and get the band list */
59  if (rd_rhos_open(file, lam_lst, &l_nlam) != 0)
60  return 1;
61  /* allocate rhos space for output */
62  if ((out_rhos = (float *)
63  malloc(npix * ndet * N_VNIR_BND * sizeof ( float))) == NULL) {
64  printf("%s, %d: Unable to allocate rhos output storage\n",
65  __FILE__, __LINE__);
66  return 1;
67  }
68  *rhos = out_rhos;
69  /* allocate local rhos space */
70  if ((lrhos = (float *)
71  malloc(npix * ndet * l_nlam * sizeof ( float))) == NULL) {
72  printf("%s, %d: Unable to allocate rhos storage\n",
73  __FILE__, __LINE__);
74  return 1;
75  }
76  /* get the viirs band list and keep in local storage */
77  if ((bnd_ix_2_sen_info("Lambda", (void *) bndlist)) < 0) {
78  printf("%s, %d: failure to read sensor information\n",
79  __FILE__, __LINE__);
80  }
81  for (ibnd = 0; ibnd < N_VNIR_BND; ibnd++)
82  *(viirs_bands + ibnd) = (float) *(bndlist + ibnd);
83  }
84  /*
85  * read the line's reflectance
86  */
87  ilin = iscn * ndet;
88  start[0] = ilin;
89  count[0] = ndet;
90  start[1] = 0;
91  count[1] = npix;
92  for (ibnd = 0; ibnd < l_nlam; ibnd++) {
93  if (h5io_rd_ds_slice(&dat_ids[ibnd], start, count,
94  (void *) (lrhos + npix * ndet * ibnd)) != 0) {
95  printf(
96  "%s, %d: Failed to read reflectance data set slice for line %d\n",
97  __FILE__, __LINE__, ilin);
98  return 1;
99  }
100  }
101  /*
102  * interpolate the values to the VIIRS bands
103  */
104  for (ilin = 0; ilin < ndet; ilin++) {
105  for (ipix = 0; ipix < npix; ipix++) {
106  for (ibnd = 0; ibnd < l_nlam; ibnd++)
107  vec_lrho[ibnd] = *(lrhos + ipix + (ilin + ibnd * ndet) * npix);
108  lspline(lam_lst, vec_lrho, l_nlam, viirs_bands, vec_rho, N_VNIR_BND);
109  for (ibnd = 0; ibnd < N_VNIR_BND; ibnd++)
110  *(out_rhos + ipix + (ilin + ibnd * ndet) * npix) = vec_rho[ibnd];
111  }
112  }
113  return 0;
114 }
115 
116 int rd_rhos_open(char *file, float *lam_lst, int *nlam)
117 /*-----------------------------------------------------------------------------
118  Program: rd_rhos_open
119 
120  Description: Open the reflectance file
121 
122  Arguments:
123  Type Name I/O Description
124  ---- ---- --- -----------
125  char * file I file of reflectance
126  float * lam_lst O list of wavelengths in the file
127  int * nlam O # of wavelengths
128 
129  Modification history:
130 
131  W. Robinson, SAIC 18 Nov 2009 Original development
132 
133 ----------------------------------------------------------------------------*/ {
134  char *sloc, parms[20][15], parm_list[1000];
135  int more_chars, ibnd;
136  /*
137  * open the reflectance file
138  */
139  if (h5io_openr(file, 0, &file_id) != 0) {
140  printf("%s, %d: Unable to open the reflectance file: %s\n", __FILE__,
141  __LINE__, file);
142  return 1;
143  }
144  /*
145  * get the parm names, wavelengths, and #
146  */
147  if (h5io_rd_attr(&file_id, "parm_list", (void *) parm_list) != 0) {
148  printf("%s, %d: Unable to read parm_list from reflectance file: %s\n",
149  __FILE__, __LINE__, file);
150  return 1;
151  }
152 
153  more_chars = 1;
154  *nlam = 0;
155  while (more_chars) {
156  if (*nlam == 0)
157  sloc = strtok(parm_list, ",");
158  else
159  sloc = strtok(NULL, ",");
160  if (sloc != NULL) {
161  strcpy(parms[*nlam], sloc);
162  sscanf(parms[*nlam], "rhos_%f", lam_lst + *nlam);
163  (*nlam)++;
164  } else
165  more_chars = 0;
166  }
167  /*
168  * open datasets for each parm
169  */
170  if ((dat_ids = (h5io_str *) malloc(*nlam * sizeof ( h5io_str)))
171  == NULL) {
172  printf("%s, %d: Unable to reserve h5io ids for refl datasets\n",
173  __FILE__, __LINE__);
174  return 1;
175  }
176  for (ibnd = 0; ibnd < *nlam; ibnd++) {
177  if (h5io_set_ds(&file_id, parms[ibnd], (dat_ids + ibnd)) != 0) {
178  printf("%s, %d: Unable to set to dataset %d in refl file %s\n",
179  __FILE__, __LINE__, ibnd, file);
180  return 1;
181  }
182  }
183  return 0;
184 }
int h5io_openr(char *file, int opt, h5io_str *id)
Definition: h5io.c:4
#define NULL
Definition: decode_rs.h:63
int rd_rhos_scan(char *file, int npix, int iscn, int ndet, float **rhos)
Definition: rd_rhos_scan.c:8
#define MAX_BND
Definition: viirs_sim_sdr.h:34
int h5io_close(h5io_str *id)
Definition: h5io.c:115
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
Definition: HISTORY.txt:413
int h5io_set_ds(h5io_str *id, char *path_name, h5io_str *ds_id)
Definition: h5io.c:324
int bnd_ix_2_sen_info(char *pname, void *pval)
int h5io_rd_ds_slice(h5io_str *ds_id, int *start, int *count, void *data)
Definition: h5io.c:602
int h5io_rd_attr(h5io_str *id, char *attr_name, void *data)
Definition: h5io.c:412
int rd_rhos_open(char *file, float *lam_lst, int *nlam)
Definition: rd_rhos_scan.c:116
void lspline(float xin[], float yin[], int32_t nin, float xout[], float yout[], int32_t nout)
Definition: lspline.c:20
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
#define N_VNIR_BND
Definition: viirs_sim_sdr.h:31
int npix
Definition: get_cmp.c:27
int count
Definition: decode_rs.h:79