OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
cz_mov_scn.c
Go to the documentation of this file.
1 #include <limits.h>
2 #include "l1czcs.h"
3 
4 int cz_mov_scn(int init, int ds_num, char *file, mstr_struc *mstr,
5  int mstr_last, int nscan_out, gattr_struc *gattr, l1_data_struc *l1_data)
6 /*******************************************************************
7 
8  cz_mov_scn
9 
10  purpose: move the proper data scan information from the input L1
11  czcs file to the output storage
12 
13  Returns type: int - return status: 0 is good
14 
15  Parameters: (in calling order)
16  Type Name I/O Description
17  ---- ---- --- -----------
18  int init I set up global attributes
19  flag: 1, set gattr from 1st
20  file. 0, only modify with
21  incoming attrs
22  int ds_num I dataset id #
23  char * file I L1 czcs file to transfer
24  scans from
25  mstr_struc * mstr I master control structure
26  int mstr_last I last entry in the master list
27  int nscan_out I # lines in merged file
28  gattr_struc * gattr I/O global attributes for output
29  l1_data_struc * l1_data I/O data structure for output
30 
31  Modification history:
32  Programmer Date Description of change
33  ---------- ---- ---------------------
34  W. Robinson, SAIC 10 Aug 2004 Original development
35  W. Robinson, SAIC 20 Dec 2005 add the moving of the pos_err or
36  position error values
37 
38  *******************************************************************/
39  {
40  l1_data_struc in_dat;
41  gattr_struc in_attr;
42  int i, j, n_ctl, nscan, time_reset;
43  short in_scn;
44  int32_t out_scn, sum;
45  /*
46  * read in the L1 data and attributes from the file
47  * fill output attr struct if first file
48  */
49  if (init == 1) {
50  if (cz_l1_read(file, 0, gattr, &in_dat) != 0) return -1;
51  n_ctl = gattr->n_ctl_pt;
52  nscan = gattr->scan_lines;
53  /*
54  * copy ctl_pt_cols entirely the first time
55  */
56  memcpy(l1_data->ctl_pt_cols, in_dat.ctl_pt_cols,
57  (n_ctl * sizeof ( int)));
58  } else {
59  if (cz_l1_read(file, 0, &in_attr, &in_dat) != 0) return -1;
60  n_ctl = in_attr.n_ctl_pt;
61  nscan = in_attr.scan_lines;
62  /*
63  * Update some of the global attributes, Note that some items are
64  * updated in cz_meta_adj and also in czl1merge as well as in cz_l1_write
65  *
66  * end time as the latest end time seen
67  */
68  time_reset = 0;
69  if (in_attr.end_year > gattr->end_year)
70  time_reset = 1;
71  else if (in_attr.end_day > gattr->end_day)
72  time_reset = 1;
73  else if (in_attr.end_msec > gattr->end_msec)
74  time_reset = 1;
75 
76  if (time_reset == 1) {
77  gattr->end_year = in_attr.end_year;
78  gattr->end_day = in_attr.end_day;
79  gattr->end_msec = in_attr.end_msec;
80  strcpy(gattr->end_time, in_attr.end_time);
81  }
82 
83  /*
84  * file metrics will best represent the cumulative scan info
85  *
86  * the ILT flags and parameter presence will be the bitwise or
87  * of the current and new values
88  */
89  gattr->ilt_flags = gattr->ilt_flags | in_attr.ilt_flags;
90  gattr->parm_presence = gattr->parm_presence | in_attr.parm_presence;
91  /*
92  * for the other file metrics, sum together till short limit is reached
93  */
94  sum = (int32_t) gattr->n_miss_scans + (int32_t) in_attr.n_miss_scans;
95  gattr->n_miss_scans = (sum > SHRT_MAX) ? SHRT_MAX : (short) sum;
96 
97  for (i = 0; i < 6; i++) {
98  sum = (int32_t) gattr->n_scan_mis_chan[i] + (int32_t) in_attr.n_scan_mis_chan[i];
99  gattr->n_scan_mis_chan[i] = (sum > SHRT_MAX) ? SHRT_MAX : (short) sum;
100  }
101 
102  sum = (int32_t) gattr->n_hdt_sync_loss + (int32_t) in_attr.n_hdt_sync_loss;
103  gattr->n_hdt_sync_loss = (sum > SHRT_MAX) ? SHRT_MAX : (short) sum;
104 
105  sum = (int32_t) gattr->n_hdt_parity_err + (int32_t) in_attr.n_hdt_parity_err;
106  gattr->n_hdt_parity_err = (sum > SHRT_MAX) ? SHRT_MAX : (short) sum;
107 
108  sum = (int32_t) gattr->n_wbvt_sync_loss + (int32_t) in_attr.n_wbvt_sync_loss;
109  gattr->n_wbvt_sync_loss = (sum > SHRT_MAX) ? SHRT_MAX : (short) sum;
110 
111  sum = (int32_t) gattr->n_wbvt_slips + (int32_t) in_attr.n_wbvt_slips;
112  gattr->n_wbvt_slips = (sum > SHRT_MAX) ? SHRT_MAX : (short) sum;
113 
114  }
115  printf("cz_mov_scn: dataset # (ds_num) = %d, # scans: %d\n",
116  ds_num, nscan);
117  printf("cz_mov_scn: file: %s\n", file);
118  /*
119  * transfer each portion of the scan info as indicated by the master list
120  * note that mstr_last is pointer to last, hence <=
121  */
122  for (i = 0; i <= mstr_last; i++) {
123  if ((mstr->ds_num[i] == ds_num) && (mstr->exist[i] == 1)) {
124  in_scn = mstr->scan[i];
125  out_scn = mstr->out_scan[i];
126  /* for detail of output
127  printf(
128  "cz_mov_scn: moving scan line %d to output line %ld, mstr loop indx: %d\n",
129  in_scn, out_scn, i );
130  */
131  for (j = 0; j < 6; j++)
132  memcpy(l1_data->counts[j] + (NCZCS_PIX * out_scn),
133  in_dat.counts[j] + (NCZCS_PIX * in_scn),
134  (NCZCS_PIX * sizeof (unsigned char)));
135 
136  l1_data->msec[out_scn] = in_dat.msec[in_scn];
137  l1_data->tilt[out_scn] = in_dat.tilt[in_scn];
138  l1_data->slat[out_scn] = in_dat.slat[in_scn];
139  l1_data->slon[out_scn] = in_dat.slon[in_scn];
140  l1_data->clat[out_scn] = in_dat.clat[in_scn];
141  l1_data->clon[out_scn] = in_dat.clon[in_scn];
142  l1_data->elat[out_scn] = in_dat.elat[in_scn];
143  l1_data->elon[out_scn] = in_dat.elon[in_scn];
144  memcpy(l1_data->cal_sum + (5 * out_scn),
145  in_dat.cal_sum + (5 * in_scn), (5 * sizeof (unsigned char)));
146  memcpy(l1_data->cal_scan + (6 * out_scn),
147  in_dat.cal_scan + (6 * in_scn), (6 * sizeof (unsigned char)));
148  memcpy(l1_data->orb_vec + (3 * out_scn),
149  in_dat.orb_vec + (3 * in_scn), (3 * sizeof ( float)));
150  memcpy(l1_data->att_ang + (3 * out_scn),
151  in_dat.att_ang + (3 * in_scn), (3 * sizeof ( float)));
152  l1_data->pos_err[out_scn] = in_dat.pos_err[in_scn];
153  memcpy(l1_data->slope + (6 * out_scn), in_dat.slope + (6 * in_scn),
154  (6 * sizeof ( float)));
155  memcpy(l1_data->intercept + (6 * out_scn),
156  in_dat.intercept + (6 * in_scn), (6 * sizeof ( float)));
157  l1_data->gain[out_scn] = in_dat.gain[in_scn];
158  memcpy(l1_data->ctl_pt_lat + (out_scn * n_ctl),
159  in_dat.ctl_pt_lat + (in_scn * n_ctl), (n_ctl * sizeof (float)));
160  memcpy(l1_data->ctl_pt_lon + (out_scn * n_ctl),
161  in_dat.ctl_pt_lon + (in_scn * n_ctl), (n_ctl * sizeof (float)));
162  l1_data->ctl_pt_rows[out_scn] = out_scn + 1;
163  }
164  }
165  /*
166  * remove allocated arrays in data struct
167  */
168  cz_dat_free(&in_dat, 0);
169  return 0;
170 }
int cz_l1_read(char *file, int r_mode, gattr_struc *cz_attr, l1_data_struc *cz_dat)
Definition: cz_l1_read.c:4
int j
Definition: decode_rs.h:73
int32 nscan
Definition: l1_czcs_hdf.c:19
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
void cz_dat_free(l1_data_struc *l1_data, int r_mode)
Definition: cz_dat_alloc.c:106
int init(int32_t ipr, int32_t jpr, char *efile, char *pfile)
Definition: proj_report.c:51
int cz_mov_scn(int init, int ds_num, char *file, mstr_struc *mstr, int mstr_last, int nscan_out, gattr_struc *gattr, l1_data_struc *l1_data)
Definition: cz_mov_scn.c:4
int i
Definition: decode_rs.h:71
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
#define NCZCS_PIX
Definition: l1czcs.h:23