OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
olap_resolve.c
Go to the documentation of this file.
1 #include "l1czcs.h"
2 
3 void olap_resolve(mstr_struc *mstr, int mstr_last, int new_start, int new_end,
4  int ds_num)
5 /*******************************************************************
6 
7  olap_resolve
8 
9  purpose: resolve the overlap of new data over current data in master list
10  Use the quality / existance values to pick the best replacement scans
11 
12  Returns type: void
13 
14  Parameters: (in calling order)
15  Type Name I/O Description
16  ---- ---- --- -----------
17  mstr_struc * mstr I/O master structure of scan info
18  int mstr_last I last line in master list
19  int new_start I start of new overlapping data
20  int new_end I end of new overlapping data
21  int ds_num I dataset id of new data
22 
23  Modification history:
24  Programmer Date Description of change
25  ---------- ---- ---------------------
26  W. Robinson, SAIC 6 Aug 2004 Original developmento
27 
28  Note that if the overlap is inside the master range, it will either
29  completely replace it or not at all. If the overlap is at the end,
30  the best scan line will be found in the overlap to begin inserting scans
31  from the new data. This will preserve the scan continuity while getting
32  the best quality possible.
33 
34  *******************************************************************/
35  {
36  int cum_cur, cum_new, *ca_cur, *ca_new, i, olap_st, olap_en, n_olap,
37  break_scan, sum;
38  /*
39  * first, decide if the new data range is inside (or at the end of)
40  * the current data
41  */
42  cum_cur = 0;
43  cum_new = 0;
44 
45  if (new_end < mstr_last) {
46  /*
47  * overlap is inside current range, get the cumulative # scans with
48  * bad status, non-existent scans for current and new scans
49  */
50  printf("olap_resolve: overlap is inside current range\n");
51 
52  for (i = new_start; i < new_end; i++) {
53  if (mstr->exist[i] == 0)
54  cum_cur++;
55  else if (mstr->qual[i] != 0)
56  cum_cur++;
57 
58  if (mstr->in_exist[i] == 0)
59  cum_new++;
60  else if (mstr->in_qual[i] != 0)
61  cum_new++;
62  }
63  printf("olap_resolve: cum_new = %d, cum_cur = %d\n", cum_new, cum_cur);
64  if (cum_new < cum_cur) {
65  /*
66  * new data has better overall quality in the overlap than current data.
67  * so, replace the current data
68  */
69  printf("olap_resolve: new data better, cum_new = %d, cum_cur = %d\n",
70  cum_new, cum_cur);
71  for (i = new_start; i < (new_end + 1); i++) {
72  mstr->exist[i] = mstr->in_exist[i];
73  mstr->qual[i] = mstr->in_qual[i];
74  mstr->ds_num[i] = ds_num;
75  mstr->msec[i] = mstr->in_msec[i];
76  mstr->scan[i] = mstr->in_scan[i];
77  }
78  } else
79  printf("olap_resolve: current data has equal of better quality\n");
80  } else {
81  /*
82  * overlap is at / beyond the current end of data. get overlap range
83  */
84  printf("olap_resolve: overlap is at / beyond the current end\n");
85  olap_st = new_start;
86  olap_en = mstr_last;
87  n_olap = olap_en - olap_st + 1;
88  /*
89  * allocate cumulative quality arrays for the current and new overlaps
90  */
91  ca_cur = malloc(n_olap * sizeof ( int));
92  ca_new = malloc(n_olap * sizeof ( int));
93  /*
94  * loop through the overlap range, forward for current data and backward for
95  * new data. accumulate # quality problems for each
96  */
97  for (i = 0; i < n_olap; i++) {
98  if (mstr->exist[ i + olap_st ] == 0)
99  cum_cur++;
100  else if (mstr->qual[ i + olap_st ] != 0)
101  cum_cur++;
102 
103  ca_cur[i] = cum_cur;
104 
105  if (mstr->in_exist[ olap_en - i ] == 0)
106  cum_new++;
107  else if (mstr->in_qual[ olap_en - i ] != 0)
108  cum_new++;
109 
110  ca_new[ n_olap - 1 - i ] = cum_new;
111  }
112  printf("olap_resolve: current total bad: %d, new total bad: %d\n",
113  cum_cur, cum_new);
114  /*
115  * Cumulative arrays set. go thru and find scan where total problems
116  * are least. Note that this favors the new file in equally good data
117  */
118  sum = n_olap * 3; /* start at a high valus */
119  break_scan = -1;
120  for (i = 0; i < n_olap; i++) {
121  if ((ca_new[i] + ca_cur[i]) < sum) {
122  sum = ca_new[i] + ca_cur[i];
123  break_scan = i;
124  }
125  }
126  printf("olap_resolve: break at line %d of overlap, total # olap = %d\n",
127  break_scan, n_olap);
128  printf("olap_resolve: lowest sum is %d\n", sum);
129  /*
130  * the best place to break the overlap is found. replace current data
131  * with new data beyond this line
132  */
133  if (break_scan < (n_olap - 1)) {
134  for (i = break_scan; i < n_olap; i++) {
135  mstr->exist[ i + olap_st ] = mstr->in_exist[ i + olap_st ];
136  mstr->qual[ i + olap_st ] = mstr->in_qual[ i + olap_st ];
137  mstr->ds_num[ i + olap_st ] = ds_num;
138  mstr->msec[ i + olap_st ] = mstr->in_msec[ i + olap_st ];
139  mstr->scan[ i + olap_st ] = mstr->in_scan[ i + olap_st ];
140  }
141  }
142  /*
143  * free the ca_cur, ca_new
144  */
145  free(ca_cur);
146  free(ca_new);
147  }
148  return;
149 }
void olap_resolve(mstr_struc *mstr, int mstr_last, int new_start, int new_end, int ds_num)
Definition: olap_resolve.c:3
int i
Definition: decode_rs.h:71
short * ds_num
Definition: l1czcs.h:381