IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7174


Ignore:
Timestamp:
May 22, 2006, 4:10:23 PM (20 years ago)
Author:
jhoblitt
Message:

add validDetInputClassIds()
start implementation of masterframeMode()

File:
1 edited

Legend:

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

    r7159 r7174  
    1414static bool addstacMode(pxConfig *config);
    1515static bool stacMode(pxConfig *config);
     16static psArray *validDetInputClassIds(pxConfig *config, const char *det_id);
    1617static bool stacframeMode(pxConfig *config);
    1718static bool addmasterMode(pxConfig *config);
     
    479480    }
    480481
     482    psArray *valid_class_ids = validDetInputClassIds(config, det_id);
     483    if (!valid_class_ids) {
     484        psError(PS_ERR_UNKNOWN, false, "no detInputExp imfile class_ids found");
     485        return false;
     486    }
     487   
     488    // check class_ids for validity
     489    for (long i = 0; i < psArrayLength(stackedImfiles); i++) {
     490        bool valid = false;
     491        for (long j = 0; j < psArrayLength(valid_class_ids); j++) {
     492            if (strcmp(((detStackedImfileRow *)stackedImfiles->data[i])->class_id,
     493                   (char *)valid_class_ids->data[j]) == 0) {
     494                valid = true;
     495                if (!psArrayRemove(valid_class_ids, valid_class_ids->data[j])) {
     496                    psError(PS_ERR_UNKNOWN, false, "psArrayRemove() failed");
     497                    psFree(stackedImfiles);
     498                    psFree(valid_class_ids);
     499                    return false;
     500                }
     501                j--; // must update loop index
     502            }
     503        }
     504        if (!valid) {
     505            psError(PS_ERR_UNKNOWN, true,
     506        "class_id %s does not corespond to on contained in an detInputExp",
     507            ((detStackedImfileRow *)stackedImfiles->data[i])->class_id);
     508            psFree(stackedImfiles);
     509            psFree(valid_class_ids);
     510            return false;
     511        }
     512    }
     513
     514    // check for residual (unmatched) input imfile class_ids
     515    if (psArrayLength(valid_class_ids)) {
     516        psError(PS_ERR_UNKNOWN, true, "det_id frame is missing %d class_ids",
     517            psArrayLength(valid_class_ids));
     518        psFree(valid_class_ids);
     519        return false;
     520    }
     521    psFree(valid_class_ids);
     522
     523    // print detStackedImfile if all class_ids are matched
     524    psMetadata *output = psMetadataAlloc();
     525    for (long i = 0; i < psArrayLength(stackedImfiles); i++) {
     526        psMetadata *md = detStackedImfileMetadataFromObject(
     527                stackedImfiles->data[i]);
     528        psMetadataAddMetadata(
     529            output, PS_LIST_TAIL, "detStackedImfile", PS_META_DUPLICATE_OK,
     530            NULL, md
     531        );
     532    }
     533
     534    psString str = psMetadataConfigFormat(output);
     535    psFree(output);
     536    fprintf(stdout, "%s\n", str);
     537    psFree(str);
     538 
     539    return true;
     540}
     541
     542static psArray *validDetInputClassIds(pxConfig *config, const char *det_id)
     543{
     544    PS_ASSERT_PTR_NON_NULL(config, NULL);
     545    // det_id is input as a string because the fact that it is an integer
     546    // is just a database impliementation detail.
     547    PS_ASSERT_PTR_NON_NULL(det_id, NULL);
     548
    481549    psArray *inputExps = NULL;
    482550    {
     
    486554            psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
    487555            psFree(where);
    488             psFree(stackedImfiles);
    489             return false;
     556            return NULL;
    490557        }
    491558        inputExps = detInputExpSelectRowObjects(config->dbh, where, 0);
     
    505572                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
    506573                psFree(where);
    507                 return false;
     574                return NULL;
    508575            }
    509576        }
     
    536603    }
    537604    psFree(rawImfiles);
    538    
    539     // check class_ids for validity
    540     for (long i = 0; i < psArrayLength(stackedImfiles); i++) {
    541         bool valid = false;
    542         for (long j = 0; j < psArrayLength(valid_class_ids); j++) {
    543             if (strcmp(((detStackedImfileRow *)stackedImfiles->data[i])->class_id,
    544                    (char *)valid_class_ids->data[j]) == 0) {
    545                 valid = true;
    546                 if (!psArrayRemove(valid_class_ids, valid_class_ids->data[j])) {
    547                     psError(PS_ERR_UNKNOWN, false, "psArrayRemove() failed");
    548                     psFree(stackedImfiles);
    549                     psFree(valid_class_ids);
    550                     return false;
    551                 }
    552                 j--; // must update loop index
    553             }
    554         }
    555         if (!valid) {
    556             psError(PS_ERR_UNKNOWN, true,
    557         "class_id %s does not corespond to on contained in an detInputExp",
    558             ((detStackedImfileRow *)stackedImfiles->data[i])->class_id);
    559             psFree(stackedImfiles);
    560             psFree(valid_class_ids);
    561             return false;
    562         }
    563     }
    564 
    565     // check for residual (unmatched) input imfile class_ids
    566     if (psArrayLength(valid_class_ids)) {
    567         psError(PS_ERR_UNKNOWN, true, "det_id frame is missing %d class_ids",
    568             psArrayLength(valid_class_ids));
    569         psFree(valid_class_ids);
    570         return false;
    571     }
    572     psFree(valid_class_ids);
    573 
    574     // print detStackedImfile if all class_ids are matched
    575     psMetadata *output = psMetadataAlloc();
    576     for (long i = 0; i < psArrayLength(stackedImfiles); i++) {
    577         psMetadata *md = detStackedImfileMetadataFromObject(
    578                 stackedImfiles->data[i]);
    579         psMetadataAddMetadata(
    580             output, PS_LIST_TAIL, "detStackedImfile", PS_META_DUPLICATE_OK,
    581             NULL, md
    582         );
    583     }
    584 
    585     psString str = psMetadataConfigFormat(output);
    586     psFree(output);
    587     fprintf(stdout, "%s\n", str);
    588     psFree(str);
    589  
    590     return true;
     605
     606    return valid_class_ids;
    591607}
    592608
     
    685701{
    686702    PS_ASSERT_PTR_NON_NULL(config, false);
    687     return true;
    688 }
     703
     704    // find all detMasterIImfile for det_id
     705    // XXX det_id is requried as a simplification
     706    psArray *masterImfiles =
     707        detMasterImfileSelectRowObjects(config->dbh, config->where, 0);
     708    if (!masterImfiles) {
     709        psError(PS_ERR_UNKNOWN, false, "no detMasterImfile rows found");
     710        return NULL;
     711    }
     712
     713    return true;
     714}
Note: See TracChangeset for help on using the changeset viewer.