OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
fin_sdr.c
Go to the documentation of this file.
1 #include "viirs_sim_sdr.h"
2 
3 int fin_sdr(ctl_struc *ctl, in_rec_struc *in_rec, out_rec_struc *out_rec)
4 /*-----------------------------------------------------------------------------
5  Program: fin_sdr
6 
7  Description: finish up on the simulation processing: close input
8  and output dataset IDs
9 
10  Arguments:
11  Type Name I/O Description
12  ---- ---- --- -----------
13  ctl_struc * ctl I processing controls
14  in_rec_struc * in_rec I input record controls
15  out_rec_struc * out_rec I/O output record controls
16 
17  Modification history:
18 
19  W. Robinson, SAIC 21 Oct 2008 Original development
20 
21 ----------------------------------------------------------------------------*/ {
22  int iid, jid, isdr, ibnd;
23  /*
24  * Input dataset controls
25  * geolocation
26  */
27  for (iid = 0; iid < 6; iid++) {
28  if (h5io_close(&(in_rec->geo_dat_id[ iid ])) != 0) {
29  printf("%s: Unable to close input geoloc dataset # %d\n",
30  __FILE__, iid);
31  return 1;
32  }
33  }
34 
35  if (h5io_close(&(in_rec->geo_fid)) != 0) {
36  printf("%s: Unable to close input geoloc file\n", __FILE__);
37  return 1;
38  }
39  /*
40  * compute the granule latitude, longitude limits
41  * this could be placed in the dataset, if needed, in the future
42  */
43  printf("latitude limits, S: %f, N: %f\n", in_rec->ll_lims[0],
44  in_rec->ll_lims[1]);
45  printf("(-) longitude limits, W: %f, E: %f\n", in_rec->ll_lims[2],
46  in_rec->ll_lims[3]);
47  printf("(+) longitude limits, W: %f, E: %f\n", in_rec->ll_lims[4],
48  in_rec->ll_lims[5]);
49  /* w_lim = -180.;
50  e_lim = 180.;
51  we'll have to make some kind of actual W, E limits */
52  /*
53  * Output dataset controls
54  * geolocation and then band data ids
55  */
56  for (iid = 0; iid < 6; iid++) {
57  if (h5io_close(&(out_rec->geo_dat_id[ iid ])) != 0) {
58  printf("%s: Unable to close output geoloc dataset id # %d\n",
59  __FILE__, iid);
60  return 1;
61  }
62  }
63  for (isdr = 0; isdr < out_rec->nbnd; isdr++) {
64  for (iid = 0; iid < 2; iid++) {
65  if (h5io_close(&(out_rec->bnd_dat_id[iid][isdr])) != 0) {
66  printf("%s: Unable to close output band file # %d, dataset # %d\n",
67  __FILE__, isdr, iid);
68  return 1;
69  }
70  }
71  /*
72  * QF1_VIIRSMBANDSDR dataset id close
73  */
74  if (h5io_close(&(out_rec->qual1_m_id[isdr])) != 0) {
75  printf(
76  "%s, %d: Failed closing output QF1_VIIRSMBANDSDR dataset file # %d\n",
77  __FILE__, __LINE__, isdr);
78  return 1;
79  }
80  }
81  /* open groups */
82  for (isdr = 0; isdr < out_rec->nbnd + 1; isdr++) {
83  for (iid = 0; iid < 2; iid++) {
84  jid = 1 - iid;
85  if (h5io_close(&(out_rec->sdr_dat_gid[ jid ][isdr])) != 0) {
86  printf("%s: Unable to close output sdr group id # %d, sdr # %d\n",
87  __FILE__, jid, isdr);
88  return 1;
89  }
90  }
91  }
92  /* open files */
93  for (isdr = 0; isdr < out_rec->nbnd + 1; isdr++) {
94  if (h5io_close(&(out_rec->sdr_fid[isdr])) != 0) {
95  printf("%s: Unable to close output sdr file for sdr# %d\n",
96  __FILE__, isdr);
97  return 1;
98  }
99  }
100  /* close the L2 file if used */
101  if (ctl->l2_use == 1)
102  if (closeL2(&in_rec->l2_str, 0) != 0) {
103  printf("%s: Unable to close input L2 file: %s\n",
104  __FILE__, in_rec->l2_str.filename);
105  return 1;
106  }
107  /*
108  * free data storage, note that the in_rec->lat of NULL signals frees
109  * in scan_cvt
110  */
111  free(in_rec->lat);
112  in_rec->lat = NULL;
113  if (scan_cvt(in_rec, out_rec) != 0)
114  return 1;
115  free(in_rec->lon);
116  free(in_rec->sena);
117  free(in_rec->senz);
118  free(in_rec->sola);
119  free(in_rec->solz);
120  for (ibnd = 0; ibnd < out_rec->nbnd; ibnd++) {
121  free(in_rec->bnd_lt[ibnd]);
122  free(in_rec->bnd_q[ibnd]);
123  free(out_rec->qual1_m[ibnd]);
124  free(in_rec->gain_bit[ibnd]);
125  free(in_rec->dn_sat[ibnd]);
126  if (ctl->count_cal_opt != 0) {
127  free(in_rec->dn[ibnd]);
128  }
129  }
130  /*
131  * clean up for artifact use
132  * free the electronic crosstalk internal storage
133  */
134  if (ctl->ext_opt != 0)
135  if (viirs_ext(ctl, in_rec) != 0)
136  return 1;
137  /* for the noise and stray light generation */
138  if (ctl->noise_mode == 1)
139  viirs_noise(ctl, in_rec, 1);
140  if (ctl->stray_opt == 1)
141  viirs_straylt(ctl, in_rec, 1);
142 
143  return 0;
144 }
#define NULL
Definition: decode_rs.h:63
int fin_sdr(ctl_struc *ctl, in_rec_struc *in_rec, out_rec_struc *out_rec)
Definition: fin_sdr.c:3
int h5io_close(h5io_str *id)
Definition: h5io.c:115
int32_t closeL2(l2_prod *l2_str, int32_t ifile)
Definition: readL2scan.c:1936
int viirs_noise(ctl_struc *ctl, in_rec_struc *in_rec, int noise_stop)
Definition: viirs_noise.c:9
int scan_cvt(in_rec_struc *in_rec, out_rec_struc *out_rec)
Definition: scan_cvt.c:5
int viirs_ext(ctl_struc *ctl, in_rec_struc *in_rec)
Definition: viirs_ext.c:5
int viirs_straylt(ctl_struc *, in_rec_struc *, int)
Definition: viirs_straylt.c:7