Changeset 15323 for trunk/ppstamp/src/ppstampArguments.c
- Timestamp:
- Oct 16, 2007, 4:00:33 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppstamp/src/ppstampArguments.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppstamp/src/ppstampArguments.c
r15280 r15323 4 4 5 5 #include "ppstamp.h" 6 7 static void usage (void) { 8 fprintf(stderr, "USAGE: ppstamp -pixcenter x y -pixrange dx dy -chip chipname [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n"); 9 10 fprintf(stderr, "USAGE: ppstamp -pixcenter x y -celrange dRA dDEC -chip chipname [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n"); 6 #include "ohana.h" 7 8 static bool get2Angles(int argnum, int *pArgc, char **argv, bool bothDegrees, double *p1, double *p2); 9 static bool get2Ints(int argnum, int *pArgc, char **argv, int *p1, int *p2); 10 11 // XXX This usage output is kind of busy 12 13 static void usage (void) 14 { 15 fprintf(stderr, "\n"); 16 17 fprintf(stderr, "USAGE: ppstamp -celcenter RA DEC -arcrange dRA dDEC [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n"); 11 18 fprintf(stderr, " ppstamp -celcenter RA DEC -celrange dRA dDEC [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n"); 12 19 fprintf(stderr, " ppstamp -celcenter RA DEC -pixrange dx dy [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n"); 13 fprintf(stderr, "\n"); 14 15 #ifdef notyet 20 fprintf(stderr, " ppstamp -pixcenter x y -pixrange dx dy -chip chipname [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n"); 21 fprintf(stderr, " ppstamp -pixcenter x y -arcrange dRA dDEC -chip chipname [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n"); 22 fprintf(stderr, " ppstamp -pixcenter x y -celrange dRA dDEC -chip chipname [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n"); 23 fprintf(stderr, "\n"); 24 25 fprintf(stderr, "celcenter & celrange may be specified in HH:MM:SS DD:MM:SS or as 2 values in decimal degrees\n"); 26 fprintf(stderr, "arcrange may be specfied as 2 values DD:MM:SS DD:MM:SS or decimal degrees\n"); 27 fprintf(stderr, "\n"); 16 28 fprintf(stderr, "Optional arguments:\n"); 17 fprintf(stderr, "\t-stats STATS.mdc: Output statistics into STATS.mdc\n"); 18 fprintf(stderr, "\n"); 19 fprintf(stderr, "Input options (single file / file list):\n"); 20 fprintf(stderr, "\n"); 21 #endif 29 fprintf(stderr, " -chip chipName selects chip (only used with -pixcenter)\n"); 30 fprintf(stderr, "\n"); 31 22 32 exit (2); 23 }24 25 void get2Doubles(int argnum, int *pArgc, char **argv, double *p1, double *p2) {26 if (*pArgc < 3) {27 usage();28 }29 psArgumentRemove(argnum, pArgc, argv);30 *p1 = atof(argv[argnum]);31 psArgumentRemove(argnum, pArgc, argv);32 *p2 = atof(argv[argnum]);33 psArgumentRemove(argnum, pArgc, argv);34 33 } 35 34 … … 48 47 psString version; 49 48 version = ppstampVersionLong(); fprintf (stdout, "%s\n", version); psFree (version); 50 // don't need these51 // version = ppStatsVersionLong(); fprintf (stdout, "%s\n", version); psFree (version);52 // version = psphotVersionLong(); fprintf (stdout, "%s\n", version); psFree (version);53 // version = psastroVersionLong(); fprintf (stdout, "%s\n", version); psFree (version);54 49 version = psModulesVersionLong(); fprintf (stdout, "%s\n", version); psFree (version); 55 50 version = psLibVersionLong(); fprintf (stdout, "%s\n", version); psFree (version); … … 58 53 59 54 // load the site-wide configuration information 60 pmConfig *config = pmConfigRead(&argc, argv, RECIPE_NAME);55 pmConfig *config = pmConfigRead(&argc, argv, NULL); 61 56 if (config == NULL) { 62 57 psErrorStackPrint(stderr, "Can't find site configuration!\n"); … … 64 59 } 65 60 66 (void) pmConfigRecipeOptions (config, RECIPE_NAME);67 68 61 options = ppstampOptionsAlloc(); 69 62 *pOptions = options; … … 72 65 gotCenter = true; 73 66 options->celestialCenter = false; 74 get2Doubles(argnum, &argc, argv, &options->centerX, &options->centerY); 75 } 67 psArgumentRemove(argnum, &argc, argv); 68 69 if (!get2Ints(argnum, &argc, argv, &options->centerX, &options->centerY)) { 70 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "invalid pixcenter specification\n"); 71 usage(); 72 } 73 } 74 76 75 if ((argnum = psArgumentGet(argc, argv, "-celcenter"))) { 77 76 if (gotCenter) { … … 79 78 usage(); 80 79 } 81 get2Doubles(argnum, &argc, argv, &options->centerRA, &options->centerDEC); 82 options->centerRA = DEG_TO_RAD(options->centerRA); 83 options->centerDEC = DEG_TO_RAD(options->centerDEC); 80 psArgumentRemove(argnum, &argc, argv); 81 82 double raDeg, decDeg; 83 if (!get2Angles(argnum, &argc, argv, false, &raDeg, &decDeg)) { 84 usage(); 85 } 86 options->centerRA = DEG_TO_RAD(raDeg); 87 options->centerDEC = DEG_TO_RAD(decDeg); 84 88 gotCenter = true; 85 89 options->celestialCenter = true; 86 90 } 91 87 92 if (!gotCenter) { 88 usage(); 89 } 93 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "must specify center of region of interest\n"); 94 usage(); 95 } 96 90 97 if ((argnum = psArgumentGet(argc, argv, "-pixrange"))) { 91 98 gotRange = true; 92 99 options->celestialRange = false; 93 get2Doubles(argnum, &argc, argv, &options->dX, &options->dY); 94 } 95 if ((argnum = psArgumentGet(argc, argv, "-celrange"))) { 96 fprintf(stderr, "Specifying range in celestial coordinates is not implemented yet\n"); 97 exit(1); 100 psArgumentRemove(argnum, &argc, argv); 101 if (!get2Ints(argnum, &argc, argv, &options->dX, &options->dY)) { 102 usage(); 103 } 104 } 105 106 if ((argnum = psArgumentGet(argc, argv, "-arcrange"))) { 98 107 if (gotRange) { 99 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "can't specify both -pixrange and -celrange\n");; 100 usage(); 101 } 108 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "specify only one of -pixrange or -arcrange or -celrange\n");; 109 usage(); 110 } 111 psArgumentRemove(argnum, &argc, argv); 102 112 gotRange = true; 103 113 options->celestialRange = true; 104 get2Doubles(argnum, &argc, argv, &options->dRA, &options->dDEC); 105 options->dRA = DEG_TO_RAD(options->dRA); 106 options->dDEC = DEG_TO_RAD(options->dDEC); 107 } 114 115 double deg1, deg2; 116 if (!get2Angles(argnum, &argc, argv, true, °1, °2)) { 117 usage(); 118 } 119 options->dRA = DEG_TO_RAD(deg1); 120 options->dDEC = DEG_TO_RAD(deg2); 121 } 122 if ((argnum = psArgumentGet(argc, argv, "-celrange"))) { 123 if (gotRange) { 124 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "specify one of -pixrange or -arcrange or -celrange\n");; 125 usage(); 126 } 127 psArgumentRemove(argnum, &argc, argv); 128 gotRange = true; 129 options->celestialRange = true; 130 131 double deg1, deg2; 132 if (!get2Angles(argnum, &argc, argv, false, °1, °2)) { 133 usage(); 134 } 135 options->dRA = DEG_TO_RAD(deg1); 136 options->dDEC = DEG_TO_RAD(deg2); 137 } 138 108 139 if (!gotRange) { 140 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "must specify range\n"); 109 141 usage(); 110 142 } … … 114 146 options->chipName = psStringCopy(argv[argnum]); 115 147 psArgumentRemove(argnum, &argc, argv); 116 }117 118 if (!options->celestialCenter && (options->chipName == NULL)) {119 fprintf(stderr, "must specify chip name when using -pixcenter\n");120 usage();121 148 } 122 149 … … 125 152 if (!status) { 126 153 // TODO: shall we print a specific message? 154 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "must specify INPUT\n"); 127 155 usage (); 128 156 } 129 157 130 if (argc != 2) usage (); 158 // finally the output file 159 if (argc != 2) { 160 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "must specify OUTPUT\n"); 161 usage (); 162 } 131 163 132 164 // Add the input and output images (which remain on the command-line) to the arguments list … … 137 169 return config; 138 170 } 171 172 static bool validNumber(char *string) 173 { 174 char *p = string; 175 if ((*p == '+') || (*p == '-')) { 176 p++; 177 } 178 return isdigit(*p); 179 } 180 181 static bool get2Ints(int argnum, int *pArgc, char **argv, int *p1, int *p2) 182 { 183 if (*pArgc < 2) { 184 usage(); 185 } 186 187 if (!validNumber(argv[argnum])) { 188 return false; 189 } 190 191 *p1 = atoi(argv[argnum]); 192 psArgumentRemove(argnum, pArgc, argv); 193 194 if (!validNumber(argv[argnum])) { 195 return false; 196 } 197 198 *p2 = atoi(argv[argnum]); 199 psArgumentRemove(argnum, pArgc, argv); 200 201 return true; 202 } 203 204 static bool get2Angles(int argnum, int *pArgc, char **argv, bool bothInDegrees, double *p1, double *p2) 205 { 206 bool rval; 207 208 if (*pArgc < 2) { 209 usage(); 210 } 211 212 if (bothInDegrees) { 213 // both values are angles of arc DD:MM:SS or decimal degrees 214 rval = ohana_dms_to_ddd(p1, argv[argnum]); 215 if (rval) { 216 rval = ohana_dms_to_ddd(p1, argv[argnum+1]); 217 } 218 } else { 219 // first value may be in HH:MM:SS 220 rval = ohana_str_to_radec(p1, p2, argv[argnum], argv[argnum+1]); 221 } 222 223 psArgumentRemove(argnum, pArgc, argv); 224 psArgumentRemove(argnum, pArgc, argv); 225 226 return rval; 227 }
Note:
See TracChangeset
for help on using the changeset viewer.
