IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 21, 2010, 2:45:13 PM (16 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100823/ippToPsps/src/ippToPsps.c

    r28529 r29515  
    2424extern int ippToPsps_batchDifference(IppToPsps *data);
    2525
     26// Gets uncalibrated instrumental flux from magnitude
     27__inline bool ippToPsps_getFlux(const float exposureTime, const float magnitude, float* flux, const float magnitudeErr, float* fluxErr) {
     28
     29    *flux = powf(10.0, -0.4*magnitude) / exposureTime;
     30    if (!isfinite(*flux) || *flux < 0.000001) return false;
     31    if (fluxErr) *fluxErr = fabsf((magnitudeErr * *flux)/1.085736);
     32//      if (fluxErr)    printf("Mag = %03.03f, Flux = %03.03f, Mag err = %03.03f, Flux Err = %03.03f\n", magnitude, *flux, magnitudeErr, *fluxErr);
     33
     34    return true;
     35}
     36
    2637// Destructor
    2738static void ippToPsps_Destructor(IppToPsps* this) {
     
    5566    // save XML document for results
    5667    if (this->resultsXmlDoc) {
    57    
     68
    5869        xmlSaveFormatFileEnc(this->resultsPath, this->resultsXmlDoc, "UTF-8", 1);
    5970
     
    151162
    152163    psMetadata *arguments = psMetadataAlloc();
    153     psMetadataAddStr(arguments, PS_LIST_TAIL, "-expid", 0, "Exposure ID", NULL);
     164    psMetadataAddStr(arguments, PS_LIST_TAIL, "-id", 0, "ID", NULL);
    154165    psMetadataAddStr(arguments, PS_LIST_TAIL, "-expname", 0, "Exposure name", NULL);
    155166    psMetadataAddStr(arguments, PS_LIST_TAIL, "-survey", 0, "Survey type", NULL);
     
    158169    psMetadataAddStr(arguments, PS_LIST_TAIL, "-results", 0, "Path to results output", NULL);
    159170    psMetadataAddStr(arguments, PS_LIST_TAIL, "-config", 0, "Path to config dir", NULL);
    160     psMetadataAddStr(arguments, PS_LIST_TAIL, "-batch", 0, "Product type: [det|stack|diff]", NULL);
     171    psMetadataAddStr(arguments, PS_LIST_TAIL, "-batch", 0, "Product type: [IN|P2|ST|TODO]", NULL);
    161172
    162173    bool ret = true;
     
    168179    else {
    169180
    170         char *tmp = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-expid"));
    171         if (tmp) this->expId = atoi(tmp);
     181        char *tmp = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-id"));
     182        if (tmp) this->id = atoi(tmp);
    172183        //free(tmp); tmp = NULL;
    173184        this->expName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-expname"));
     
    181192        if (!tmp) this->batchType = BATCH_UNDEFINED;
    182193        else if (strcmp(tmp, "test") == 0) this->batchType = BATCH_TEST;
    183         else if (strcmp(tmp, "init") == 0) this->batchType = BATCH_INIT;
    184         else if (strcmp(tmp, "det") == 0) this->batchType = BATCH_DETECTION;
    185         else if (strcmp(tmp, "stack") == 0) this->batchType = BATCH_STACK;
    186         else if (strcmp(tmp, "diff") == 0) this->batchType = BATCH_DIFFERENCE;
     194        else if (strcmp(tmp, "IN") == 0) this->batchType = BATCH_INIT;
     195        else if (strcmp(tmp, "P2") == 0) this->batchType = BATCH_DETECTION;
     196        else if (strcmp(tmp, "ST") == 0) this->batchType = BATCH_STACK;
     197        else if (strcmp(tmp, "TODO") == 0) this->batchType = BATCH_DIFFERENCE;
    187198        else this->batchType = BATCH_UNDEFINED;
    188199
     
    192203                (this->batchType != BATCH_INIT && !this->fitsInPath) ||
    193204                (this->batchType != BATCH_INIT && !this->resultsPath) ||
    194                 (this->batchType != BATCH_INIT && this->expId == -1) ||
     205                (this->batchType != BATCH_INIT && this->id == -1) ||
    195206                !this->fitsOutPath ||
    196207                !this->configsDir ||
     
    211222static int ippToPsps_run(IppToPsps *this) {
    212223
     224    // any files?
     225    if (this->batchType == BATCH_DETECTION ||
     226            this->batchType == BATCH_STACK ||
     227            this->batchType == BATCH_DIFFERENCE ) {
     228
     229        if (this->numOfInputFiles < 1) {
     230
     231            this->exitCode = PS_EXIT_DATA_ERROR;
     232            psError(PS_ERR_UNKNOWN, false, "No input files for this batch");
     233        }
     234
     235    }
     236
    213237    if(this->exitCode == PS_EXIT_SUCCESS) {
    214238
     
    250274    psMemSetDeallocator(this, (psFreeFunc)ippToPsps_Destructor);
    251275
    252     this->expId = -1;
     276    // deal with DVO database
     277    bool haveDvo = false;
     278    for (int i=0;i<*argc; i++) {
     279
     280        if (strcmp(argv[i], "CATDIR") == 0) {haveDvo = true; break;}
     281    }
     282    if (haveDvo) this->dvoConfig = dvoConfigRead(argc, argv);
     283    else this->dvoConfig = NULL;
     284
     285    // remaining args
     286    this->id = -1;
    253287    this->expName = NULL;
    254288    this->surveyType = NULL;
     289    this->surveyID = -1;
    255290    this->fitsInPath = NULL;
    256291    this->resultsPath = NULL;
     
    261296    this->fitsOut = NULL;
    262297    this->configsDir = NULL;
    263     this->dvoConfig = NULL;
    264298    this->config = NULL;
    265     this->dvoConfig = dvoConfigRead(argc, argv);
    266299    this->pmconfig = pmConfigRead(argc, argv, NULL);
    267300    this->exitCode = PS_EXIT_SUCCESS;
    268301    this->run = ippToPsps_run;
     302
     303    // sort out current time
     304    time_t now = time(NULL);;
     305    struct tm *ts = gmtime(&now); // TODO should be UTC
     306    strftime(this->todaysDate, sizeof(this->todaysDate), "%Y-%m-%d", ts);
    269307
    270308    if (!this->pmconfig) {
     
    299337        psStringAppend(&this->configsDir, "/stack");
    300338
    301 
     339    // create filename
    302340    char outputName[100];
    303     sprintf(outputName, "%08d.FITS", this->expId);
     341    sprintf(outputName, "%08d.FITS", this->id);
    304342    psStringAppend(&this->fitsOutPath, "/%s", outputName);
    305343
     
    321359    }
    322360
     361    // get survey ID using config object
     362    if (this->batchType != BATCH_INIT &&
     363            !ippToPspsConfig_getSurveyId(this->config, this->surveyType, &this->surveyID)) {
     364       
     365        this->exitCode = PS_EXIT_CONFIG_ERROR;
     366        return this;
     367    }
     368
    323369    // create XML document for results
    324370    if (this->resultsPath) {
Note: See TracChangeset for help on using the changeset viewer.