OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1subpix.c
Go to the documentation of this file.
1 /* -------------------------------------------------------------------- */
2 /* l1subpix() - sub-samples and/or crops a level-1 record in place */
3 /* */
4 /* Returns 0 on succss, 1 on error. */
5 /* */
6 /* Notes: Only record fields which are filled by the L1 read routines */
7 /* must be updated here. All other fields will be filled later */
8 /* using the sub-sampled geometry and radiances. */
9 /* */
10 /* Written By: B. A. Franz */
11 /* W. Robinson, SAIC 15Feb2017 add geom_per_band shifting */
12 /* -------------------------------------------------------------------- */
13 
14 #include <string.h>
15 #include "l1.h"
16 
17 int l1subpix(filehandle *l1file, l1str *l1rec) {
18  int32_t sp = l1file->spix;
19  int32_t ep = l1file->epix;
20  int32_t dp = l1_input->dpixl;
21  int32_t nbands = l1file->nbands;
22 
23  if ((sp == 0) && (ep == l1file->npix - 1) && dp == 1)
24  return (0);
25 
26  if (sp > ep || dp < 1 || dp > (ep - sp + 1)) {
27  fprintf(stderr,
28  "-E- %s Line %d: subpixel specification error (sp=%d,ep=%d,dp=%d).\n",
29  __FILE__, __LINE__, sp, ep, dp);
30  return (1);
31  }
32 
33  if (dp == 1) {
34 
35  int32_t length;
36 
37  l1rec->npix = ep - sp + 1;
38 
39  length = l1rec->npix * sizeof (float);
40 
41  memmove(l1rec->pixnum, &l1rec->pixnum[sp], l1rec->npix * sizeof (int32_t));
42  memmove(l1rec->slot, &l1rec->slot [sp], l1rec->npix * sizeof (unsigned char));
43  memmove(l1rec->nobs, &l1rec->nobs [sp], l1rec->npix * sizeof (int32_t));
44 
45  memmove(l1rec->lon, &l1rec->lon [sp], length);
46  memmove(l1rec->lat, &l1rec->lat [sp], length);
47  memmove(l1rec->solz, &l1rec->solz[sp], length);
48  memmove(l1rec->sola, &l1rec->sola[sp], length);
49  memmove(l1rec->senz, &l1rec->senz[sp], length);
50  memmove(l1rec->sena, &l1rec->sena[sp], length);
51 
52  memmove(l1rec->alpha, &l1rec->alpha[sp], length);
53  memmove(l1rec->height, &l1rec->height[sp], length);
54  memmove(l1rec->flags, &l1rec->flags[sp], l1rec->npix * sizeof (int32_t));
55  memmove(l1rec->hilt, &l1rec->hilt[sp], l1rec->npix * sizeof (char));
56  memmove(l1rec->stlight, &l1rec->stlight[sp], l1rec->npix * sizeof (char));
57  memmove(l1rec->navfail, &l1rec->navfail[sp], l1rec->npix * sizeof (char));
58  memmove(l1rec->navwarn, &l1rec->navwarn[sp], l1rec->npix * sizeof (char));
59 
60  memmove(l1rec->Lt, &l1rec->Lt [sp * nbands], length * nbands);
61  memmove(l1rec->Lt_unc, &l1rec->Lt_unc[sp * nbands], length * nbands);
62 
63  memmove(l1rec->sw_n, &l1rec->sw_n [sp * nbands], length * nbands);
64  memmove(l1rec->sw_a, &l1rec->sw_a [sp * nbands], length * nbands);
65  memmove(l1rec->sw_bb, &l1rec->sw_bb [sp * nbands], length * nbands);
66  memmove(l1rec->sw_a_avg, &l1rec->sw_a_avg [sp * nbands], length * nbands);
67  memmove(l1rec->sw_bb_avg, &l1rec->sw_bb_avg [sp * nbands], length * nbands);
68 
69  memmove(l1rec->Ltir, &l1rec->Ltir [sp * NBANDSIR], length * NBANDSIR);
70  memmove(l1rec->Bt, &l1rec->Bt [sp * NBANDSIR], length * NBANDSIR);
71 
72  memmove(l1rec->rho_cirrus, &l1rec->rho_cirrus[sp], length);
73 
74  if (l1rec->geom_per_band != NULL) {
75  memmove(l1rec->geom_per_band->senz,
76  &l1rec->geom_per_band->senz[ sp * nbands ], length * nbands);
77  memmove(l1rec->geom_per_band->sena,
78  &l1rec->geom_per_band->sena[ sp * nbands ], length * nbands);
79  memmove(l1rec->geom_per_band->solz,
80  &l1rec->geom_per_band->solz[ sp * nbands ], length * nbands);
81  memmove(l1rec->geom_per_band->sola,
82  &l1rec->geom_per_band->sola[ sp * nbands ], length * nbands);
83  }
84 
85  /* MERIS */
86  memmove(l1rec->pixdet, &l1rec->pixdet[sp], l1rec->npix * sizeof (int32_t));
87  memmove(l1rec->radcor, &l1rec->radcor[sp * nbands], length * nbands);
88 
89  } else {
90 
91  int32_t i;
92 
93  l1rec->npix = (ep - sp) / dp + 1;
94 
95  for (i = 0; i < l1rec->npix; i++) {
96 
97  l1rec->pixnum[i] = l1rec->pixnum[i * dp + sp];
98  l1rec->slot[i] = l1rec->slot[i * dp + sp];
99  l1rec->nobs[i] = l1rec->nobs[i * dp + sp];
100 
101  l1rec->lon [i] = l1rec->lon [i * dp + sp];
102  l1rec->lat [i] = l1rec->lat [i * dp + sp];
103  l1rec->solz[i] = l1rec->solz[i * dp + sp];
104  l1rec->sola[i] = l1rec->sola[i * dp + sp];
105  l1rec->senz[i] = l1rec->senz[i * dp + sp];
106  l1rec->sena[i] = l1rec->sena[i * dp + sp];
107 
108  l1rec->alpha[i] = l1rec->alpha[i * dp + sp];
109  l1rec->height[i] = l1rec->height[i * dp + sp];
110  l1rec->flags[i] = l1rec->flags[i * dp + sp];
111 
112  l1rec->hilt [i] = l1rec->hilt [i * dp + sp];
113  l1rec->stlight[i] = l1rec->stlight[i * dp + sp];
114  l1rec->navfail[i] = l1rec->navfail[i * dp + sp];
115  l1rec->navwarn[i] = l1rec->navwarn[i * dp + sp];
116 
117  l1rec->rho_cirrus[i] = l1rec->rho_cirrus[i * dp + sp];
118 
119  memmove(&l1rec->Lt [i * nbands],
120  &l1rec->Lt [(i * dp + sp) * nbands], nbands * sizeof (float));
121 
122  memmove(&l1rec->sw_n [i * nbands],
123  &l1rec->sw_n [(i * dp + sp) * nbands], nbands * sizeof (float));
124  memmove(&l1rec->sw_a [i * nbands],
125  &l1rec->sw_a [(i * dp + sp) * nbands], nbands * sizeof (float));
126  memmove(&l1rec->sw_bb[i * nbands],
127  &l1rec->sw_bb[(i * dp + sp) * nbands], nbands * sizeof (float));
128  memmove(&l1rec->sw_a_avg [i * nbands],
129  &l1rec->sw_a_avg [(i * dp + sp) * nbands], nbands * sizeof (float));
130  memmove(&l1rec->sw_bb_avg[i * nbands],
131  &l1rec->sw_bb_avg[(i * dp + sp) * nbands], nbands * sizeof (float));
132 
133  memmove(&l1rec->Ltir [i * NBANDSIR],
134  &l1rec->Ltir [(i * dp + sp) * NBANDSIR], NBANDSIR * sizeof (float));
135 
136  memmove(&l1rec->Bt [i * NBANDSIR],
137  &l1rec->Bt [(i * dp + sp) * NBANDSIR], NBANDSIR * sizeof (float));
138 
139  if (l1rec->geom_per_band != NULL) {
140  memmove(&l1rec->geom_per_band->senz[ i * nbands ],
141  &l1rec->geom_per_band->senz[ (i * dp + sp) * nbands ],
142  nbands * sizeof (float));
143  memmove(&l1rec->geom_per_band->sena[ i * nbands ],
144  &l1rec->geom_per_band->sena[ (i * dp + sp) * nbands ],
145  nbands * sizeof (float));
146  memmove(&l1rec->geom_per_band->solz[ i * nbands ],
147  &l1rec->geom_per_band->solz[ (i * dp + sp) * nbands ],
148  nbands * sizeof (float));
149  memmove(&l1rec->geom_per_band->sola[ i * nbands ],
150  &l1rec->geom_per_band->sola[ (i * dp + sp) * nbands ],
151  nbands * sizeof (float));
152  }
153 
154  /* MERIS */
155  l1rec->pixdet[i] = l1rec->pixdet[i * dp + sp];
156  memmove(&l1rec->radcor [i * nbands],
157  &l1rec->radcor [(i * dp + sp) * nbands], nbands * sizeof (float));
158 
159  }
160  }
161 
162  return (0);
163 }
164 
int32 l1file(int32 sdfid, int32 *nsamp, int32 *nscans, int16 *dtynum)
Definition: l1stat_chk.c:586
#define NBANDSIR
Definition: filehandle.h:23
#define NULL
Definition: decode_rs.h:63
read l1rec
l1_input_t * l1_input
Definition: l1_options.c:9
float dp[MODELMAX]
int32_t nbands
int l1subpix(filehandle *l1file, l1str *l1rec)
Definition: l1subpix.c:17
int i
Definition: decode_rs.h:71