OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
viirs_pxcvt.c
Go to the documentation of this file.
1 #include "l12_proto.h"
2 /*
3  * viirs_pxcvt.c contains routines for conversion of unaggregated to
4  * aggregated VIIRS pixels and visa versa. Also, it finds an
5  * aggregated pixel that is x unaggregated samples away.
6  */
7 static int ag_px_st[] = {0, 640, 1008, 2192, 2560, 3200};
8 static int ag_fact[] = {1, 2, 3, 2, 1, -1};
9 static int uag_px_st[] = {0, 640, 1376, 4928, 5664, 6304};
10 
11 void viirs_pxcvt_2uag(int in_pix, int *out_pix, int *nag)
12 /*******************************************************************
13 
14  viirs_pxcvt_2uag
15 
16  purpose: convert pixel number from aggregated to unaggregated
17 
18  Returns type: void
19 
20  Parameters: (in calling order)
21  Type Name I/O Description
22  ---- ---- --- -----------
23  int in_pix I aggregated pixel number
24  int * out_pix O unaggregated pixel number
25  int * nag O number of samples aggregated
26  at this agregated pixel
27 
28  Modification history:
29  Programmer Date Description of change
30  ---------- ---- ---------------------
31  W. Robinson 15-Aug-2011 Original development
32 
33  Note that the mapping from aggregated to unaggregated makes a range of
34  pixel numbers from out_pix -> out_pix + nag - 1
35 
36  *******************************************************************/ {
37  int found, nzone = 6, iz;
38  /*
39  * Find the zone for the pixel and convert it to the unaggregated value
40  */
41  found = 0;
42  for (iz = 0; iz < (nzone - 1); iz++) {
43  if ((in_pix >= ag_px_st[iz]) && (in_pix < ag_px_st[ iz + 1 ])) {
44  *out_pix = uag_px_st[iz] + (in_pix - ag_px_st[iz]) * ag_fact[iz];
45  *nag = ag_fact[iz];
46  found = 1;
47  break;
48  }
49  }
50  /*
51  * extrapolate for values outside actual range
52  */
53  if (found != 1) {
54  *nag = 1;
55  if (in_pix < ag_px_st[0])
56  *out_pix = in_pix;
57  else
58  *out_pix = uag_px_st[ nzone - 1 ] + in_pix - ag_px_st[ nzone - 1 ];
59  }
60 }
61 
62 void viirs_pxcvt_2ag(int in_pix, int *out_pix)
63 /*******************************************************************
64 
65  viirs_pxcvt_2ag
66 
67  purpose: convert pixel number from unaggregated to aggregated
68 
69  Returns type: void
70 
71  Parameters: (in calling order)
72  Type Name I/O Description
73  ---- ---- --- -----------
74  int in_pix I unaggregated pixel number
75  int * out_pix O aggregated pixel number
76 
77  Modification history:
78  Programmer Date Description of change
79  ---------- ---- ---------------------
80  W. Robinson 15-Aug-2011 Original development
81 
82  *******************************************************************/ {
83  int found, nzone = 6, iz;
84  /*
85  * Find the zone for the pixel and convert it to the aggregated value
86  */
87  found = 0;
88  for (iz = 0; iz < (nzone - 1); iz++) {
89  if ((in_pix >= uag_px_st[iz]) && (in_pix < uag_px_st[ iz + 1 ])) {
90  *out_pix = ag_px_st[iz] + (in_pix - uag_px_st[iz]) / ag_fact[iz];
91  found = 1;
92  break;
93  }
94  }
95  /*
96  * extrapolate for values outside actual range
97  */
98  if (found != 1) {
99  if (in_pix < uag_px_st[0])
100  *out_pix = in_pix;
101  else
102  *out_pix = ag_px_st[ nzone - 1 ] + in_pix - uag_px_st[ nzone - 1 ];
103  }
104 }
105 
106 void viirs_pxcvt_agdel(int in_pix, int del, int *out_pix)
107 /*******************************************************************
108 
109  viirs_pxcvt_agdel
110 
111  purpose: add unaggregated samples to aggregated pixel numbers
112 
113  Returns type: void
114 
115  Parameters: (in calling order)
116  Type Name I/O Description
117  ---- ---- --- -----------
118  int in_pix I aggregated pixel number
119  int del I unaggregated sample offset
120  int * out_pix O final aggregated pixel number
121 
122  Modification history:
123  Programmer Date Description of change
124  ---------- ---- ---------------------
125  W. Robinson 15-Aug-2011 Original development
126 
127  *******************************************************************/ {
128  int uag_px, ag;
129  /*
130  * get the unaggregated pixel
131  */
132  viirs_pxcvt_2uag(in_pix, &uag_px, &ag);
133  /*
134  * add the offset, if in (+) direction, make sure it is from highest
135  * unaggregated pixel # possible
136  */
137  uag_px = (del < 0) ? uag_px + del : uag_px + (ag - 1) + del;
138  /*
139  * convert back to aggregated and done
140  */
141  viirs_pxcvt_2ag(uag_px, out_pix);
142 }
void viirs_pxcvt_2ag(int in_pix, int *out_pix)
Definition: viirs_pxcvt.c:62
void viirs_pxcvt_agdel(int in_pix, int del, int *out_pix)
Definition: viirs_pxcvt.c:106
void viirs_pxcvt_2uag(int in_pix, int *out_pix, int *nag)
Definition: viirs_pxcvt.c:11