IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 28, 2010, 3:09:59 PM (16 years ago)
Author:
watersc1
Message:

JPEG work should be done. Transitioning to try to pick up stackAssociation concept in this branch as well.

Location:
branches/czw_branch/20100519
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20100519

  • branches/czw_branch/20100519/ippTools/src

    • Property svn:ignore
      •  

        old new  
        2020flatcorr
        2121guidetool
         22labeltool
        2223magicdstool
        2324magictool
         
        3738stamp-h1
        3839warptool
         40
  • branches/czw_branch/20100519/ippTools/src/pxtools.c

    r28043 r28164  
    4949
    5050psString pxMergeCodeVersions(psString version1, psString version2) {
    51   psString out = NULL;
    52 
    53   bool mod1 = false;
    54   bool mod2 = false;
    55 
    56   psS32 num1;
    57   psS32 num2;
    58   psS32 numO;
    59 
    60   if (!version1) {
    61     psStringAppend(&out,version2);
     51    psString out = NULL;
     52
     53    bool mod1 = false;
     54    bool mod2 = false;
     55
     56    psS32 num1;
     57    psS32 num2;
     58    psS32 numO;
     59
     60    if (!version1) {
     61        psStringAppend(&out, "%s", version2);
     62        return(out);
     63    }
     64    if (!version2) {
     65        psStringAppend(&out, "%s", version1);
     66        return(out);
     67    }
     68 
     69    if (strchr(version1,'M')) {
     70        psStringSubstitute(&version1,"M","");
     71        mod1 = true;
     72    }
     73    if (strchr(version2,'M')) {
     74        psStringSubstitute(&version2,"M","");
     75        mod2 = true;
     76    }
     77
     78    num1 = strtol(version1,NULL,10);
     79    num2 = strtol(version2,NULL,10);
     80
     81    if (num1 >= num2) {
     82        numO = num1;
     83    }
     84    else {
     85        numO = num2;
     86    }
     87 
     88    psStringAppend(&out,"%" PRId32,numO);
     89    if (mod1 || mod2) {
     90        psStringAppend(&out,"M");
     91    }
    6292    return(out);
    63   }
    64   if (!version2) {
    65     psStringAppend(&out,version1);
    66     return(out);
    67   }
    68  
    69   if (strchr(version1,'M')) {
    70     psStringSubstitute(&version1,"M","");
    71     mod1 = true;
    72   }
    73   if (strchr(version2,'M')) {
    74     psStringSubstitute(&version2,"M","");
    75     mod2 = true;
    76   }
    77 
    78   num1 = strtol(version1,NULL,10);
    79   num2 = strtol(version2,NULL,10);
    80 
    81   if (num1 >= num2) {
    82     numO = num1;
    83   }
    84   else {
    85     numO = num2;
    86   }
    87  
    88   psStringAppend(&out,"%" PRId32,numO);
    89   if (mod1 || mod2) {
    90     psStringAppend(&out,"M");
    91   }
    92   return(out);
    9393}
    9494
    9595bool pxCoalesceRunStatus(pxConfig *config, const psString dbQFile, psS64 stage_id, psString *software_ver,
    96                          psS32 *maskfrac_npix, psF32 *maskfrac_static, psF32 *maskfrac_dynamic,
     96                         psS64 *maskfrac_npix, psF32 *maskfrac_static, psF32 *maskfrac_dynamic,
    9797                         psF32 *maskfrac_magic, psF32 *maskfrac_advisory) {
    98   psString query = pxDataGet(dbQFile);
     98    psString query = pxDataGet(dbQFile);
    9999/*   psString text_id = NULL; */
    100100/*   psStringAppend(&text_id," %" PRId64,stage_id); */
    101101/*   psStringSubstitute(&query,text_id,"@STAGE_ID@"); */
    102102/*   psFree(text_id); */
    103   if (!p_psDBRunQueryF(config->dbh, query, stage_id)) {
    104     psError(PS_ERR_UNKNOWN, false, "database error");
     103    if (!p_psDBRunQueryF(config->dbh, query, stage_id)) {
     104        psError(PS_ERR_UNKNOWN, false, "database error");
     105        psFree(query);
     106        return(false);
     107    }
    105108    psFree(query);
    106     return(false);
    107   }
    108   psFree(query);
    109   psArray *output = p_psDBFetchResult(config->dbh);
    110   if (!output) {
    111     psError(PS_ERR_UNKNOWN, false, "database error");
    112     return(false);
    113   }
    114  
    115   for (long i = 0; i < psArrayLength(output); i++) {
    116     psMetadata *row = output->data[i];
    117 
    118     psS32 this_npix = psMetadataLookupS32(NULL, row, "maskfrac_npix");
    119     psF32 this_static = psMetadataLookupF32(NULL, row, "maskfrac_static");
    120     psF32 this_dynamic = psMetadataLookupF32(NULL, row, "maskfrac_dynamic");
    121     psF32 this_magic = psMetadataLookupF32(NULL, row, "maskfrac_magic");
    122     psF32 this_advisory = psMetadataLookupF32(NULL, row, "maskfrac_advisory");
    123     psString this_version = psMetadataLookupStr(NULL, row, "software_ver");
    124 
    125     *software_ver = pxMergeCodeVersions(*software_ver,this_version);
    126 
    127     *maskfrac_static = ((*maskfrac_static * *maskfrac_npix) + (this_npix * this_static)) / (this_npix + *maskfrac_npix);
    128     *maskfrac_dynamic = ((*maskfrac_dynamic * *maskfrac_npix) + (this_npix * this_dynamic)) / (this_npix + *maskfrac_npix);
    129     *maskfrac_magic = ((*maskfrac_magic * *maskfrac_npix) + (this_npix * this_magic)) / (this_npix + *maskfrac_npix);
    130     *maskfrac_advisory = ((*maskfrac_advisory * *maskfrac_npix) + (this_npix * this_advisory)) / (this_npix + *maskfrac_npix);
    131     *maskfrac_npix += this_npix;
    132   }
    133   psFree(output);
    134   return(true);
     109    psArray *output = p_psDBFetchResult(config->dbh);
     110    if (!output) {
     111        psError(PS_ERR_UNKNOWN, false, "database error");
     112        return(false);
     113    }
     114 
     115    for (long i = 0; i < psArrayLength(output); i++) {
     116        psMetadata *row = output->data[i];
     117
     118        psS32 this_npix = psMetadataLookupS32(NULL, row, "maskfrac_npix");
     119        psF32 this_static = psMetadataLookupF32(NULL, row, "maskfrac_static");
     120        psF32 this_dynamic = psMetadataLookupF32(NULL, row, "maskfrac_dynamic");
     121        psF32 this_magic = psMetadataLookupF32(NULL, row, "maskfrac_magic");
     122        psF32 this_advisory = psMetadataLookupF32(NULL, row, "maskfrac_advisory");
     123        psString this_version = psMetadataLookupStr(NULL, row, "software_ver");
     124
     125        *software_ver = pxMergeCodeVersions(*software_ver,this_version);
     126/*     printf("%ld : %d %f %f %f %f <-> %ld %f %f %f %f\n",i,this_npix,this_static,this_dynamic,this_magic,this_advisory, */
     127/*         *maskfrac_npix,*maskfrac_static,*maskfrac_dynamic,*maskfrac_magic,*maskfrac_advisory); */
     128        if (this_npix > 0) {
     129            *maskfrac_static = ((*maskfrac_static * *maskfrac_npix) + (this_npix * this_static)) / (this_npix + *maskfrac_npix);
     130            *maskfrac_dynamic = ((*maskfrac_dynamic * *maskfrac_npix) + (this_npix * this_dynamic)) / (this_npix + *maskfrac_npix);
     131            *maskfrac_magic = ((*maskfrac_magic * *maskfrac_npix) + (this_npix * this_magic)) / (this_npix + *maskfrac_npix);
     132            *maskfrac_advisory = ((*maskfrac_advisory * *maskfrac_npix) + (this_npix * this_advisory)) / (this_npix + *maskfrac_npix);
     133            *maskfrac_npix += this_npix;
     134        }
     135    }
     136    psFree(output);
     137    return(true);
    135138}
    136139
    137140bool pxSetRunSoftware(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id,
    138141                      psString software_ver) {
    139   char *query = "UPDATE %s SET software_ver = '%s' WHERE %s = %" PRId64;
    140   printf(query,tableName,software_ver,stage_id_name,stage_id);
    141   if (!p_psDBRunQueryF(config->dbh,query,tableName,software_ver,stage_id_name,stage_id)) {
    142     psError(PS_ERR_UNKNOWN, false,
    143             "failed to set software version for %s %" PRId64,stage_id_name,stage_id);
    144     return(false);
    145   }
    146  
    147   return(true);
    148 }
     142    char *query = "UPDATE %s SET software_ver = '%s' WHERE %s = %" PRId64;
     143/*   printf(query,tableName,software_ver,stage_id_name,stage_id); */
     144    if (!p_psDBRunQueryF(config->dbh,query,tableName,software_ver,stage_id_name,stage_id)) {
     145        psError(PS_ERR_UNKNOWN, false,
     146                "failed to set software version for %s %" PRId64,stage_id_name,stage_id);
     147        return(false);
     148    }
     149 
     150    return(true);
     151}
     152
    149153bool pxSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id,
    150                       psS32 maskfrac_npix, psF32 maskfrac_static, psF32 maskfrac_dynamic,
     154                      psS64 maskfrac_npix, psF32 maskfrac_static, psF32 maskfrac_dynamic,
    151155                      psF32 maskfrac_magic, psF32 maskfrac_advisory) {
    152   char *query = "UPDATE %s SET maskfrac_npix = %d, maskfrac_static = %f, maskfrac_dynamic = %f, maskfrac_magic = %f, maskfrac_advisory = %f WHERE %s = %" PRId64;
    153   if (!p_psDBRunQueryF(config->dbh,query,tableName,maskfrac_npix,maskfrac_static,
    154                        maskfrac_dynamic, maskfrac_magic,maskfrac_advisory,stage_id_name,stage_id)) {
     156    char *query = "UPDATE %s SET maskfrac_npix = %f, maskfrac_static = %f, maskfrac_dynamic = %f, maskfrac_magic = %f, maskfrac_advisory = %f WHERE %s = %" PRId64;
     157    if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_npix,maskfrac_static,
     158                         maskfrac_dynamic, maskfrac_magic,maskfrac_advisory,stage_id_name,stage_id)) {
     159        psError(PS_ERR_UNKNOWN, false,
     160                "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id);
     161        return(false);
     162    }
     163 
     164
     165
     166    return(true);
     167}
     168
     169bool pxCamSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id,
     170                         psS64 maskfrac_ref_npix, psF32 maskfrac_ref_static, psF32 maskfrac_ref_dynamic,
     171                         psF32 maskfrac_ref_magic, psF32 maskfrac_ref_advisory,
     172                         psS64 maskfrac_max_npix, psF32 maskfrac_max_static, psF32 maskfrac_max_dynamic,
     173                         psF32 maskfrac_max_magic, psF32 maskfrac_max_advisory) {
     174  char *query = "UPDATE %s SET maskfrac_ref_npix = %f, maskfrac_ref_static = %f, maskfrac_ref_dynamic = %f, maskfrac_ref_magic = %f, maskfrac_ref_advisory = %f, maskfrac_max_npix = %f, maskfrac_max_static = %f, maskfrac_max_dynamic = %f, maskfrac_max_magic = %f, maskfrac_max_advisory = %f WHERE %s = %" PRId64;
     175  if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_ref_npix,maskfrac_ref_static,
     176                       maskfrac_ref_dynamic, maskfrac_ref_magic,maskfrac_ref_advisory,
     177                       (float) maskfrac_max_npix,maskfrac_max_static,
     178                       maskfrac_max_dynamic, maskfrac_max_magic,maskfrac_max_advisory,
     179                       stage_id_name,stage_id)) {
    155180    psError(PS_ERR_UNKNOWN, false,
    156181            "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id);
     
    268293    char *comma = ",";
    269294
    270 #   define addColumn(_tab, _val) \
    271         do { \
    272             if (_val) { \
    273                 psStringAppend(pQuery, "%s %s.%s = '%s'", separator, _tab, #_val, _val); \
    274                 separator = comma; \
    275             } \
    276         } while (0)
     295#   define addColumn(_tab, _val)                                        \
     296    do {                                                                \
     297        if (_val) {                                                     \
     298            psStringAppend(pQuery, "%s %s.%s = '%s'", separator, _tab, #_val, _val); \
     299            separator = comma;                                          \
     300        }                                                               \
     301    } while (0)
    277302
    278303    addColumn(runTable, state);
     
    411436        if (import_version && strcmp(import_version, schema_version)) {
    412437            psError(PS_ERR_UNKNOWN, true, "input file schema_version: %s does not match data base: %s",
    413                 import_version, schema_version);
     438                    import_version, schema_version);
    414439            return false;
    415440        } else if (!import_version) {
Note: See TracChangeset for help on using the changeset viewer.