IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 11, 2005, 10:38:56 AM (21 years ago)
Author:
desonia
Message:

made adjustments to psMetadata and added psFitsUpdateTable.

Location:
trunk/psLib/src/collections
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psMetadata.c

    r3381 r3407  
    1212*  @author Ross Harman, MHPCC
    1313*
    14 *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2005-03-07 20:58:50 $
     14*  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2005-03-11 20:38:56 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6767/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    6868/*****************************************************************************/
     69
     70static psMetadataItem* makeMetaMulti(psHash* table, const char* key, psMetadataItem* existing)
     71{
     72
     73    if (existing != NULL && existing->type == PS_META_MULTI) {
     74        return existing;
     75    }
     76
     77    // move any existing entry into a psList
     78    psList* newList = psListAlloc(existing);
     79
     80    psMetadataItem* item = psMetadataItemAlloc(key,
     81                           PS_META_MULTI,
     82                           "",
     83                           newList);
     84
     85    if (existing != NULL) {
     86        psHashRemove(table,key); // take out the old entry
     87    }
     88
     89    psHashAdd(table, key, item); // put in the new entry
     90
     91    // free local references of newly allocated items.
     92    psFree(newList);
     93    psFree(item);
     94
     95    return item;
     96}
    6997
    7098static void metadataItemFree(psMetadataItem* metadataItem)
     
    253281    existingEntry = (psMetadataItem*)psHashLookup(mdTable, key);
    254282
    255     // how the item is added to the hash depends on flags & prior existence
    256     if(existingEntry != NULL) {
    257         if ((flags & PS_META_DUPLICATE_OK) != 0) {
     283    if (metadataItem->type == PS_META_MULTI) {
     284        // the incoming entry is PS_META_MULTI
     285
     286        // force the hash entry to be PS_META_MULTI
     287        existingEntry = makeMetaMulti(mdTable,key,existingEntry);
     288
     289        // add all the items in the incoming entry to metadata
     290        psList* list = metadataItem->data.list;
     291        if (list != NULL) {
     292            psListIterator* iter = psListIteratorAlloc(list,PS_LIST_HEAD,true);
     293            psMetadataItem* listItem;
     294            while ((listItem=(psMetadataItem*)psListGetAndIncrement(iter)) != NULL) {
     295                psMetadataAddItem(md,listItem,location,flags);
     296            }
     297            psFree(iter);
     298        }
     299
     300        return true; // all done.
     301    }
     302
     303    // how the item is added to the hash depends on prior existence, flags, etc.
     304    if(existingEntry != NULL) { // prior existence
     305        if (existingEntry->type == PS_META_MULTI || (flags & PS_META_DUPLICATE_OK) != 0) {
    258306            // duplicate entries allowed - add another entry.
    259             if (existingEntry->type != PS_META_MULTI) {
    260                 // first duplicate, transfer the hash's old entry into a
    261                 // list of entries with the type PS_META_MULTI.
    262 
    263                 // add entry to a list and dereference the local pointer
    264                 psList* newList = psListAlloc(existingEntry);
    265 
    266                 existingEntry = psMetadataItemAlloc(key,
    267                                                     PS_META_MULTI,
    268                                                     "",
    269                                                     newList);
    270                 psHashRemove(mdTable,key); // take out the old entry
    271                 psHashAdd(mdTable, key, existingEntry); // put in the new entry
    272 
    273                 // free local references of newly allocated items.
    274                 psFree(newList);
    275                 psFree(existingEntry);
    276 
    277             }
     307
     308            // make sure the existing entry is PS_META_MULTI
     309            existingEntry = makeMetaMulti(mdTable,key,existingEntry);
    278310
    279311            // add to the hash's list of duplicate entries
     
    282314                return false;
    283315            }
    284             // (added to list below)
    285 
    286316        } else if ((flags & PS_META_REPLACE) != 0) {
    287317            // replace entry instead of creating a duplicate entry.
    288318
    289319            // remove the existing entry from metadata
    290             psListRemoveData(mdList, existingEntry);
    291             psHashRemove(mdTable, key);
     320            psMetadataRemove(md,0,key);
    292321
    293322            // treat as if new (added to list below)
     
    423452            // multiple entries with same key, remove just the specified one
    424453            psListRemoveData(tableItem->data.list, entry);
    425             if (psListGet(tableItem->data.list,PS_LIST_HEAD) == NULL) {
    426                 // list is empty, so let's clear the whole entry now.
    427                 if (!psHashRemove(mdTable, key)) {
    428                     psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED, key);
    429                     return false;
    430                 }
    431             }
    432454        } else {
    433455            if (!psHashRemove(mdTable, key)) {
  • trunk/psLib/src/collections/psMetadata.h

    r3381 r3407  
    1111*  @author Ross Harman, MHPCC
    1212*
    13 *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2005-03-07 20:58:50 $
     13*  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2005-03-11 20:38:56 $
    1515*
    1616*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3737 */
    3838typedef enum {
    39     PS_META_S32,                       ///< psS32 primitive data.
    40     PS_META_F32,                       ///< psF32 primitive data.
    41     PS_META_F64,                       ///< psF64 primitive data.
    42     PS_META_BOOL,                      ///< psBool primitive data.
    43     PS_META_LIST,                      ///< List data (Stored as item.data.list).
     39    PS_META_S32 = PS_TYPE_S32,         ///< psS32 primitive data.
     40    PS_META_F32 = PS_TYPE_F32,         ///< psF32 primitive data.
     41    PS_META_F64 = PS_TYPE_F64,         ///< psF64 primitive data.
     42    PS_META_BOOL = PS_TYPE_BOOL,       ///< psBool primitive data.
     43    PS_META_LIST = 0x10000,            ///< List data (Stored as item.data.list).
    4444    PS_META_STR,                       ///< String data (Stored as item.data.V).
    4545    PS_META_VEC,                       ///< Vector data (Stored as item.data.V).
     
    5151    PS_META_ASTROM,                    ///< Astrometric coefficients (Stored as item.data.V).
    5252    PS_META_UNKNOWN,                   ///< Other data (Stored as item.data.V).
    53     PS_META_MULTI,                     ///< Used internally, do not create an metadata item of this type.
    54     PS_META_NTYPE                      ///< Number of types. Must be last.
     53    PS_META_MULTI                      ///< Used internally, do not create an metadata item of this type.
    5554} psMetadataType;
    5655
  • trunk/psLib/src/collections/psVector.c

    r3264 r3407  
    1 
    21/** @file  psVector.c
    32*
     
    109*  @author Robert DeSonia, MHPCC
    1110*
    12 *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2005-02-17 19:26:23 $
     11*  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2005-03-11 20:38:56 $
    1413*
    1514*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1817#include <string.h>                        // for memcpy
    1918#include <stdlib.h>
     19#include <stdio.h>
    2020#include <math.h>
    2121
     
    407407    return outVector;
    408408}
     409
     410char* psVectorToString(psVector* vector, int maxLength)
     411{
     412
     413    if (maxLength < 5) {
     414        return NULL;
     415    }
     416
     417    char* str = psAlloc(sizeof(char)*maxLength+1);
     418
     419    if (vector == NULL) {
     420        snprintf(str,maxLength, "NULL");
     421        return str;
     422    }
     423
     424    int size = vector->n;
     425
     426    if (size == 0) {
     427        snprintf(str,maxLength, "[]");
     428        return str;
     429    }
     430
     431    char* tempStr = psAlloc(sizeof(char)*maxLength+1);
     432    *str = '\0';
     433    bool full = false;
     434
     435    #define APPEND_ELEMENTS_CASE(TYPE, NATIVE_TYPE, FORMAT) \
     436case PS_TYPE_##TYPE: \
     437    for (lcv=0; lcv < size && ! full; lcv++) { \
     438        snprintf(tempStr, maxLength, "%s" FORMAT, prefix, (NATIVE_TYPE) (vector->data.TYPE[lcv])); \
     439        strncat(str,tempStr,maxLength); \
     440        full = (strlen(str) > maxLength-2); \
     441        prefix = ","; \
     442    } \
     443    break;
     444
     445    #define APPEND_ELEMENTS_CASE_COMPLEX(TYPE,CREAL,CIMAG) \
     446case PS_TYPE_##TYPE: \
     447    for (lcv=0; lcv < size && ! full; lcv++) { \
     448        snprintf(tempStr, maxLength, "%s%g%+gi", prefix, \
     449                 CREAL(vector->data.TYPE[lcv]), \
     450                 CIMAG(vector->data.TYPE[lcv])); \
     451        full = (strlen(str) > maxLength-2); \
     452        prefix = ","; \
     453    } \
     454    break;
     455
     456    int lcv;
     457    char* prefix = "[";
     458    switch(vector->type.type) {
     459        APPEND_ELEMENTS_CASE(S8,char,"%hd")
     460        APPEND_ELEMENTS_CASE(S16,short int,"%hd")
     461        APPEND_ELEMENTS_CASE(S32,int,"%d")
     462        APPEND_ELEMENTS_CASE(S64,long,"%ld")
     463        APPEND_ELEMENTS_CASE(U8,unsigned char,"%hu")
     464        APPEND_ELEMENTS_CASE(U16,unsigned short,"%hu")
     465        APPEND_ELEMENTS_CASE(U32,unsigned int, "%u")
     466        APPEND_ELEMENTS_CASE(U64,unsigned long,"%lu")
     467        APPEND_ELEMENTS_CASE(F32,double,"%g")
     468        APPEND_ELEMENTS_CASE(F64,double,"%g")
     469        APPEND_ELEMENTS_CASE_COMPLEX(C32,crealf,cimagf)
     470        APPEND_ELEMENTS_CASE_COMPLEX(C64,creal,cimag)
     471    default:
     472        snprintf(str,maxLength,"[...]");
     473        break;
     474    }
     475
     476    if (full) {
     477        // couldn't all fit in given string length
     478
     479        // remove elements until there is room for ",...]"
     480        while (strlen(str) > maxLength - 5) {
     481            char* lastComma = strrchr(str,',');
     482            if (lastComma == NULL) { // no comma, must be first number
     483                str[1] = '\0';
     484            } else {
     485                *lastComma = '\0';
     486            }
     487        }
     488        strncat(str,",...]",maxLength);
     489    } else {
     490        strncat(str,"]",maxLength);
     491    }
     492
     493    psFree(tempStr);
     494
     495    return str;
     496}
     497
  • trunk/psLib/src/collections/psVector.h

    r3264 r3407  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2005-02-17 19:26:23 $
     13 *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2005-03-11 20:38:56 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    144144);
    145145
     146/** Creates a string from a psVector's values in the form "[x0,x1,x2]".
     147 *
     148 *  @return psPtr          a newly allocated string
     149 */
     150char* psVectorToString(
     151    psVector* vector,                  ///< vector to create a string from
     152    int maxLength                      ///< the maximum length of the resulting string
     153);
     154
    146155/// @}
    147156
Note: See TracChangeset for help on using the changeset viewer.