IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 28, 2005, 11:17:02 PM (21 years ago)
Author:
magnier
Message:

checking in the versions of the files below, incorporating the changes
I made and have already submitted to bugzilla. these files should be
replaced with the versions contributed on the main trunk by MHPCC.
I will tag this state with eam-psphot-1

src/astronomy/psMetadata.c src/astronomy/psMetadata.h
src/collections/psVector.c src/collections/psVector.h
src/dataManip/psMinimize.c src/dataManip/psMinimize.h
src/image/psImage.c src/image/psImage.h src/sysUtils/psTrace.c
src/sysUtils/psTrace.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam-psphot-branch/psLib/src/astronomy/psMetadata.c

    r3541 r3788  
    1212*  @author Ross Harman, MHPCC
    1313*
    14 *  @version $Revision: 1.57 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2005-03-29 21:31:54 $
     14*  @version $Revision: 1.57.4.1 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2005-04-29 09:17:02 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6868/*****************************************************************************/
    6969
    70 static psMetadataItem* makeMetaMulti(psHash* table, const char* key, psMetadataItem* existing)
     70# if (0)
     71    static psMetadataItem* makeMetaMulti(psHash* table, const char* key, psMetadataItem* existing)
    7172{
    7273
     
    9596    return item;
    9697}
     98# endif
    9799
    98100static void metadataItemFree(psMetadataItem* metadataItem)
     
    174176{
    175177    psMetadataItem* metadataItem = NULL;
    176 
     178    char tmp;
     179    int Nbyte;
    177180
    178181    PS_PTR_CHECK_NULL(name,NULL);
     
    185188    p_psMemSetDeallocator(metadataItem, (psFreeFcn) metadataItemFree);
    186189
    187     // Allocate and set metadata item comment
    188     metadataItem->comment = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
     190    // set metadata item comment
    189191    if (comment == NULL) {
    190192        // Per SDRS, null isn't allowed, must use "" instead
    191         strncpy(metadataItem->comment, "", MAX_STRING_LENGTH);
     193        metadataItem->comment = psStringCopy ("");
    192194    } else {
    193         strncpy(metadataItem->comment, comment, MAX_STRING_LENGTH);
     195        metadataItem->comment = psStringCopy (comment);
    194196    }
    195197
     
    201203
    202204    // Allocate and set metadata item name
    203     metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
     205    Nbyte = vsnprintf(&tmp, 0, name, argPtr) + 1;
     206    metadataItem->name = (char *)psAlloc(sizeof(char) * Nbyte);
    204207    vsprintf(metadataItem->name, name, argPtr);
    205208
     
    220223    case PS_META_STR:
    221224        // Perform copy of input strings
    222         metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH);
     225        metadataItem->data.V = psStringCopy(va_arg(argPtr, char *));
    223226        break;
    224227    case PS_META_LIST:
     
    230233    case PS_META_ASTROM:
    231234    case PS_META_UNKNOWN:
    232     case PS_META_MULTI:
    233235        // Copy of input data not performed due to variability of data types
    234236        metadataItem->data.V = psMemIncrRefCounter(va_arg(argPtr, psPtr));
     237        break;
     238    case PS_META_MULTI:
     239        // MULTI needs to create a psList entry, value must be NULL
     240        metadataItem->data.list = psListAlloc(NULL);
    235241        break;
    236242    default:
     
    239245        metadataItem = NULL;
    240246    }
    241 
    242247    return metadataItem;
    243248}
     
    262267
    263268    return metadata;
     269}
     270
     271psBool MetadataAddNewItem (psMetadata *md, psMetadataItem *metadataItem, psS32 location)
     272{
     273
     274    char * key = NULL;
     275    psHash *mdTable = NULL;
     276    psList *mdList = NULL;
     277
     278    mdTable = md->table;
     279    mdList = md->list;
     280    key = metadataItem->name;
     281
     282    // OK, this is a new item.
     283    // Add new metadata item to metadata collection's hash
     284    if(!psHashAdd(mdTable, key, metadataItem)) {
     285        psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,key);
     286        return false;
     287    }
     288
     289    // Add new metadata item to metadata collection's list
     290    if(!psListAdd(mdList, location, metadataItem)) {
     291        psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED,key);
     292        return false;
     293    }
     294    // Success
     295    return true;
    264296}
    265297
     
    282314
    283315    // See if key is already in table
    284     existingEntry = (psMetadataItem*)psHashLookup(mdTable, key);
    285 
     316    existingEntry = psMetadataLookup(md, key);
     317
     318    if (existingEntry == NULL) {
     319        MetadataAddNewItem (md, metadataItem, location);
     320        return true;
     321    }
     322
     323    // if existing entry is MULTI, add the new entry to that list
     324    // XXX does this behave correctly for adding a MULTI node to an exiting MULTI node?
     325    if (existingEntry->type == PS_META_MULTI) {
     326        PS_PTR_CHECK_NULL(existingEntry->data.list,NULL);
     327
     328        // Add new metadata item to multi entry's list (XXX is TAIL correct, or location?)
     329        if(!psListAdd(existingEntry->data.list, PS_LIST_TAIL, metadataItem)) {
     330            psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED,key);
     331            return false;
     332        }
     333
     334        // Add new metadata item to metadata collection's list
     335        if(!psListAdd(mdList, location, metadataItem)) {
     336            psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED,key);
     337            return false;
     338        }
     339        return true;
     340    }
     341
     342    // if existing entry is NOT MULTI, we have several choices:
     343    //   - new entry is MULTI: move existing entry to new MULTI list
     344    //   - DUPLICATE_OK: create a new MULTI and add both old and new to it
     345    //   - REPLACE : replace the existing entry with the new entry
     346    //   - raise an error
     347
     348    // incoming entry is PS_META_MULTI  (DUPLICATE_OK is redundant, REPLACE is non-sequitor)
    286349    if (metadataItem->type == PS_META_MULTI) {
    287         // the incoming entry is PS_META_MULTI
    288 
    289         // force the hash entry to be PS_META_MULTI
    290         existingEntry = makeMetaMulti(mdTable,key,existingEntry);
    291 
    292         // add all the items in the incoming entry to metadata
    293         psList* list = metadataItem->data.list;
    294         if (list != NULL) {
    295             psListIterator* iter = psListIteratorAlloc(list,PS_LIST_HEAD,true);
    296             psMetadataItem* listItem;
    297             while ((listItem=(psMetadataItem*)psListGetAndIncrement(iter)) != NULL) {
    298                 psMetadataAddItem(md,listItem,location,flags);
    299             }
    300             psFree(iter);
    301         }
     350
     351        // replace hash entry with points to existingEntry with new entry
     352        psHashAdd (mdTable, key, metadataItem);
     353
     354        // move the existing hash entry to a node of the new entry
     355        psListAdd (metadataItem->data.list, PS_LIST_TAIL, existingEntry);
    302356
    303357        return true; // all done.
    304358    }
    305359
    306     // how the item is added to the hash depends on prior existence, flags, etc.
    307     if(existingEntry != NULL) { // prior existence
    308         if (existingEntry->type == PS_META_MULTI || (flags & PS_META_DUPLICATE_OK) != 0) {
    309             // duplicate entries allowed - add another entry.
    310 
    311             // make sure the existing entry is PS_META_MULTI
    312             existingEntry = makeMetaMulti(mdTable,key,existingEntry);
    313 
    314             // add to the hash's list of duplicate entries
    315             if (! psListAdd(existingEntry->data.list, PS_LIST_TAIL, metadataItem) ) {
    316                 psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED,key);
    317                 return false;
    318             }
    319         } else if ((flags & PS_META_REPLACE) != 0) {
    320             // replace entry instead of creating a duplicate entry.
    321 
    322             // remove the existing entry from metadata
    323             psMetadataRemove(md,0,key);
    324 
    325             // treat as if new (added to list below)
    326             if(!psHashAdd(mdTable, key, metadataItem)) {
    327                 psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,key);
    328                 return false;
    329             }
    330         } else {
    331             // default is to error on duplicate entry.
    332             psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    333                     PS_ERRORTEXT_psMetadata_DUPLICATE_NOT_ALLOWED);
    334             return false;
    335         }
    336     } else {
    337         // OK, this is a new item.
    338 
    339         // Node doesn't exist - Add new metadata item to metadata collection's hash
    340         if(!psHashAdd(mdTable, key, metadataItem)) {
    341             psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,key);
    342             return false;
    343         }
    344     }
    345 
    346     if(!psListAdd(mdList, location, metadataItem)) {
    347         psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED,key);
    348         return false;
    349     }
    350 
    351     return true;
     360    // duplicate entries allowed - create a MULTI with name and add both to it
     361    if (flags & PS_META_DUPLICATE_OK) {
     362
     363        psMetadataItem *multi;
     364
     365        multi = psMetadataItemAlloc (key, PS_META_MULTI, "multi container", NULL);
     366
     367        // replace hash entry with points to existingEntry with new multi
     368        psHashAdd (mdTable, key, multi);
     369
     370        // move the existing hash entry to a node of the new entry
     371        psListAdd (multi->data.list, PS_LIST_TAIL, existingEntry);
     372
     373        // move the existing hash entry to a node of the new entry
     374        psListAdd (multi->data.list, PS_LIST_TAIL, metadataItem);
     375
     376        // move the existing hash entry to a node of the new entry
     377        psListAdd (mdList, PS_LIST_TAIL, metadataItem);
     378
     379        return true;
     380    }
     381
     382    if (flags & PS_META_REPLACE) {
     383        // replace entry instead of creating a duplicate entry.
     384
     385        // remove the existing entry from metadata
     386        psMetadataRemove(md,0,key);
     387
     388        // treat as if new (added to list below)
     389        MetadataAddNewItem (md, metadataItem, location);
     390        return true;
     391    }
     392
     393    // default is to error on duplicate entry.
     394    psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     395            PS_ERRORTEXT_psMetadata_DUPLICATE_NOT_ALLOWED);
     396    return false;
    352397}
    353398
Note: See TracChangeset for help on using the changeset viewer.