OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_beg_ext.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include "hdf.h"
3 #include "seaproto.h"
4 
5 int32_t get_beg_ext32(int32_t n_bins_write, int32_t *binnum_data,
6  int32_t *basebin, int32_t nrows, int32_t *beg, int32_t *ext) {
7  int i, j;
8  int32_t last_row;
9  int32_t *row;
10  int32_t *uniq;
11 
12  row = (int32_t *) calloc(n_bins_write, sizeof (int32_t));
13  uniq = (int32_t *) calloc(nrows + 1, sizeof (int32_t));
14 
15  /* Determine row number of each bin */
16  /* -------------------------------- */
17  last_row = 0;
18  for (j = 0; j < n_bins_write; j++) {
19  for (i = last_row; i <= nrows; i++) {
20  if (basebin[i] > binnum_data[j]) {
21  row[j] = i;
22  last_row = i;
23  break;
24  }
25  }
26  if (row[j] == 0) {
27  printf("Zero row at bin: %d of %d total bins.\n", j, n_bins_write);
28  printf("basebin: %ld binnum_data: %ld\n", (long int) basebin[i],
29  (long int) binnum_data[j]);
30  printf("%d %d\n", i, last_row);
31  }
32  }
33 
34  for (i = 0; i < n_bins_write - 1; i++) {
35  if (row[i] > row[i + 1]) {
36  printf("Improper row number: %d at element: %d\n", row[i], i);
37  }
38  }
39 
40  /* Determine unique row numbers */
41  /* ---------------------------- */
42  last_row = row[0];
43  uniq[0] = 0;
44  i = 1;
45  for (j = 1; j < n_bins_write; j++) {
46  if (row[j] != last_row) {
47  uniq[i++] = j;
48  last_row = row[j];
49  }
50  }
51  for (j = i; j < nrows; j++)
52  uniq[j] = -1;
53 
54  /* Determine begining pixel number for each row */
55  /* -------------------------------------------- */
56  for (j = 0; j < nrows; j++) {
57  if (uniq[j] == -1)
58  break;
59  beg[row[uniq[j]] - 1] = binnum_data[uniq[j]];
60 
61  if (row[uniq[j]] - 1 < 0)
62  printf("bad row index: %d %d %d\n", j, uniq[j], row[uniq[j]]);
63  }
64 
65  uniq[i] = n_bins_write;
66 
67  /* Determine extent of each row */
68  /* ---------------------------- */
69  for (j = 0; j < i; j++) {
70  if (uniq[j] == -1)
71  break;
72 
73  ext[row[uniq[j]] - 1] = uniq[j + 1] - uniq[j];
74  }
75 
76  free(row);
77  free(uniq);
78 
79  return 0;
80 }
81 
82 
83 int64_t get_beg_ext(int32_t n_bins_write, int64_t *binnum_data,
84  int64_t *basebin, int32_t nrows, int64_t *beg, int32_t *ext) {
85  int i, j;
86  int32_t last_row;
87  int32_t *row;
88  int32_t *uniq;
89 
90  row = (int32_t *) calloc(n_bins_write, sizeof (int32_t));
91  uniq = (int32_t *) calloc(nrows + 1, sizeof (int32_t));
92 
93  /* Determine row number of each bin */
94  /* -------------------------------- */
95  last_row = 0;
96  for (j = 0; j < n_bins_write; j++) {
97  for (i = last_row; i <= nrows; i++) {
98  if (basebin[i] > binnum_data[j]) {
99  row[j] = i;
100  last_row = i;
101  break;
102  }
103  }
104  if (row[j] == 0) {
105  printf("Zero row at bin: %d of %d total bins.\n", j, n_bins_write);
106  printf("basebin: %ld binnum_data: %ld\n", (long int) basebin[i],
107  (long int) binnum_data[j]);
108  printf("%d %d\n", i, last_row);
109  }
110  }
111 
112  for (i = 0; i < n_bins_write - 1; i++) {
113  if (row[i] > row[i + 1]) {
114  printf("Improper row number: %d at element: %d\n", row[i], i);
115  }
116  }
117 
118  /* Determine unique row numbers */
119  /* ---------------------------- */
120  last_row = row[0];
121  uniq[0] = 0;
122  i = 1;
123  for (j = 1; j < n_bins_write; j++) {
124  if (row[j] != last_row) {
125  uniq[i++] = j;
126  last_row = row[j];
127  }
128  }
129  for (j = i; j < nrows; j++)
130  uniq[j] = -1;
131 
132  /* Determine begining pixel number for each row */
133  /* -------------------------------------------- */
134  for (j = 0; j < nrows; j++) {
135  if (uniq[j] == -1)
136  break;
137  beg[row[uniq[j]] - 1] = binnum_data[uniq[j]];
138 
139  if (row[uniq[j]] - 1 < 0)
140  printf("bad row index: %d %d %d\n", j, uniq[j], row[uniq[j]]);
141  }
142 
143  uniq[i] = n_bins_write;
144 
145  /* Determine extent of each row */
146  /* ---------------------------- */
147  for (j = 0; j < i; j++) {
148  if (uniq[j] == -1)
149  break;
150 
151  ext[row[uniq[j]] - 1] = uniq[j + 1] - uniq[j];
152  }
153 
154  free(row);
155  free(uniq);
156 
157  return 0;
158 }
int j
Definition: decode_rs.h:73
int64_t get_beg_ext(int32_t n_bins_write, int64_t *binnum_data, int64_t *basebin, int32_t nrows, int64_t *beg, int32_t *ext)
Definition: get_beg_ext.c:83
int32_t get_beg_ext32(int32_t n_bins_write, int32_t *binnum_data, int32_t *basebin, int32_t nrows, int32_t *beg, int32_t *ext)
Definition: get_beg_ext.c:5
int32 nrows
int i
Definition: decode_rs.h:71