Changeset 42942 for trunk/Ohana/src/opihi/cmd.data
- Timestamp:
- Nov 12, 2025, 5:00:47 PM (8 months ago)
- Location:
- trunk/Ohana/src/opihi/cmd.data
- Files:
-
- 2 edited
-
section.c (modified) (5 diffs)
-
tdhistogram.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/section.c
r31160 r42942 1 1 # include "data.h" 2 2 3 enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL, BG, IMAGE };3 enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL, BG, IMAGE, IMCENTER}; 4 4 5 5 int section (int argc, char **argv) { … … 17 17 } 18 18 if ((N = get_argument (argc, argv, "-up"))) { 19 if (action != NONE) goto escape; 19 20 action = UP; 20 21 remove_argument (N, &argc, argv); 21 22 } 22 23 if ((N = get_argument (argc, argv, "-down"))) { 24 if (action != NONE) goto escape; 23 25 action = DOWN; 24 26 remove_argument (N, &argc, argv); 25 27 } 26 28 if ((N = get_argument (argc, argv, "-top"))) { 29 if (action != NONE) goto escape; 27 30 action = TOP; 28 31 remove_argument (N, &argc, argv); 29 32 } 30 33 if ((N = get_argument (argc, argv, "-bottom"))) { 34 if (action != NONE) goto escape; 31 35 action = BOTTOM; 32 36 remove_argument (N, &argc, argv); 33 37 } 34 38 if ((N = get_argument (argc, argv, "-imtool"))) { 39 if (action != NONE) goto escape; 35 40 action = TOOL; 36 41 remove_argument (N, &argc, argv); … … 41 46 background = -1; // invisible 42 47 if ((N = get_argument (argc, argv, "-bg"))) { 48 if (action != NONE) goto escape; 43 49 remove_argument (N, &argc, argv); 44 50 if (!strcasecmp (argv[N], "NONE")) { … … 52 58 53 59 if ((N = get_argument (argc, argv, "-image"))) { 60 if (action != NONE) goto escape; 54 61 remove_argument (N, &argc, argv); 55 62 action = IMAGE; 63 } 64 65 if ((N = get_argument (argc, argv, "-imcenter"))) { 66 if (action != NONE) goto escape; 67 remove_argument (N, &argc, argv); 68 action = IMCENTER; 56 69 } 57 70 … … 65 78 FREE (name); 66 79 67 /* list sections */ 68 if ((argc == 1) && (action == NONE)) { 69 KapaGetSection (kapa, "*"); 70 gprint (GP_ERR, "USAGE: section name [x y dx dy] or [options]\n"); 71 gprint (GP_ERR, "OPTIONS: -list : show properties of all sections\n"); 72 gprint (GP_ERR, " -up : move section up in display stack\n"); 73 gprint (GP_ERR, " -down : move section down in display stack\n"); 74 gprint (GP_ERR, " -top : move section to top of display stack\n"); 75 gprint (GP_ERR, " -bottom : move section to bottom of display stack\n"); 76 gprint (GP_ERR, " -imtool (position) : set location of image zoom / status box\n"); 77 gprint (GP_ERR, " (position may be: -x, +x, -y, +y, none)\n"); 78 gprint (GP_ERR, " -image : define section upper-right corner so image fills the section\n"); 79 gprint (GP_ERR, " -bg (color) : set background color (see style -c help for color choices)\n"); 80 81 return (TRUE); 82 } 83 84 if ((argc != 2) && (action != NONE)) { 85 gprint (GP_ERR, "can only use dash options without numbers\n"); 80 // deal with these cases first 81 if (action == NONE) { 82 if (argc == 1) { // command: section 83 gprint (GP_ERR, "USAGE: section name x y dx dy\n"); 84 gprint (GP_ERR, " section name -image x y\n"); 85 gprint (GP_ERR, " section name [options]\n"); 86 gprint (GP_ERR, "OPTIONS: -list : show properties of all sections\n"); 87 gprint (GP_ERR, " -up : move section up in display stack\n"); 88 gprint (GP_ERR, " -down : move section down in display stack\n"); 89 gprint (GP_ERR, " -top : move section to top of display stack\n"); 90 gprint (GP_ERR, " -bottom : move section to bottom of display stack\n"); 91 gprint (GP_ERR, " -imtool (position) : set location of image zoom / status box\n"); 92 gprint (GP_ERR, " (position may be: -x, +x, -y, +y, none)\n"); 93 gprint (GP_ERR, " -image : define section upper-right corner so image fills the section\n"); 94 gprint (GP_ERR, " -bg (color) : set background color (see style -c help for color choices or use NONE)\n"); 95 return (TRUE); 96 } 97 if (argc == 2) { // command: section name 98 KapaSelectSection (kapa, argv[1]); 99 return TRUE; 100 } 101 if (argc == 6) { // command: section name x y dx dy 102 /* set section */ 103 section.name = argv[1]; 104 section.x = atof (argv[2]); 105 section.y = atof (argv[3]); 106 section.dx = atof (argv[4]); 107 section.dy = atof (argv[5]); 108 section.bg = -2; // bg must be set on its own 109 KapaSetSection (kapa, §ion); 110 return (TRUE); 111 } 112 goto escape; 113 } 114 115 // list properties of the specified section, or all sections 116 if (action == LIST) { 117 if (argc == 1) { 118 KapaGetSection (kapa, "*"); 119 return TRUE; 120 } 121 if (argc == 2) { 122 KapaGetSection (kapa, argv[1]); 123 KapaSelectSection (kapa, argv[1]); 124 return TRUE; 125 } 126 goto escape; 127 } 128 129 if ((action == IMAGE) || (action == IMCENTER)) { 130 if (argc != 4) goto escape; 131 } else { 132 if (argc != 2) goto escape; 133 } 134 135 /* select / show section */ 136 switch (action) { 137 case UP: 138 KapaMoveSection (kapa, argv[1], "up"); 139 break; 140 case DOWN: 141 KapaMoveSection (kapa, argv[1], "down"); 142 break; 143 case TOP: 144 KapaMoveSection (kapa, argv[1], "top"); 145 break; 146 case BOTTOM: 147 KapaMoveSection (kapa, argv[1], "bottom"); 148 break; 149 150 case BG: 151 KapaSectionBG (kapa, argv[1], background); 152 break; 153 154 case TOOL: 155 KapaSelectSection (kapa, argv[1]); 156 if (!strcmp(location, "-x")) { 157 KapaSetToolbox (kapa, 1); 158 break; 159 } 160 if (!strcmp(location, "+x")) { 161 KapaSetToolbox (kapa, 3); 162 break; 163 } 164 if (!strcmp(location, "-y")) { 165 KapaSetToolbox (kapa, 2); 166 break; 167 } 168 if (!strcmp(location, "+y")) { 169 KapaSetToolbox (kapa, 4); 170 break; 171 } 172 if (!strcmp(location, "none")) { 173 KapaSetToolbox (kapa, 0); 174 break; 175 } 176 gprint (GP_ERR, "unknown toolbox location %s\n", location); 177 gprint (GP_ERR, "valid values: -x, +x, -y, +y, none\n"); 86 178 return (FALSE); 87 } 88 89 if (argc == 2) { 90 /* select / show section */ 91 switch (action) { 92 case NONE: 93 KapaSelectSection (kapa, argv[1]); 94 break; 95 96 case UP: 97 KapaMoveSection (kapa, argv[1], "up"); 98 break; 99 case DOWN: 100 KapaMoveSection (kapa, argv[1], "down"); 101 break; 102 case TOP: 103 KapaMoveSection (kapa, argv[1], "top"); 104 break; 105 case BOTTOM: 106 KapaMoveSection (kapa, argv[1], "bottom"); 107 break; 108 109 case BG: 110 KapaSectionBG (kapa, argv[1], background); 111 break; 112 113 case TOOL: 114 if (!strcmp(location, "-x")) { 115 KapaSetToolbox (kapa, 1); 116 break; 117 } 118 if (!strcmp(location, "+x")) { 119 KapaSetToolbox (kapa, 3); 120 break; 121 } 122 if (!strcmp(location, "-y")) { 123 KapaSetToolbox (kapa, 2); 124 break; 125 } 126 if (!strcmp(location, "+y")) { 127 KapaSetToolbox (kapa, 4); 128 break; 129 } 130 if (!strcmp(location, "none")) { 131 KapaSetToolbox (kapa, 0); 132 break; 133 } 134 gprint (GP_ERR, "unknown toolbox location %s\n", location); 135 gprint (GP_ERR, "valid values: -x, +x, -y, +y, none\n"); 136 return (FALSE); 137 138 case LIST: 139 KapaGetSection (kapa, argv[1]); 140 break; 141 } 142 return (TRUE); 143 } 144 145 if (argc == 4) { 146 /* set section */ 147 section.name = argv[1]; 148 section.x = atof (argv[2]); 149 section.y = atof (argv[3]); 150 section.bg = background; 151 KapaSetSectionByImage (kapa, §ion); 152 return (TRUE); 153 } 154 155 if (argc == 6) { 156 /* set section */ 157 section.name = argv[1]; 158 section.x = atof (argv[2]); 159 section.y = atof (argv[3]); 160 section.dx = atof (argv[4]); 161 section.dy = atof (argv[5]); 162 section.bg = background; 163 KapaSetSection (kapa, §ion); 164 return (TRUE); 165 } 166 gprint (GP_ERR, "USAGE: section name [x y dx dy]\n"); 167 gprint (GP_ERR, "USAGE: section name [-image x y] : width based on current image\n"); 168 gprint (GP_ERR, "USAGE: section name [-list] [-up] [-down] [-top] [-bottom]\n"); 179 180 case IMAGE: 181 /* set section */ 182 section.name = argv[1]; 183 section.x = atof (argv[2]); 184 section.y = atof (argv[3]); 185 section.bg = -2; 186 KapaSetSectionByImage (kapa, §ion); 187 return (TRUE); 188 189 case IMCENTER: 190 /* set section */ 191 section.name = argv[1]; 192 section.x = atof (argv[2]); 193 section.y = atof (argv[3]); 194 KapaSetSectionCenterByImage (kapa, §ion); 195 return (TRUE); 196 197 case NONE: 198 case LIST: 199 default: 200 gprint (GP_ERR, "oops, programming error in section.c:171\n"); 201 break; 202 } 203 return (TRUE); 204 205 escape: 206 gprint (GP_ERR, "USAGE: section name : select the section\n"); 207 gprint (GP_ERR, "USAGE: section name x y dx dy : define section location\n"); 208 gprint (GP_ERR, "USAGE: section name -image x y : width based on current image\n"); 209 gprint (GP_ERR, "USAGE: section name -imtool (position) : width based on current image\n"); 210 gprint (GP_ERR, "USAGE: section name [-list] [-up] [-down] [-top] [-bottom] [-bg color]\n"); 211 gprint (GP_ERR, " only one -OPTION at a time\n"); 169 212 return (FALSE); 170 213 } -
trunk/Ohana/src/opihi/cmd.data/tdhistogram.c
r41891 r42942 5 5 int tdhistogram (int argc, char **argv) { 6 6 7 int i, N x, Ny, Nz, N;7 int i, N; 8 8 float *val; 9 9 Buffer *bf; 10 10 Vector *vx, *vy, *vz, *range; 11 11 opihi_flt *x, *y, *z; 12 int kapa; 13 Graphdata graphmode; 14 15 int useGraph = FALSE; 16 if ((N = get_argument (argc, argv, "-graph"))) { 17 remove_argument (N, &argc, argv); 18 useGraph = TRUE; 19 if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE; 20 } 12 21 13 22 int reuse = FALSE; 14 23 if ((N = get_argument (argc, argv, "-reuse"))) { 24 if (useGraph) { gprint (GP_ERR, "-reuse and -graph are incompatible\n"); return FALSE; } 15 25 remove_argument (N, &argc, argv); 16 26 reuse = TRUE; 27 } 28 29 int Nx = 100; 30 double dx = NAN; 31 if ((N = get_argument (argc, argv, "-dx"))) { 32 if (useGraph) { gprint (GP_ERR, "-dx and -graph are incompatible\n"); return FALSE; } 33 remove_argument (N, &argc, argv); 34 dx = atof(argv[N]); 35 remove_argument (N, &argc, argv); 36 } 37 if ((N = get_argument (argc, argv, "-Nx"))) { 38 if (useGraph) { gprint (GP_ERR, "-Nx and -graph are incompatible\n"); return FALSE; } 39 if (isfinite(dx)) { gprint (GP_ERR, "-Nx and -dx are incompatible\n"); return FALSE; } 40 remove_argument (N, &argc, argv); 41 Nx = atoi(argv[N]); 42 remove_argument (N, &argc, argv); 43 } 44 45 int Ny = 100; 46 double dy = NAN; 47 if ((N = get_argument (argc, argv, "-dy"))) { 48 if (useGraph) { gprint (GP_ERR, "-dx and -graph are incompatible\n"); return FALSE; } 49 remove_argument (N, &argc, argv); 50 dy = atof(argv[N]); 51 remove_argument (N, &argc, argv); 52 } 53 if ((N = get_argument (argc, argv, "-Ny"))) { 54 if (useGraph) { gprint (GP_ERR, "-Ny and -graph are incompatible\n"); return FALSE; } 55 if (isfinite(dy)) { gprint (GP_ERR, "-Ny and -dy are incompatible\n"); return FALSE; } 56 remove_argument (N, &argc, argv); 57 Ny = atoi(argv[N]); 58 remove_argument (N, &argc, argv); 59 } 60 61 int Nz = 100; 62 double dz = NAN; 63 if ((N = get_argument (argc, argv, "-dz"))) { 64 remove_argument (N, &argc, argv); 65 dz = atof(argv[N]); 66 remove_argument (N, &argc, argv); 67 } 68 if ((N = get_argument (argc, argv, "-Nz"))) { 69 if (useGraph) { gprint (GP_ERR, "-Nz and -graph are incompatible\n"); return FALSE; } 70 if (isfinite(dz)) { gprint (GP_ERR, "-Nz and -dz are incompatible\n"); return FALSE; } 71 remove_argument (N, &argc, argv); 72 Nz = atoi(argv[N]); 73 remove_argument (N, &argc, argv); 74 } 75 76 int binning = 1; 77 if ((N = get_argument (argc, argv, "-binning"))) { 78 if (!useGraph) { gprint (GP_ERR, "-binning requires -graph\n"); return FALSE; } 79 remove_argument (N, &argc, argv); 80 binning = atoi(argv[N]); 81 remove_argument (N, &argc, argv); 17 82 } 18 83 … … 24 89 } 25 90 26 double dx = NAN; 27 if ((N = get_argument (argc, argv, "-dx"))) { 28 remove_argument (N, &argc, argv); 29 dx = atof(argv[N]); 30 remove_argument (N, &argc, argv); 31 } 32 double dy = NAN; 33 if ((N = get_argument (argc, argv, "-dy"))) { 34 remove_argument (N, &argc, argv); 35 dy = atof(argv[N]); 36 remove_argument (N, &argc, argv); 37 } 38 double dz = NAN; 39 if ((N = get_argument (argc, argv, "-dz"))) { 40 remove_argument (N, &argc, argv); 41 dz = atof(argv[N]); 42 remove_argument (N, &argc, argv); 43 } 44 45 int valid = (!reuse && (argc == 11)) || (reuse && (argc == 5)); 91 int valid = (reuse && (argc == 5)) || (useGraph && (argc == 7)) || (argc == 11); 46 92 if (!valid) { 47 93 gprint (GP_ERR, "USAGE: tdhistogram buffer x y z (Xmin) (Xmax) (Ymin) (Ymax) (Zmin) (Zmax) [-dx dx] [-dy dy] [-dz dz] [-range range]\n"); 94 gprint (GP_ERR, "USAGE: tdhistogram buffer x y z (Zmin) (Zmax) -graph [-binning N] [-dz dz] [-range range]\n"); 48 95 gprint (GP_ERR, " OR: tdhistogram buffer x y z -reuse\n"); 49 96 gprint (GP_ERR, " -dx, -dy, -dy specify the bin size in these directions\n"); 50 97 gprint (GP_ERR, " -range : generate an output vector corresponding to the elements in the z-direction\n"); 98 gprint (GP_ERR, " -graph : use X,Y range from active graph\n"); 99 gprint (GP_ERR, " -binning N : use binning to define bin sizes relative to graph\n"); 51 100 gprint (GP_ERR, " output buffer is 3D\n"); 52 101 return (FALSE); … … 63 112 double Xmin, Xmax, Ymin, Ymax, Zmin, Zmax; 64 113 65 if (!reuse) { 66 Xmin = atof(argv[5]); 67 Xmax = atof(argv[6]); 68 if (!isfinite(dx)) { 69 Nx = 100; 70 dx = (Xmax - Xmin) / (Nx - 1); 71 } else { 72 Nx = (Xmax - Xmin) / dx + 1; 73 } 74 if (dx < 0) { 75 gprint (GP_ERR, "invalid value for delta: %f\n", dx); 76 return (FALSE); 77 } 78 Ymin = atof(argv[7]); 79 Ymax = atof(argv[8]); 80 if (!isfinite(dy)) { 81 Ny = 100; 82 dy = (Ymax - Ymin) / (Ny - 1); 83 } else { 84 Ny = (Ymax - Ymin) / dy + 1; 85 } 86 if (dy < 0) { 87 gprint (GP_ERR, "invalid value for delta: %f\n", dy); 88 return (FALSE); 89 } 90 Zmin = atof(argv[9]); 91 Zmax = atof(argv[10]); 92 if (!isfinite(dz)) { 93 Nz = 100; 94 dz = (Zmax - Zmin) / (Nz - 1); 95 } else { 96 Nz = (Zmax - Zmin) / dz + 1; 97 } 98 if (dz < 0) { 99 gprint (GP_ERR, "invalid value for delta: %f\n", dz); 100 return (FALSE); 101 } 102 103 if (Nz > 1000) { 104 gprint (GP_ERR, "warning: delta of %f will result in %d histogram bins\n", dz, Nz); 105 return (FALSE); 106 } 107 } else { 114 if (reuse) { 108 115 gfits_scan (&bf[0].header, "XMIN", "%lf", 1, &Xmin); 109 116 gfits_scan (&bf[0].header, "XMAX", "%lf", 1, &Xmax); … … 118 125 Ny = bf[0].header.Naxis[1]; 119 126 Nz = bf[0].header.Naxis[2]; 120 } 121 127 goto got_range; 128 } 129 130 if (useGraph) { 131 int Xpix, Ypix; 132 KapaGetImageRange (kapa, &Xmin, &Xmax, &Ymax, &Ymin, &Xpix, &Ypix); 133 Xmax = graphmode.xmax; 134 Xmin = graphmode.xmin; 135 Ymax = graphmode.ymax; 136 Ymin = graphmode.ymin; 137 138 // (dX, dY) are the pixel scale of the output image (output pixels / input pixels) 139 140 dx = binning * (Xmax - Xmin) / (Xpix - 1); 141 dy = binning * (Ymax - Ymin) / (Ypix - 1); 142 143 Nx = abs((Xmax - Xmin) / dx) + 1; 144 Ny = abs((Ymax - Ymin) / dy) + 1; 145 146 // XXX : note that Zmin and Zmax have a different argv location in useGraph 147 Zmin = atof(argv[5]); 148 Zmax = atof(argv[6]); 149 150 goto set_Zvalues; 151 } 152 153 // This section is only used if !reuse and !useGraph 154 Xmin = atof(argv[5]); 155 Xmax = atof(argv[6]); 156 if (!isfinite(dx)) { 157 dx = (Xmax - Xmin) / (Nx - 1); 158 } else { 159 Nx = (Xmax - Xmin) / dx + 1; 160 } 161 if (dx < 0) { 162 gprint (GP_ERR, "invalid value for delta: %f\n", dx); 163 return (FALSE); 164 } 165 Ymin = atof(argv[7]); 166 Ymax = atof(argv[8]); 167 if (!isfinite(dy)) { 168 dy = (Ymax - Ymin) / (Ny - 1); 169 } else { 170 Ny = (Ymax - Ymin) / dy + 1; 171 } 172 if (dy < 0) { 173 gprint (GP_ERR, "invalid value for delta: %f\n", dy); 174 return (FALSE); 175 } 176 // XXX : note that Zmin and Zmax have a different argv location in useGraph 177 Zmin = atof(argv[9]); 178 Zmax = atof(argv[10]); 179 180 set_Zvalues: 181 if (!isfinite(dz)) { 182 dz = (Zmax - Zmin) / (Nz - 1); 183 } else { 184 Nz = (Zmax - Zmin) / dz + 1; 185 } 186 if (dz < 0) { 187 gprint (GP_ERR, "invalid value for delta: %f\n", dz); 188 return (FALSE); 189 } 190 if (Nz > 1000) { 191 gprint (GP_ERR, "warning: delta of %f will result in %d histogram bins\n", dz, Nz); 192 return (FALSE); 193 } 194 195 got_range: 122 196 REQUIRE_VECTOR_FLT (vx, FALSE); 123 197 REQUIRE_VECTOR_FLT (vy, FALSE);
Note:
See TracChangeset
for help on using the changeset viewer.
