IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 5, 2006, 12:30:52 PM (20 years ago)
Author:
jhoblitt
Message:

implement p3tool -addprocessedexp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/camtool.c

    r9310 r9311  
    5353
    5454    psString query = psStringCopy(
    55             "SELECT * FROM p3PendingExp"
     55            "SELECT p3PendingExp.*"
     56            " FROM p3PendingExp"
    5657            " LEFT JOIN p3ProcessedExp"
    5758            "   USING(exp_tag)"
     
    169170    PS_ASSERT_PTR_NON_NULL(config, false);
    170171
     172    // det_id, exp_tag, recip, -bg, -bg_stdev, & -bg_mean_stdev
     173    // are required
     174    bool status = false;
     175    psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
     176    if (!status) {
     177        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
     178        return false;
     179    }
     180    if (!exp_tag) {
     181        psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
     182        return false;
     183    }
     184    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
     185    if (!status) {
     186        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
     187        return false;
     188    }
     189    if (!uri) {
     190        psError(PS_ERR_UNKNOWN, true, "-uri is required");
     191        return false;
     192    }
     193    psString recipe = psMetadataLookupStr(&status, config->args, "-recip");
     194    if (!status) {
     195        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -recip");
     196        return false;
     197    }
     198    if (!recipe) {
     199        psError(PS_ERR_UNKNOWN, true, "-recip is required");
     200        return false;
     201    }
     202    psF64 bg = psMetadataLookupF64(&status, config->args, "-bg");
     203    if (!status) {
     204        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg");
     205        return false;
     206    }
     207    if (isnan(bg)) {
     208        psError(PS_ERR_UNKNOWN, true, "-bg is required");
     209        return false;
     210    }
     211    psF64 bg_stdev = psMetadataLookupF64(&status, config->args, "-bg_stdev");
     212    if (!status) {
     213        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_stdev");
     214        return false;
     215    }
     216    if (isnan(bg_stdev)) {
     217        psError(PS_ERR_UNKNOWN, true, "-bg_stdev is required");
     218        return false;
     219    }
     220    psF64 bg_mean_stdev = psMetadataLookupF64(&status, config->args, "-bg_mean_stdev");
     221    if (!status) {
     222        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_mean_stdev");
     223        return false;
     224    }
     225    if (isnan(bg_mean_stdev)) {
     226        psError(PS_ERR_UNKNOWN, true, "-bg_mean_stdev is required");
     227        return false;
     228    }
     229    psF32 sigma_ra = psMetadataLookupF32(&status, config->args, "-sigma_ra");
     230    if (!status) {
     231        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -sigma_ra");
     232        return false;
     233    }
     234    if (isnan(sigma_ra)) {
     235        psError(PS_ERR_UNKNOWN, true, "-sigma_ra is required");
     236        return false;
     237    }
     238    psF32 sigma_dec = psMetadataLookupF32(&status, config->args, "-sigma_dec");
     239    if (!status) {
     240        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -sigma_dec");
     241        return false;
     242    }
     243    if (isnan(sigma_dec)) {
     244        psError(PS_ERR_UNKNOWN, true, "-sigma_dec is required");
     245        return false;
     246    }
     247    psS32 nastro = psMetadataLookupS32(&status, config->args, "-nastro");
     248    if (!status) {
     249        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -nastro");
     250        return false;
     251    }
     252    if (nastro < 0) {
     253        psError(PS_ERR_UNKNOWN, true, "-nastro is required");
     254        return false;
     255    }
     256    psF32 zp_mean = psMetadataLookupF32(&status, config->args, "-zp_mean");
     257    if (!status) {
     258        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -zp_mean");
     259        return false;
     260    }
     261    if (isnan(zp_mean)) {
     262        psError(PS_ERR_UNKNOWN, true, "-zp_mean is required");
     263        return false;
     264    }
     265    psF32 zp_stdev = psMetadataLookupF32(&status, config->args, "-zp_stdev");
     266    if (!status) {
     267        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -zp_stdev");
     268        return false;
     269    }
     270    if (isnan(zp_stdev)) {
     271        psError(PS_ERR_UNKNOWN, true, "-zp_stdev is required");
     272        return false;
     273    }
     274    // optional
     275    psString b1_uri = psMetadataLookupStr(&status, config->args, "-b1_uri");
     276    if (!status) {
     277        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b1_uri");
     278        return false;
     279    }
     280    psString b2_uri = psMetadataLookupStr(&status, config->args, "-b2_uri");
     281    if (!status) {
     282        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b2_uri");
     283        return false;
     284    }
     285
     286    psString query = psStringCopy(
     287        "SELECT p3PendingExp.*"
     288        " FROM p3PendingExp"
     289        " LEFT JOIN p3ProcessedExp"
     290        "   USING(exp_tag)"
     291        " WHERE"
     292        "   p3ProcessedExp.exp_tag IS NULL"
     293        "   AND p3PendingExp.exp_tag = '%s'"
     294    );
     295
     296    if (!p_psDBRunQuery(config->dbh, query, exp_tag)) {
     297        psError(PS_ERR_UNKNOWN, false, "database error");
     298        psFree(query);
     299        return false;
     300    }
     301    psFree(query);
     302
     303    psArray *output = p_psDBFetchResult(config->dbh);
     304    if (!output) {
     305        psError(PS_ERR_UNKNOWN, false, "database error");
     306        return false;
     307    }
     308    if (!psArrayLength(output)) {
     309        // XXX check psError here
     310        psError(PS_ERR_UNKNOWN, false, "no p3PendingExp rows found");
     311        return true;
     312    }
     313
     314    p3PendingExpRow *pendingRow = p3PendingExpObjectFromMetadata(output->data[0]);
     315    psFree(output);
     316    // create a new p3ProcessedImfile object
     317    p3ProcessedExpRow *row = p3ProcessedExpRowAlloc(
     318        exp_tag,
     319        uri,
     320        recipe,
     321        bg,
     322        bg_stdev,
     323        bg_mean_stdev,
     324        sigma_ra,
     325        sigma_dec,
     326        nastro,
     327        b1_uri,
     328        b2_uri,
     329        zp_mean,
     330        zp_stdev,
     331        pendingRow->p2_version,
     332        pendingRow->p3_version
     333    );
     334    psFree(pendingRow);
     335
     336    // insert the new row into the p3ProcessedImfile table
     337    if (!p3ProcessedExpInsertObject(config->dbh, row)) {
     338        psError(PS_ERR_UNKNOWN, false, "database error");
     339        psFree(row);
     340        return false;
     341    }
     342
     343    psFree(row);
     344
    171345    return true;
    172346}
Note: See TracChangeset for help on using the changeset viewer.