Changeset 37869
- Timestamp:
- Jan 19, 2015, 11:27:34 AM (12 years ago)
- Location:
- branches/eam_branches/ipp-20150112/Ohana/src
- Files:
-
- 11 edited
-
kapa2/src/InterpretKeys.c (modified) (1 diff)
-
libfits/include/gfitsio.h (modified) (1 diff)
-
libfits/matrix/F_convert_format.c (modified) (2 diffs)
-
libfits/matrix/F_create_M.c (modified) (1 diff)
-
opihi/cmd.data/mcreate.c (modified) (1 diff)
-
opihi/cmd.data/rd.c (modified) (10 diffs)
-
opihi/cmd.data/tv.c (modified) (2 diffs)
-
opihi/cmd.data/wd.c (modified) (1 diff)
-
opihi/lib.shell/BufferOps.c (modified) (1 diff)
-
opihi/lib.shell/convert_to_RPN.c (modified) (1 diff)
-
opihi/lib.shell/stack_math.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20150112/Ohana/src/kapa2/src/InterpretKeys.c
r37807 r37869 98 98 Screen_to_Image (&X, &Y, (double)(event[0].x + 0.5), (double)(event[0].y + 0.5), &image[0].picture); \ 99 99 UpdateStatusBox (graphic, image, X, Y, 0.0, 1); \ 100 Remap (graphic, image); \ 100 101 break; 101 102 // Remap (graphic, image);103 102 104 103 // the number of entries here must match the value of NCHANNELS in contants.h -
branches/eam_branches/ipp-20150112/Ohana/src/libfits/include/gfitsio.h
r37807 r37869 147 147 148 148 int gfits_init_matrix PROTO((Matrix *matrix)); 149 off_t gfits_npix_matrix PROTO((Matrix *matrix)); 149 150 void gfits_add_matrix_value PROTO((Matrix *matrix, off_t x, off_t y, double value)); 150 151 int gfits_convert_format PROTO((Header *header, Matrix *matrix, int outBitpix, double outScale, double outZero, int inBlank, int outUnsign)); -
branches/eam_branches/ipp-20150112/Ohana/src/libfits/matrix/F_convert_format.c
r27435 r37869 90 90 91 91 /*********************** fits convert format ***********************************/ 92 /* this function is safe in the number of axes (can even be 0) */ 92 93 int gfits_convert_format (Header *header, Matrix *matrix, int outBitpix, double outScale, double outZero, int inBlank, int outUnsign) { 93 94 94 unsigned long i, nbytes, Npixels;95 off_t i, nbytes; 95 96 int inBitpix, inUnsign; 96 97 double inScale, inZero; … … 116 117 gfits_modify_alt (header, "UNSIGN", "%t", 1, outUnsign); 117 118 118 Npixels = header[0].Naxis[0]*header[0].Naxis[1];119 nbytes = Npixels * (abs(outBitpix) / 8);119 off_t Npixels = gfits_npix_matrix (matrix); 120 nbytes = Npixels * (abs(outBitpix) / 8); 120 121 121 122 A = inScale / outScale; -
branches/eam_branches/ipp-20150112/Ohana/src/libfits/matrix/F_create_M.c
r35756 r37869 43 43 } 44 44 45 // XXX free buffer if non-null: need to double check for existing frees 45 /*********************** return number of valid pixels *******************************/ 46 off_t gfits_npix_matrix (Matrix *matrix) { 47 48 if (!matrix->Naxes) return 0; 49 50 int i; 51 int Npix = 1; 52 for (i = 0; i < matrix->Naxes; i++) { 53 if (matrix->Naxis[i] == 0) break; 54 Npix *= matrix->Naxis[i]; 55 } 56 return Npix; 57 } -
branches/eam_branches/ipp-20150112/Ohana/src/opihi/cmd.data/mcreate.c
r9275 r37869 3 3 int mcreate (int argc, char **argv) { 4 4 5 int N x, Ny;5 int N; 6 6 Buffer *buf; 7 7 8 int Nz = 0; 9 if ((N = get_argument (argc, argv, "-nz"))) { 10 remove_argument (N, &argc, argv); 11 Nz = atoi (argv[N]); 12 remove_argument (N, &argc, argv); 13 } 14 8 15 if (argc != 4) { 9 gprint (GP_ERR, "USAGE: mcreate <buffer> Nx Ny \n");16 gprint (GP_ERR, "USAGE: mcreate <buffer> Nx Ny [-nz Nz]\n"); 10 17 return (FALSE); 11 18 } 12 19 13 20 if ((buf = SelectBuffer (argv[1], ANYBUFFER, TRUE)) == NULL) return (FALSE); 14 Nx = atof (argv[2]);15 Ny = atof (argv[3]);21 int Nx = atof (argv[2]); 22 int Ny = atof (argv[3]); 16 23 17 24 /* I should encapsulate this in a create_default_buffer */ 18 25 gfits_free_matrix (&buf[0].matrix); 19 26 gfits_free_header (&buf[0].header); 20 CreateBuffer (buf, Nx, Ny, -32, 1.0, 0.0); 27 28 if (Nz) { 29 CreateBuffer3D (buf, Nx, Ny, Nz, -32, 1.0, 0.0); 30 } else { 31 CreateBuffer (buf, Nx, Ny, -32, 1.0, 0.0); 32 } 21 33 return (TRUE); 22 34 } -
branches/eam_branches/ipp-20150112/Ohana/src/opihi/cmd.data/rd.c
r29938 r37869 4 4 int rd (int argc, char **argv) { 5 5 6 int i, N, status, plane, Nplane, extend, Nextend, Nskip, JustHead, blank; 7 int ccdsel, done, Nword, IsCompressed; 8 char region[512], *ccdid, *filename; 9 FILE *f; 6 int i, N, Nskip, blank; 7 int done, Nword; 8 char region[512]; 10 9 Buffer *buf; 11 10 12 JustHead = FALSE;11 int JustHead = FALSE; 13 12 if ((N = get_argument (argc, argv, "-head"))) { 14 13 remove_argument (N, &argc, argv); … … 16 15 } 17 16 18 plane =1;17 int plane = -1; 19 18 if ((N = get_argument (argc, argv, "-plane"))) { 20 19 remove_argument (N, &argc, argv); … … 23 22 } 24 23 25 extend = FALSE;26 Nextend = -1;24 int extend = FALSE; 25 int Nextend = -1; 27 26 if ((N = get_argument (argc, argv, "-x"))) { 28 27 remove_argument (N, &argc, argv); … … 32 31 } 33 32 34 ccdsel = FALSE;35 c cdid = (char *)NULL;33 int ccdsel = FALSE; 34 char *ccdid = NULL; 36 35 if ((N = get_argument (argc, argv, "-n"))) { 37 36 remove_argument (N, &argc, argv); … … 52 51 53 52 /* test if file exists */ 54 f = fopen (argv[2], "r");53 FILE *f = fopen (argv[2], "r"); 55 54 if (f == (FILE *) NULL) { 56 55 gprint (GP_ERR, "file %s not found\n", argv[2]); … … 67 66 68 67 /* save file name */ 69 filename = filebasename (argv[2]);68 char *filename = filebasename (argv[2]); 70 69 strcpy (buf[0].file, filename); 71 70 free (filename); 72 71 73 status = FALSE;74 IsCompressed = FALSE;72 int status = FALSE; 73 int IsCompressed = FALSE; 75 74 76 75 /*** advance to the correct FITS extension ***/ … … 168 167 169 168 /* check for valid plane */ 170 Nplane = buf[0].header.Naxis[2]; 171 if (Nplane == 0) Nplane = 1; 172 if (plane > Nplane) { 173 gprint (GP_ERR, "-plane is too large: %d total planes\n", Nplane); 174 DeleteBuffer (buf); 175 fclose (f); 176 return (FALSE); 169 int Nz = buf[0].header.Naxis[2]; 170 if (plane >= 0) { 171 // we are requesting a specific plane (-1 : all data) 172 int tooFar = Nz ? (plane >= Nz) : (plane > Nz); 173 if (tooFar) { 174 gprint (GP_ERR, "-plane is too large: %d total planes\n", Nz); 175 DeleteBuffer (buf); 176 fclose (f); 177 return (FALSE); 178 } 177 179 } 178 180 179 181 /* load matrix data */ 180 182 if (IsCompressed) { 183 if (plane > -1) { 184 gprint (GP_ERR, "-plane incompatible with compressed image\n"); 185 DeleteBuffer (buf); 186 fclose (f); 187 return (FALSE); 188 } 181 189 FTable ftable; 182 190 Header theader; … … 191 199 // XXX this currently does not work for a cube (we get a cube back, not a specific plane) 192 200 } else { 193 sprintf (region, "-1 -1 -1 -1 %d %d", (plane - 1), plane); 194 status = gfits_fread_matrix_segment (f, &buf[0].matrix, &buf[0].header, region); 201 if (plane > -1) { 202 // read a single plane into a 2D image 203 sprintf (region, "-1 -1 -1 -1 %d %d", (plane - 1), plane); 204 status = gfits_fread_matrix_segment (f, &buf[0].matrix, &buf[0].header, region); 205 buf[0].header.Naxis[2] = 0; 206 buf[0].header.Naxes = 2; 207 gfits_modify (&buf[0].header, "NAXIS", "%d", 1, 2); 208 gfits_modify (&buf[0].header, "NAXIS3", "%d", 1, 0); 209 } else { 210 status = gfits_fread_matrix (f, &buf[0].matrix, &buf[0].header); 211 } 195 212 } 196 213 fclose (f); … … 200 217 DeleteBuffer (buf); 201 218 return (FALSE); 202 }203 204 /* adjust buffer to represent 2D data */205 if (Nplane > 1) {206 buf[0].header.Naxis[2] = 0;207 buf[0].header.Naxes = 2;208 gfits_modify (&buf[0].header, "NAXIS", "%d", 1, 2);209 gfits_delete (&buf[0].header, "NAXIS3", 1);210 219 } 211 220 … … 215 224 buf[0].header.Naxis[1] = 1; 216 225 buf[0].matrix.Naxis[1] = 1; 226 gfits_modify (&buf[0].header, "NAXIS", "%d", 1, 2); 227 gfits_modify (&buf[0].header, "NAXIS2", "%d", 1, 1); 217 228 } 218 229 -
branches/eam_branches/ipp-20150112/Ohana/src/opihi/cmd.data/tv.c
r37807 r37869 28 28 } 29 29 30 int plane = 0; 31 if ((N = get_argument (argc, argv, "-plane"))) { 32 remove_argument (N, &argc, argv); 33 plane = atoi (argv[N]); 34 remove_argument (N, &argc, argv); 35 } 36 if (plane < 0) { 37 gprint (GP_ERR, " ERROR: -plane (plane) : cannot be negative\n"); 38 return (FALSE); 39 } 40 30 41 /* shell exits on pipe close, FIX */ 31 42 if ((N = get_argument (argc, argv, "-kill"))) { … … 55 66 GetCoords (&coords, &buf[0].header); 56 67 57 image.data1d = (float *) buf[0].matrix.buffer;58 68 image.Nx = buf[0].matrix.Naxis[0]; 59 69 image.Ny = buf[0].matrix.Naxis[1]; 70 71 int tooBig = buf[0].matrix.Naxis[2] ? (plane >= buf[0].matrix.Naxis[2]) : plane > 0; 72 if (tooBig) { 73 gprint (GP_ERR, " ERROR: -plane (plane) : out of bounds (%d vs %d)\n", plane, buf[0].matrix.Naxis[2]); 74 return (FALSE); 75 } 76 int Npix2D = image.Nx * image.Ny; 77 78 float *imdata = (float *) buf[0].matrix.buffer; 79 image.data1d = &imdata[plane*Npix2D]; 60 80 61 81 // send only the root of the file, not the full path -
branches/eam_branches/ipp-20150112/Ohana/src/opihi/cmd.data/wd.c
r27435 r37869 81 81 memcpy (temp_header.buffer, buf[0].header.buffer, temp_header.datasize); 82 82 83 if (temp_header.Naxes) { 84 // the inBlank value probably does not matter: temp_matrix is float, so nan is used 85 gfits_convert_format (&temp_header, &temp_matrix, outBitpix, outScale, outZero, 0xffff, outUnsign); 86 } else { 87 gfits_modify (&temp_header, "BITPIX", "%d", 1, outBitpix); 88 gfits_modify (&temp_header, "BSCALE", "%lf", 1, outScale); 89 gfits_modify (&temp_header, "BZERO", "%lf", 1, outZero); 90 gfits_modify_alt (&temp_header, "UNSIGN", "%t", 1, outUnsign); 91 } 83 gfits_convert_format (&temp_header, &temp_matrix, outBitpix, outScale, outZero, 0xffff, outUnsign); 92 84 85 // Extend puts the output matrix in the first available non-PHU slot (ie, the last one) 86 // it updates NEXTEND and set EXTEND to TRUE, and modifies the PHU header (neither should happen) 87 // if those keywords do not exist... 93 88 if (Extend) { 94 89 Header Xhead; -
branches/eam_branches/ipp-20150112/Ohana/src/opihi/lib.shell/BufferOps.c
r37855 r37869 120 120 } 121 121 122 // buffer is 1D array referenced in the order: 123 // buffer[x + Nx*y + Nx*Ny*z + ...] 122 124 int CreateBuffer3D (Buffer *buf, int Nx, int Ny, int Nz, int bitpix, float bzero, float bscale) { 123 125 -
branches/eam_branches/ipp-20150112/Ohana/src/opihi/lib.shell/convert_to_RPN.c
r36679 r37869 60 60 if (!strcmp (argv[i], "xramp")) { type = ST_UNARY; goto gotit; } 61 61 if (!strcmp (argv[i], "yramp")) { type = ST_UNARY; goto gotit; } 62 if (!strcmp (argv[i], "zramp")) { type = ST_UNARY; goto gotit; } 62 63 if (!strcmp (argv[i], "ramp")) { type = ST_UNARY; goto gotit; } 63 64 if (!strcmp (argv[i], "zero")) { type = ST_UNARY; goto gotit; } -
branches/eam_branches/ipp-20150112/Ohana/src/opihi/lib.shell/stack_math.c
r37857 r37869 127 127 int MMM_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) { 128 128 129 int i , Npix;129 int i; 130 130 float *out, *M1, *M2, *M3; 131 131 char line[512]; // this is only used to report an error 132 132 133 Npix = 1; 134 for (i = 0; i < V1[0].buffer[0].matrix.Naxes; i++) { 135 if (V1[0].buffer[0].matrix.Naxis[i] == 0) break; 136 Npix *= V1[0].buffer[0].matrix.Naxis[i]; 137 } 133 int Npix = gfits_npix_matrix (&V1[0].buffer[0].matrix); 138 134 139 135 if (V1[0].type == ST_MATRIX_TMP) { /** use V1 as temp buffer **/ … … 725 721 int MM_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) { 726 722 727 int i , Npix;723 int i; 728 724 float *out, *M1, *M2; 729 725 char line[512]; // this is only used to report an error 730 726 731 Npix = 1; 732 for (i = 0; i < V1[0].buffer[0].matrix.Naxes; i++) { 733 if (V1[0].buffer[0].matrix.Naxis[i] == 0) break; 734 Npix *= V1[0].buffer[0].matrix.Naxis[i]; 735 } 727 int Npix = gfits_npix_matrix (&V1[0].buffer[0].matrix); 736 728 737 729 if (V1[0].type == ST_MATRIX_TMP) { /** use V1 as temp buffer **/ … … 809 801 int MS_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) { 810 802 811 int i , Npix;803 int i; 812 804 char line[512]; // this is only used to report an error 813 805 814 Npix = 1; 815 for (i = 0; i < V1[0].buffer[0].matrix.Naxes; i++) { 816 if (V1[0].buffer[0].matrix.Naxis[i] == 0) break; 817 Npix *= V1[0].buffer[0].matrix.Naxis[i]; 818 } 806 int Npix = gfits_npix_matrix (&V1[0].buffer[0].matrix); 819 807 820 808 /* if possible, use V1 as temp buffer, otherwise create new one */ … … 890 878 int SM_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) { 891 879 892 int i , Npix;880 int i; 893 881 char line[512]; // this is only used to report an error 894 882 895 Npix = 1; 896 for (i = 0; i < V2[0].buffer[0].matrix.Naxes; i++) { 897 if (V2[0].buffer[0].matrix.Naxis[i] == 0) break; 898 Npix *= V2[0].buffer[0].matrix.Naxis[i]; 899 } 883 int Npix = gfits_npix_matrix (&V2[0].buffer[0].matrix); 900 884 901 885 if (V2[0].type == ST_MATRIX_TMP) { /* V2[0] is NOT temporary, we can't use it for storage */ … … 1252 1236 if (!strcmp (op, "xramp")) V_FUNC(i, ST_SCALAR_INT); 1253 1237 if (!strcmp (op, "yramp")) V_FUNC(0, ST_SCALAR_INT); 1254 /* xramp and yramp above only make sense for matrices. for vectors, xramp = ramp, yramp = zero */ 1238 if (!strcmp (op, "zramp")) V_FUNC(0, ST_SCALAR_INT); 1239 /* xramp, yramp, zramp above only make sense for matrices. for vectors, xramp = ramp, yramp = zero */ 1255 1240 1256 1241 # undef V_FUNC … … 1271 1256 int M_unary (StackVar *OUT, StackVar *V1, char *op) { 1272 1257 1273 int i, j, Npix;1258 int i, j, k; 1274 1259 float *out, *M1; 1275 1260 1276 Npix = 1; 1277 for (i = 0; i < V1[0].buffer[0].matrix.Naxes; i++) { 1278 if (V1[0].buffer[0].matrix.Naxis[i] == 0) break; 1279 Npix *= V1[0].buffer[0].matrix.Naxis[i]; 1280 } 1261 int Npix = gfits_npix_matrix (&V1[0].buffer[0].matrix); 1281 1262 1282 1263 if (V1[0].type == ST_MATRIX_TMP) { … … 1336 1317 int Nx = V1[0].buffer[0].matrix.Naxis[0]; 1337 1318 int Ny = V1[0].buffer[0].matrix.Naxis[1]; 1338 for (j = 0; j < Ny; j++) { 1339 for (i = 0; i < Nx; i++, out++, M1++) { 1340 *out = i; 1319 int Nz = MAX (1, V1[0].buffer[0].matrix.Naxis[2]); 1320 for (k = 0; k < Nz; k++) { 1321 for (j = 0; j < Ny; j++) { 1322 for (i = 0; i < Nx; i++, out++, M1++) { 1323 *out = i; 1324 } 1341 1325 } 1342 1326 } … … 1345 1329 int Nx = V1[0].buffer[0].matrix.Naxis[0]; 1346 1330 int Ny = V1[0].buffer[0].matrix.Naxis[1]; 1347 for (j = 0; j < Ny; j++) { 1348 for (i = 0; i < Nx; i++, out++, M1++) { 1349 *out = j; 1331 int Nz = MAX (1, V1[0].buffer[0].matrix.Naxis[2]); 1332 for (k = 0; k < Nz; k++) { 1333 for (j = 0; j < Ny; j++) { 1334 for (i = 0; i < Nx; i++, out++, M1++) { 1335 *out = j; 1336 } 1337 } 1338 } 1339 } 1340 if (!strcmp (op, "zramp")) { 1341 int Nx = V1[0].buffer[0].matrix.Naxis[0]; 1342 int Ny = V1[0].buffer[0].matrix.Naxis[1]; 1343 int Nz = MAX (1, V1[0].buffer[0].matrix.Naxis[2]); 1344 for (k = 0; k < Nz; k++) { 1345 for (j = 0; j < Ny; j++) { 1346 for (i = 0; i < Nx; i++, out++, M1++) { 1347 *out = k; 1348 } 1350 1349 } 1351 1350 }
Note:
See TracChangeset
for help on using the changeset viewer.
