IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5000


Ignore:
Timestamp:
Sep 12, 2005, 11:36:54 AM (21 years ago)
Author:
drobbin
Message:

Added xml support for psTime data

Location:
trunk/psLib
Files:
7 edited

Legend:

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

    r4985 r5000  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-09-10 00:16:59 $
     14 *  @version $Revision: 1.82 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-09-12 21:36:54 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    247247    case PS_META_MULTI:
    248248    case PS_META_ARRAY:
     249    case PS_META_TIME:
    249250        // Copy of input data not performed due to variability of data types
    250251        metadataItem->data.V = psMemIncrRefCounter(va_arg(argPtr, psPtr));
     
    440441METADATA_ADD_TYPE(Metadata,psMetadata*,PS_META_META)
    441442METADATA_ADD_TYPE(Array,psArray*,PS_META_ARRAY)
     443METADATA_ADD_TYPE(Time,psTime*,PS_META_TIME)
    442444
    443445bool psMetadataRemove(psMetadata *md,
  • trunk/psLib/src/types/psMetadata.h

    r4920 r5000  
    1111*  @author Ross Harman, MHPCC
    1212*
    13 *  @version $Revision: 1.61 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2005-08-31 02:07:12 $
     13*  @version $Revision: 1.62 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2005-09-12 21:36:54 $
    1515*
    1616*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2626#include "psHash.h"
    2727#include "psList.h"
    28 #include "psImage.h"
     28#include "psTime.h"
    2929#include "psLookupTable.h"
    3030
     
    5353    PS_META_MULTI,                     ///< Used internally, do not create an metadata item of this type.
    5454    PS_META_META,                      ///< Metadata data (Stored as item.data.md).
    55     PS_META_ARRAY                      ///< Array data (Stored as item.data.V).
     55    PS_META_ARRAY,                     ///< Array data (Stored as item.data.V).
     56    PS_META_TIME                       ///< psTime data (Stored as item.data.V).
    5657} psMetadataType;
    5758#define PS_META_IS_PRIMITIVE(TYPE) \
     
    440441);
    441442
     443/** Add a Time to metadata collection.
     444 *
     445 *  @return psBool:  True for success, False for failure.
     446 */
     447psBool psMetadataAddTime(
     448    psMetadata* md,                    ///< Metadata collection to insert metadata item
     449    long location,                     ///< Index number, PS_LIST_HEAD, or PS_LIST_TAIL
     450    const char* name,                  ///< Name of metadata item
     451    int format,                        ///< psMetadataFlag options/flags
     452    const char* comment,               ///< Comment for metadata item
     453    psTime* value                      ///< Time for metadata item data
     454);
     455
    442456/** Add a Hash to metadata collection.
    443457 *
  • trunk/psLib/src/xml/psXML.c

    r4891 r5000  
    1010*  @author David Robbins, MHPCC
    1111*
    12 *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2005-08-27 01:33:41 $
     12*  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2005-09-12 21:36:54 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5454    char content[MAXSTR];
    5555    char vec[MAXVEC];
     56    char timeVal[MAXSTR];
    5657    int i;
    5758    psMetadataIterator *iter = psMetadataIteratorAlloc(*(psMetadata**)&md, PS_LIST_HEAD, NULL);
     
    7374        if ( type == 65547)
    7475            type = PS_DATA_METADATA;
     76        if ( type == 65549)
     77            type = PS_DATA_TIME;
    7578        switch (type) {
    7679        case PS_DATA_BOOL:
     
    123126            new_node = xmlAddSibling(cur_node, new_root);
    124127            psFree(newDoc);
     128            break;
     129        case PS_DATA_TIME:
     130            cur_node = xmlNewChild(root, NULL, (const xmlChar*)"time", (const xmlChar*)"\n");
     131            prop = xmlNewProp(cur_node, (const xmlChar*)"name", (const xmlChar*)item->name);
     132            if ( ((psTime*)(item->data.V))->type == PS_TIME_UTC )
     133                prop = xmlNewProp(cur_node, (const xmlChar*)"psType", (const xmlChar*)"PS_TIME_UTC");
     134            else if ( ((psTime*)(item->data.V))->type == PS_TIME_TAI )
     135                prop = xmlNewProp(cur_node, (const xmlChar*)"psType", (const xmlChar*)"PS_TIME_TAI");
     136            else if ( ((psTime*)(item->data.V))->type == PS_TIME_UT1 )
     137                prop = xmlNewProp(cur_node, (const xmlChar*)"psType", (const xmlChar*)"PS_TIME_UT1");
     138            else if ( ((psTime*)(item->data.V))->type == PS_TIME_TT )
     139                prop = xmlNewProp(cur_node, (const xmlChar*)"psType", (const xmlChar*)"PS_TIME_TT");
     140            else {
     141                psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     142                        PS_ERRORTEXT_psXML_INVALID_CONTENT);
     143                return NULL;
     144            }
     145            snprintf(content, MAXSTR, "%ld, ", ((psTime*)(item->data.V))->sec);
     146            strncpy(timeVal, content, MAXSTR);
     147            snprintf(content, MAXSTR, "%u, ", ((psTime*)(item->data.V))->nsec);
     148            strncat(timeVal, content, MAXSTR);
     149            if ( ((psTime*)(item->data.V))->leapsecond )
     150                strncat(timeVal, "T", MAXSTR);
     151            else
     152                strncat(timeVal, "F", MAXSTR);
     153            prop = xmlNewProp(cur_node, (const xmlChar*)"value", (const xmlChar*)timeVal);
    125154            break;
    126155        case PS_DATA_VECTOR:
     
    140169                    strncat(vec, content, MAXSTR);
    141170                }
    142 
    143171                break;
    144172            case PS_DATA_F32:
     
    266294}
    267295
     296static void storeTime(psTime *out, char *in)
     297{
     298    char *endp;
     299    long sec = 0;
     300    unsigned int nsec = 0;
     301
     302    sec = strtol(in, &endp, 10);
     303    out->sec = sec;
     304    if ( !strncmp(endp, ",", 1) )
     305        endp++;
     306    else
     307        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     308                PS_ERRORTEXT_psXML_INVALID_CONTENT);
     309    in = endp;
     310    nsec = (unsigned int)strtol(in, &endp, 10);
     311    out->nsec = nsec;
     312    if ( !strncmp(endp, ",", 1) )
     313        endp++;
     314    else
     315        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     316                PS_ERRORTEXT_psXML_INVALID_CONTENT);
     317    in = endp;
     318    if ( !strncmp(in, "false", 10) || !strncmp(in, "f", 10) ||
     319            !strncmp(in, "FALSE", 10) || !strncmp(in, " F", 10) )
     320        out->leapsecond = false;
     321    else if ( !strncmp(in, "true", 10) || !strncmp(in, "t", 10) ||
     322              !strncmp(in, "TRUE", 10) || !strncmp(in, "T", 10) )
     323        out->leapsecond = true;
     324    else {
     325        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     326                PS_ERRORTEXT_psXML_INVALID_CONTENT);
     327    }
     328}
     329
    268330//Check the xml item for errors.  Returns the data type or PS_DATA_UNKNOWN for errors.//
    269331static psDataType chkType(xmlNode *node)
     
    309371        }
    310372    }
     373    if(!strncmp((const char*)node->name, "time", MAXSTR) || !strncmp((const char*)node->name, "TIME", MAXSTR) ) {
     374        if (node->properties != NULL && node->properties->name
     375                && node->properties->next != NULL && node->properties->next->name != NULL) {
     376            return(PS_DATA_TIME);
     377        } else {
     378            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     379                    PS_ERRORTEXT_psXML_INVALID_CONTENT);
     380            return(PS_DATA_UNKNOWN);
     381        }
     382    }
    311383    return(PS_DATA_UNKNOWN);
    312384}
     
    385457                    psFree(vec);
    386458                    break;
     459                case PS_DATA_TIME:
     460                    strncpy(name, (const char*)cur_node->properties->children->content, MAXSTR);
     461                    strncpy(content,
     462                            (const char*)cur_node->properties->next->next->children->content, MAXSTR);
     463                    psTimeType timeType;
     464                    char type[MAXSTR];
     465                    strncpy(type, (const char*)cur_node->properties->next->children->content, MAXSTR);
     466                    if ( !strncmp(type, "PS_TIME_UTC", MAXSTR) )
     467                        timeType = PS_TIME_UTC;
     468                    else if ( !strncmp(type, "PS_TIME_TAI", MAXSTR) )
     469                        timeType = PS_TIME_TAI;
     470                    else if ( !strncmp(type, "PS_TIME_UT1", MAXSTR) )
     471                        timeType = PS_TIME_UT1;
     472                    else if ( !strncmp(type, "PS_TIME_TT", MAXSTR) )
     473                        timeType = PS_TIME_TT;
     474                    else {
     475                        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     476                                PS_ERRORTEXT_psXML_INVALID_CONTENT);
     477                        psFree(meta);
     478                        return NULL;
     479                    }
     480
     481                    psTime *time;
     482                    time = psTimeAlloc(timeType);
     483                    storeTime(time, content);
     484                    psMetadataAddTime(meta, PS_LIST_TAIL, name, 0, "", time);
     485                    psFree(time);
     486                    break;
    387487                case PS_DATA_METADATA:
    388488                    strncpy(name, (const char*)cur_node->properties->children->content, MAXSTR);
    389                     //                        psMetadata *temp = psMetadataAlloc();
    390489                    psMetadata *temp = NULL;
    391490                    temp = xml2metadata(cur_node->children, nodeNum);
  • trunk/psLib/src/xml/psXML.h

    r4815 r5000  
    1010 *  @author David Robbins, MHPCC
    1111 *
    12  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-08-18 21:44:40 $
     12 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2005-09-12 21:36:54 $
    1414 *
    1515 *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
     
    3131#include "psString.h"
    3232#include "psConstants.h"
     33#include "psTime.h"
    3334#include "psErrorText.h"
    3435
  • trunk/psLib/test/xml/psTime.xml

    r4785 r5000  
    1212    <item name = "psLib.time.BOOL.value3" psType = "BOOL" value = "t" />
    1313    <item name = "psLib.time.BOOL.value4" psType = "BOOL" value = "F" />
     14    <time name = "psLib.TIME.Magazine" psType = "PS_TIME_UTC" value = "1000, 25, F" />
    1415    <vector name = "psLib.time.Vector.S32" psType = "S32" value = "-4, -2, 506"/>
    1516    <vector name = "psLib.time.Vector.F32" psType = "F32" value = "-0.4944, -0.00023, 53262.0"/>
  • trunk/psLib/test/xml/tst_psXML.c

    r4822 r5000  
    1515*  @author  Dave Robbins, MHPCC
    1616*
    17 *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
    18 *  @date  $Date: 2005-08-20 01:49:03 $
     17*  @version $Revision: 1.4 $  $Name: not supported by cvs2svn $
     18*  @date  $Date: 2005-09-12 21:36:54 $
    1919*
    2020*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    121121        printf("Key Type:  F64      Key Value: %15.3f  ", metadataItem->data.F64);
    122122        break;
    123     case PS_DATA_METADATA:
     123    case PS_META_META:
    124124        printf("Key Type:  METADATA    ");
    125125        break;
     
    138138        printf("%s", (char*)metadataItem->data.V );
    139139        printf("\n");
     140    } else if ( !strncmp(metadataItem->name, "psLib.TIME.Magazine", 256) ) {
     141        printf("Key Value:   ");
     142        printf("%ld, ", ((psTime*)(metadataItem->data.V))->sec );
     143        printf("%u, ", ((psTime*)(metadataItem->data.V))->nsec );
     144        if( ((psTime*)(metadataItem->data.V))->leapsecond )
     145            printf("TRUE  ");
     146        else
     147            printf("FALSE  ");
     148        if( ((psTime*)(metadataItem->data.V))->type == PS_TIME_UTC )
     149            printf("PS_TIME_UTC ");
     150        else if( ((psTime*)(metadataItem->data.V))->type == PS_TIME_TAI )
     151            printf("PS_TIME_TAI ");
     152        else if( ((psTime*)(metadataItem->data.V))->type == PS_TIME_UT1 )
     153            printf("PS_TIME_UT1 ");
     154        else if( ((psTime*)(metadataItem->data.V))->type == PS_TIME_TT )
     155            printf("PS_TIME_TT ");
     156        printf("\n");
    140157    } else
    141158        printf("Key Comment: %s\n", metadataItem->comment);
  • trunk/psLib/test/xml/verified/tst_psXML.stdout

    r4791 r5000  
    77 Key Name:    psLib.time.BOOL.value3  Key Type:  BOOL     Key Value:               1  Key Comment:
    88 Key Name:    psLib.time.BOOL.value4  Key Type:  BOOL     Key Value:               0  Key Comment:
     9 Key Name:       psLib.TIME.Magazine  Key type:  psPtr    Key Value:   1000, 25, FALSE  PS_TIME_UTC
    910 Key Name:     psLib.time.Vector.S32  Key type:  psPtr    Key Values:   -4  -2  506 
    1011 Key Name:     psLib.time.Vector.F32  Key type:  psPtr    Key Comment:
    1112 Key Name:     psLib.time.Vector.F64  Key type:  psPtr    Key Comment:
    12  Key Name:                      cell  Key type:  psPtr    Key Comment:
     13 Key Name:                      cell  Key Type:  METADATA    Key Comment:
    1314 Key Name:     psLib.time.tables.dir  Key type:  psPtr    Key Value:   ../../data
    1415
     
    1617 Key Name:    psLib.time.BOOL.value4  Key Type:  BOOL     Key Value:               0  Key Comment:
    1718 Key Name:      psLib.time.F32.value  Key Type:  F32      Key Value:       50324.422  Key Comment:
    18  Key Name:                      cell  Key type:  psPtr    Key Comment:
     19 Key Name:                      cell  Key Type:  METADATA    Key Comment:
    1920 Key Name:     psLib.time.Vector.F64  Key type:  psPtr    Key Comment:
     21 Key Name:       psLib.TIME.Magazine  Key type:  psPtr    Key Value:   1000, 25, FALSE  PS_TIME_UTC
    2022 Key Name:      psLib.time.F64.value  Key Type:  F64      Key Value:       80112.490  Key Comment:
    2123 Key Name:     psLib.time.Vector.S32  Key type:  psPtr    Key Values:   -4  -2  506 
Note: See TracChangeset for help on using the changeset viewer.