Changeset 9726 for trunk/Ohana/src/opihi/cmd.data
- Timestamp:
- Oct 24, 2006, 11:58:18 AM (20 years ago)
- Location:
- trunk/Ohana/src/opihi/cmd.data
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/Makefile
r8177 r9726 64 64 $(SDIR)/load.$(ARCH).o \ 65 65 $(SDIR)/lookup.$(ARCH).o \ 66 $(SDIR)/mkrgb.$(ARCH).o \ 66 67 $(SDIR)/mcreate.$(ARCH).o \ 67 68 $(SDIR)/medacc.$(ARCH).o \ -
trunk/Ohana/src/opihi/cmd.data/init.c
r8177 r9726 49 49 int load PROTO((int, char **)); 50 50 int lookup PROTO((int, char **)); 51 int mkrgb PROTO((int, char **)); 51 52 int mcreate PROTO((int, char **)); 52 53 int medacc PROTO((int, char **)); … … 160 161 {"load", load, "load an SAOimage style overlay"}, 161 162 {"lookup", lookup, "convert vector via lookup table (vector pair)"}, 163 {"mkrgb", mkrgb, "convert 3 images to rgb jpeg"}, 162 164 {"mcreate", mcreate, "create a matrix"}, 163 165 {"medacc", medacc, "accumulate vector values in another vector"}, -
trunk/Ohana/src/opihi/cmd.data/shift.c
r7917 r9726 7 7 float *Vin, *Vot; 8 8 double Dx, Dy, fdx, fdy; 9 Buffer * buf;9 Buffer *in, *out; 10 10 11 11 ROLL = FALSE; … … 15 15 } 16 16 17 if (argc != 4) {18 gprint (GP_ERR, "USAGE: shift <buffer>dx dy\n");17 if (argc != 5) { 18 gprint (GP_ERR, "USAGE: shift (input) (output) dx dy\n"); 19 19 return (FALSE); 20 20 } 21 21 22 if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE); 22 // define the input buffer and examine the shift 23 if ((in = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE); 23 24 24 Dx = -atof (argv[2]);25 Dy = -atof (argv[3]);25 Dx = atof (argv[3]); 26 Dy = atof (argv[4]); 26 27 27 28 dx = Dx; … … 29 30 fdx = Dx - dx; 30 31 fdy = Dy - dy; 31 if (fdx < -0.001) {dx -= 1; fdx += 1;} 32 if (fdy < -0.001) {dy -= 1; fdy += 1;} 32 if (fdx < -0.000001) {dx -= 1; fdx += 1;} 33 if (fdy < -0.000001) {dy -= 1; fdy += 1;} 34 // we always specify a positive fractional shift 35 // the above choice defines a minimum fractional shift of 1e-5 33 36 34 nx = buf[0].matrix.Naxis[0];35 ny = buf[0].matrix.Naxis[1];37 nx = in[0].matrix.Naxis[0]; 38 ny = in[0].matrix.Naxis[1]; 36 39 37 if ((dx > buf[0].matrix.Naxis[0]) || (dy > buf[0].matrix.Naxis[1])) {40 if ((dx > nx) || (dy > ny)) { 38 41 gprint (GP_ERR, "shifting data out of image\n"); 39 42 return (FALSE); 40 43 } 41 44 42 if (dx < 0) { 43 DXin = 0; 44 DXot = -dx; 45 } else { 46 DXin = dx; 47 DXot = 0; 45 // define the output buffer 46 if ((out = SelectBuffer (argv[2], ANYBUFFER, TRUE)) == NULL) return (FALSE); 47 48 gfits_free_matrix (&out[0].matrix); 49 gfits_free_header (&out[0].header); 50 CreateBuffer (out, nx, ny, -32, 0.0, 1.0); 51 52 DXin = (dx < 0) ? -dx : 0; 53 DXot = (dx < 0) ? 0 : dx; 54 DYin = (dy < 0) ? -dy : 0; 55 DYot = (dy < 0) ? 0 : dy; 56 57 for (j = 0; j < ny - abs(dy); j++) { 58 Vin = (float *)(in[0].matrix.buffer) + (j + DYin)*nx + DXin; 59 Vot = (float *)(out[0].matrix.buffer) + (j + DYot)*nx + DXot; 60 for (i = 0; i < nx - abs(dx); i++, Vin++, Vot++) { 61 *Vot = *Vin; 62 } 63 // fill in the exposed x-border with 0.0 64 Vot = (dx > 0) ? 65 (float *)(out[0].matrix.buffer) + (j + DYot)*nx : 66 (float *)(out[0].matrix.buffer) + (j + DYot)*nx + nx - abs(dx); 67 for (i = 0; i < abs(dx); i++, Vot++) { 68 *Vot = 0.0; 69 } 48 70 } 49 if (dy < 0) {50 DYin = 0;51 DYot = -dy;52 } else {53 DYin = dy;54 DYot = 0;55 }56 57 if ((dy > 0) || ((dy == 0) && (dx > 0))) {58 for (j = 0; j < ny - fabs(dy); j++) {59 Vin = (float *)(buf[0].matrix.buffer) + (j + DYin)*nx + DXin;60 Vot = (float *)(buf[0].matrix.buffer) + (j + DYot)*nx + DXot;61 for (i = 0; i < nx - fabs(dx); i++, Vin++, Vot++) {62 *Vot = *Vin;63 }64 if (dx < 0)65 Vot = (float *)(buf[0].matrix.buffer) + (j + DYot)*nx;66 for (i = 0; i < fabs(dx); i++, Vot++) {67 *Vot = 0.0;68 }69 }70 Vot = (float *)(buf[0].matrix.buffer) + nx*(ny - abs(dy));71 for (j = 0; j < nx * fabs(dy); j++, Vot++) {72 *Vot = 0.0;73 }74 } else {75 for (j = ny - fabs(dy) - 1; j >= 0; j--) {76 Vin = (float *)(buf[0].matrix.buffer) + (j + DYin)*nx + DXin + nx - abs(dx) - 1;77 Vot = (float *)(buf[0].matrix.buffer) + (j + DYot)*nx + DXot + nx - abs(dx) - 1;78 for (i = 0; i < nx - fabs(dx); i++, Vin--, Vot--) {79 *Vot = *Vin;80 }81 if (dx < 0)82 Vot = (float *)(buf[0].matrix.buffer) + (j + DYot)*nx;83 for (i = 0; i < fabs(dx); i++, Vot++) {84 *Vot = 0.0;85 }86 }87 Vot = (float *)(buf[0].matrix.buffer);88 for (j = 0; j < nx * fabs(dy); j++, Vot++) {89 *Vot = 0.0;90 }91 }92 71 72 // fill in the exposed y-border with 0.0 73 Vot = (dy > 0) ? 74 (float *)(out[0].matrix.buffer) : 75 (float *)(out[0].matrix.buffer) + (ny - abs(dy))*nx; 76 77 for (j = 0; j < nx * abs(dy); j++, Vot++) { 78 *Vot = 0.0; 79 } 80 81 // apply the fractional shift 93 82 gprint (GP_ERR, "%f %f\n", fdx, fdy); 94 83 if ((fdx > 0) || (fdy > 0)) { … … 101 90 f11 = fdx * fdy; 102 91 103 Vin = (float *) buf[0].matrix.buffer;104 Vot = (float *) buf[0].matrix.buffer;92 Vin = (float *)out[0].matrix.buffer; 93 Vot = (float *)out[0].matrix.buffer; 105 94 for (j = 0; j < ny - 1; j++) { 106 95 for (i = 0; i < nx - 1; i++, Vin++, Vot++) { 107 96 value = Vin[ 0] * f00; 108 97 value += Vin[ 1] * f01; 109 value += Vin[n y] * f10;110 value += Vin[n y+1] * f11;98 value += Vin[nx ] * f10; 99 value += Vin[nx+1] * f11; 111 100 *Vot = value; 112 101 }
Note:
See TracChangeset
for help on using the changeset viewer.
