- Timestamp:
- Jul 9, 2019, 4:40:10 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20190329/src/opihi/cmd.data/cut.c
r40812 r40830 1 1 # include "data.h" 2 2 3 enum {SUM, MEAN, MEDIAN, INNER };3 enum {SUM, MEAN, MEDIAN, INNER, NGOOD}; 4 4 5 5 double cutstat (float *value, int Nvalue, int mode) { … … 50 50 return output; 51 51 } 52 if (mode == NGOOD) { 53 return Nvalue; 54 } 52 55 if ((mode == MEAN) || (mode == SUM)) { 53 56 for (int i = 0; i < Nvalue; i++) { … … 70 73 71 74 Mode = SUM; 75 if ((N = get_argument (argc, argv, "-sum"))) { 76 remove_argument (N, &argc, argv); 77 Mode = SUM; 78 } 72 79 if ((N = get_argument (argc, argv, "-median"))) { 73 80 remove_argument (N, &argc, argv); … … 81 88 remove_argument (N, &argc, argv); 82 89 Mode = INNER; 90 } 91 if ((N = get_argument (argc, argv, "-ngood"))) { 92 remove_argument (N, &argc, argv); 93 Mode = NGOOD; 83 94 } 84 95 … … 98 109 Ny = buf[0].matrix.Naxis[1]; 99 110 100 if ((sx < 0) || (sy < 0) || (sx+nx > Nx) || (sy+ny > Ny)) { 101 gprint (GP_ERR, "region out of range\n"); 111 // ny & nx do not need to be constrained by the buffer, but they do need to be sensible 112 if ((nx < 0) || (ny < 0) || (nx > 1e8) || (ny > 1e8)) { 113 gprint (GP_ERR, "warning : extraction size is crazy: %d,%d\n", nx, ny); 102 114 return (FALSE); 103 115 } … … 119 131 120 132 for (i = 0; i < nx; i++) { 133 // for out-of-range areas, set the output pixels to NAN 134 if (i + sx < 0) { 135 yvec[0].elements.Flt[i] = NAN; 136 continue; 137 } 138 if (i + sx >= Nx) { 139 yvec[0].elements.Flt[i] = NAN; 140 continue; 141 } 142 121 143 /* accumulate values */ 144 // skip out-of-range areas in y 145 if (sy < 0) { 146 ny += sy; 147 sy = 0; 148 } 149 if (sy > Ny) sy = Ny; 150 if (sy + ny >= Ny) ny = Ny - sy; 151 122 152 Vin = (float *)(buf[0].matrix.buffer) + sy*Nx + sx + i; 123 153 int Npix = 0; 124 154 for (j = 0; j < ny; j++, Vin += Nx) { 125 155 if (!isfinite(*Vin)) continue; 126 Vbuf[ j] = *Vin;156 Vbuf[Npix] = *Vin; 127 157 Npix ++; 128 158 } … … 143 173 144 174 for (i = 0; i < ny; i++) { 175 // for out-of-range areas, set the output pixels to NAN 176 if (i + sy < 0) { 177 yvec[0].elements.Flt[i] = NAN; 178 continue; 179 } 180 if (i + sy >= Ny) { 181 yvec[0].elements.Flt[i] = NAN; 182 continue; 183 } 184 145 185 /* accumulate values */ 186 // skip out-of-range areas in x 187 if (sx < 0) { 188 nx += sx; 189 sx = 0; 190 } 191 if (sx > Nx) sx = Nx; 192 if (sx + nx >= Nx) nx = Nx - sx; 193 146 194 Vin = (float *)(buf[0].matrix.buffer) + (sy + i)*Nx + sx; 147 195 int Npix = 0; 148 196 for (j = 0; j < nx; j++, Vin ++) { 149 197 if (!isfinite(*Vin)) continue; 150 Vbuf[ j] = *Vin;198 Vbuf[Npix] = *Vin; 151 199 Npix ++; 152 200 }
Note:
See TracChangeset
for help on using the changeset viewer.
