IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 14, 2014, 2:28:47 PM (12 years ago)
Author:
bills
Message:

Iniital implementation of the full force stages to the pipeline.
Maginitude and galactic coordinate limits on extended source fits

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/psModules

  • trunk/psModules/src/objects/pmModelClass.c

    r34259 r36441  
    6666
    6767static pmModelClass *models = NULL;
     68static psVector *modelClassLookupTable = NULL;  // translation between model types in header and here
    6869static int Nmodels = 0;
    6970
     
    135136    models = NULL;
    136137    Nmodels = 0;
     138    psFree(modelClassLookupTable);
     139    modelClassLookupTable = NULL;
    137140    return;
    138141}
     
    193196}
    194197
     198
     199bool pmModelClassWriteHeader(psMetadata *header)
     200{
     201    psMetadataAddS32(header, PS_LIST_TAIL, "MTNUM", PS_META_REPLACE, "number of model types", Nmodels);
     202    for (int i = 0; i < Nmodels; i++) {
     203        char modelNameKey[16];
     204        char modelValKey[16];
     205        sprintf(modelNameKey, "MTNAM%02d", i);
     206        sprintf(modelValKey,  "MTVAL%02d", i);
     207        psMetadataAddStr(header, PS_LIST_TAIL, modelNameKey, PS_META_REPLACE, "", models[i].name);
     208        psMetadataAddS32(header, PS_LIST_TAIL, modelValKey, PS_META_REPLACE, "", i);
     209    }
     210
     211    return true;
     212}
     213
     214bool pmModelClassReadHeader(psMetadata *header) {
     215    psFree(modelClassLookupTable);
     216
     217    bool status;
     218    int numHeaderModels = psMetadataLookupS32(&status, header, "MTNUM");
     219    if (!status) {
     220        return false;
     221    }
     222
     223    psVector *inputTypes = psVectorAlloc(numHeaderModels, PS_TYPE_S32);
     224    psVector *localTypes = psVectorAlloc(numHeaderModels, PS_TYPE_S32);
     225    int max_val = -1;
     226    for (int i = 0; i < numHeaderModels; i++) {
     227        char modelNameKey[16];
     228        char modelValKey[16];
     229        sprintf(modelNameKey, "MTNAM%02d", i);
     230        sprintf(modelValKey,  "MTVAL%02d", i);
     231        psString thisName = psMetadataLookupStr(&status, header, modelNameKey);
     232        int thisVal = psMetadataLookupS32(&status, header, modelValKey);
     233        if (thisVal > max_val) {
     234            max_val = thisVal;
     235        }
     236        inputTypes->data.S32[i] = thisVal;
     237        localTypes->data.S32[i] = pmModelClassGetType(thisName);
     238    }
     239    if (max_val < 0) {
     240        psFree(inputTypes);
     241        psFree(localTypes);
     242        return false;
     243    }
     244
     245    modelClassLookupTable = psVectorAlloc(max_val + 1, PS_TYPE_S32);
     246    psVectorInit(modelClassLookupTable, -1);
     247
     248    for (int i = 0; i < numHeaderModels; i++) {
     249        int thisVal = inputTypes->data.S32[i];
     250        int localVal = localTypes->data.S32[i];
     251        modelClassLookupTable->data.S32[thisVal] = localVal;
     252    }
     253    psFree(inputTypes);
     254    psFree(localTypes);
     255
     256    return true;
     257}
     258
     259pmModelType pmModelClassGetLocalType(pmModelType inputType) {
     260    pmModelType localType = -1;
     261
     262    if (modelClassLookupTable) {
     263        if (inputType >= 0 && inputType < modelClassLookupTable->n) {
     264            localType = modelClassLookupTable->data.S32[inputType];
     265        }
     266    } else {
     267        // no lookup table defined
     268        // for backwards compatability if inputType refers to a defined model, return it
     269        if (inputType >= 0 && pmModelClassGetName(inputType)) {
     270            localType = inputType;
     271        }
     272    }
     273
     274    return localType;
     275}
Note: See TracChangeset for help on using the changeset viewer.