IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 16, 2007, 4:00:33 PM (19 years ago)
Author:
bills
Message:

Solved problem with chip and cell boundary calculations by using different
functions than pmChipPixels and pmCellExtents. They don't do their calculations
in image coordinates.

Implemented specifying width/height of the ROI in celestial coordinates.
Removed unneeded WCS calculation methods. (The bug I was chasing was actually
not in ppstamp. It was a bug in ds9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppstamp/src/ppstampArguments.c

    r15280 r15323  
    44
    55#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
     8static bool get2Angles(int argnum, int *pArgc, char **argv, bool bothDegrees, double *p1, double *p2);
     9static bool get2Ints(int argnum, int *pArgc, char **argv, int *p1, int *p2);
     10
     11// XXX This usage output is kind of busy
     12
     13static 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");
    1118    fprintf(stderr, "       ppstamp -celcenter RA DEC -celrange dRA dDEC [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n");
    1219    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");
    1628    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
    2232    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);
    3433}
    3534
     
    4847        psString version;
    4948        version = ppstampVersionLong();   fprintf (stdout, "%s\n", version); psFree (version);
    50 // don't need these
    51 //      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);
    5449        version = psModulesVersionLong(); fprintf (stdout, "%s\n", version); psFree (version);
    5550        version = psLibVersionLong();     fprintf (stdout, "%s\n", version); psFree (version);
     
    5853
    5954    // load the site-wide configuration information
    60     pmConfig *config = pmConfigRead(&argc, argv, RECIPE_NAME);
     55    pmConfig *config = pmConfigRead(&argc, argv, NULL);
    6156    if (config == NULL) {
    6257        psErrorStackPrint(stderr, "Can't find site configuration!\n");
     
    6459    }
    6560
    66     (void) pmConfigRecipeOptions (config, RECIPE_NAME);
    67 
    6861    options = ppstampOptionsAlloc();
    6962    *pOptions = options;
     
    7265        gotCenter = true;
    7366        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
    7675    if ((argnum = psArgumentGet(argc, argv, "-celcenter"))) {
    7776        if (gotCenter) {
     
    7978            usage();
    8079        }
    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);
    8488        gotCenter = true;
    8589        options->celestialCenter = true;
    8690    }
     91
    8792    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
    9097    if ((argnum = psArgumentGet(argc, argv, "-pixrange"))) {
    9198        gotRange = true;
    9299        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"))) {
    98107        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);
    102112        gotRange = true;
    103113        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, &deg1, &deg2)) {
     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, &deg1, &deg2)) {
     133            usage();
     134        }
     135        options->dRA = DEG_TO_RAD(deg1);
     136        options->dDEC = DEG_TO_RAD(deg2);
     137    }
     138
    108139    if (!gotRange) {
     140        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "must specify range\n");
    109141        usage();
    110142    }
     
    114146        options->chipName = psStringCopy(argv[argnum]);
    115147        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();
    121148    }
    122149
     
    125152    if (!status) {
    126153        // TODO: shall we print a specific message?
     154        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "must specify INPUT\n");
    127155        usage ();
    128156    }
    129157
    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    }
    131163
    132164    // Add the input and output images (which remain on the command-line) to the arguments list
     
    137169    return config;
    138170}
     171
     172static bool validNumber(char *string)
     173{
     174    char *p = string;
     175    if ((*p == '+') || (*p == '-')) {
     176        p++;
     177    }
     178    return isdigit(*p);
     179}
     180
     181static 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
     204static 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.