OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
resize_2d.c
Go to the documentation of this file.
1 int resize_2d(float *in_arr, int inpix, int inlin,
2  int outpix, int outlin, float *out_arr)
3 /*******************************************************************
4 
5  resize_2d
6 
7  purpose: resize a 2d float array to a new size. all arrays must
8  be pre-allocated
9 
10  Returns type: int - 0 if all went well,
11  -1 otherwise
12 
13  Parameters: (in calling order)
14  Type Name I/O Description
15  ---- ---- --- -----------
16  float * in_arr I input array size [npix, nlin]
17  int inpix I # input pixels (columns)
18  int inlin I # input lines (rows)
19  int outnpix I # output pixels (columns)
20  int outnlin I # output lines (rows)
21  float * out_arr O final output array
22 
23  Modification history:
24  Programmer Date Description of change
25  ---------- ---- ---------------------
26  W. Robinson 6-Feb-1997 Original development
27 
28  *******************************************************************/
29  {
30  float ratio_l, ratio_p;
31  int op, oln, iln, ipx, ip, opx;
32  /*
33  * do some quick checks
34  */
35  if (inpix <= 0 || inlin <= 0 || outpix <= 0 || outlin <= 0) {
36  return -1;
37  }
38  /*
39  * find the ratio between the input and output size in lines and pixels
40  * (the -1 will convert the 0 origin indicies correctly)
41  */
42  ratio_l = (float) (inlin - 1) / (float) (outlin - 1);
43  ratio_p = (float) (inpix - 1) / (float) (outpix - 1);
44 
45  /*
46  * loop thru the file and assign the closest input pixel to each output
47  * the input line, pixel are computed as the input * ratio. .5 will
48  * make the truncation go to the closest value
49  */
50  op = 0;
51  for (oln = 0; oln < outlin; oln++) {
52  iln = (int) ((float) oln * ratio_l + .5);
53 
54  for (opx = 0; opx < outpix; opx++) {
55  ipx = (int) ((float) opx * ratio_p + .5);
56  ip = ipx + iln * inpix;
57 
58  /* out_arr[op++] = in_arr[ip]; */
59 
60  *(out_arr + op++) = *(in_arr + ip);
61  }
62  }
63  return 0;
64 }
int resize_2d(float *in_arr, int inpix, int inlin, int outpix, int outlin, float *out_arr)
Definition: resize_2d.c:1