IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

Added xml support for psTime data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.