Changeset 3341 for trunk/psLib/src/astronomy/psMetadataIO.c
- Timestamp:
- Feb 28, 2005, 1:34:10 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/astronomy/psMetadataIO.c (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astronomy/psMetadataIO.c
r3264 r3341 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.2 0$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-02- 17 19:26:23$11 * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-02-28 23:34:10 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 101 101 /*****************************************************************************/ 102 102 103 static void p_saxEndElement(void *ctx, const xmlChar *tagName);104 static void p_psInitVectorXml(void *ctx, char *tagName);105 static void p_psInitMetadataItemXml(void *ctx, char *tagName);106 static void p_saxStartElement(void *ctx, const xmlChar *tagName, const xmlChar **atts);103 static void saxEndElement(void *ctx, const xmlChar *tagName); 104 static void initVectorXml(void *ctx, char *tagName); 105 static void initMetadataItemXml(void *ctx, char *tagName); 106 static void saxStartElement(void *ctx, const xmlChar *tagName, const xmlChar **atts); 107 107 108 108 /** Determines if a line is blank (whitespace only) or a commentline. It returns true if so. The input string … … 307 307 { 308 308 psMetadataType type; 309 psElemType pType;310 309 psBool success = true; 311 310 … … 315 314 316 315 type = metadataItem->type; 317 pType = metadataItem->pType;318 316 319 317 switch(type) { 320 case PS_META_PRIMITIVE: 321 switch(pType) { 322 case PS_TYPE_BOOL: 323 fprintf(fd, format, metadataItem->data.B); 324 break; 325 case PS_TYPE_S32: 326 fprintf(fd,format, metadataItem->data.S32); 327 break; 328 case PS_TYPE_F32: 329 fprintf(fd, format, metadataItem->data.F32); 330 break; 331 case PS_TYPE_F64: 332 fprintf(fd, format, metadataItem->data.F64); 333 break; 334 default: 335 psError(PS_ERR_BAD_PARAMETER_TYPE,true, PS_ERRORTEXT_psMetadata_METATYPE_INVALID, (int)pType); 336 success = false; 337 } 318 case PS_META_BOOL: 319 fprintf(fd, format, metadataItem->data.B); 320 break; 321 case PS_META_S32: 322 fprintf(fd,format, metadataItem->data.S32); 323 break; 324 case PS_META_F32: 325 fprintf(fd, format, metadataItem->data.F32); 326 break; 327 case PS_META_F64: 328 fprintf(fd, format, metadataItem->data.F64); 338 329 break; 339 330 case PS_META_STR: … … 419 410 switch (keyType) { 420 411 case 'I': 421 success = psMetadataAdd(output, PS_LIST_TAIL, keyName, PS_ TYPE_S32, PS_META_PRIMITIVE,412 success = psMetadataAdd(output, PS_LIST_TAIL, keyName, PS_META_S32, 422 413 keyComment, atoi(keyValue)); 423 414 break; 424 415 case 'F': 425 success = psMetadataAdd(output, PS_LIST_TAIL, keyName, PS_ TYPE_F64, PS_META_PRIMITIVE,416 success = psMetadataAdd(output, PS_LIST_TAIL, keyName, PS_META_F64, 426 417 keyComment, atof(keyValue)); 427 418 break; 428 419 case 'C': 429 success = psMetadataAdd(output, PS_LIST_TAIL, keyName, PS_ TYPE_PTR, PS_META_STR, keyComment,430 key Value);420 success = psMetadataAdd(output, PS_LIST_TAIL, keyName, PS_META_STR, 421 keyComment, keyValue); 431 422 break; 432 423 case 'L': 433 424 tempBool = (keyValue[0] == 'T') ? 1 : 0; 434 success = psMetadataAdd(output, PS_LIST_TAIL, keyName, PS_ TYPE_BOOL, PS_META_PRIMITIVE, keyComment,435 tempBool);425 success = psMetadataAdd(output, PS_LIST_TAIL, keyName, PS_META_BOOL, 426 keyComment, tempBool); 436 427 break; 437 428 case 'U': … … 460 451 char *strComment = NULL; 461 452 char *linePtr = NULL; 453 psElemType vecType = PS_TYPE_PTR; 462 454 psS32 status = 0; 463 455 psU32 lineCount = 0; … … 467 459 psVector *tempVec = NULL; 468 460 FILE *fp = NULL; 469 psElemType pType;470 461 psMetadataType mdType; 471 462 … … 535 526 } else if(!strncmp(strType, "*", 1)) { 536 527 mdType = PS_META_LIST; 537 pType = PS_TYPE_PTR;538 528 } else if(!strncmp(strType, "STR", 3)) { 539 529 mdType = PS_META_STR; 540 pType = PS_TYPE_PTR; 541 } else if(!strncmp(strType, "BOOL", 3)) { 542 mdType = PS_META_PRIMITIVE; 543 pType = PS_TYPE_BOOL; 530 } else if(!strncmp(strType, "BOOL", 4)) { 531 mdType = PS_META_BOOL; 544 532 } else if(!strncmp(strType, "S32", 3)) { 545 mdType = PS_META_PRIMITIVE; 546 pType = PS_TYPE_S32; 533 mdType = PS_META_S32; 547 534 } else if(!strncmp(strType, "F32", 3)) { 548 mdType = PS_META_PRIMITIVE; 549 pType = PS_TYPE_F32; 535 mdType = PS_META_F32; 550 536 } else if(!strncmp(strType, "F64", 3)) { 551 mdType = PS_META_PRIMITIVE; 552 pType = PS_TYPE_F64; 537 mdType = PS_META_F64; 553 538 } else { 554 539 (*nFail)++; … … 559 544 560 545 if(*strName == '@') { 546 vecType = PS_META_PRIMITIVE_TYPE(mdType); 561 547 mdType = PS_META_VEC; 562 548 } … … 604 590 switch (mdType) { 605 591 case PS_META_LIST: 606 psMetadataAdd(md, PS_LIST_TAIL, strName, pType,mdType, NULL, NULL);592 psMetadataAdd(md, PS_LIST_TAIL, strName, mdType, NULL, NULL); 607 593 break; 608 594 case PS_META_STR: 609 psMetadataAdd(md, PS_LIST_TAIL, strName, pType,mdType, strComment, strValue);595 psMetadataAdd(md, PS_LIST_TAIL, strName, mdType, strComment, strValue); 610 596 break; 611 597 case PS_META_VEC: 612 tempVec = parseVector(strValue, pType, &status);598 tempVec = parseVector(strValue, vecType, &status); 613 599 if(!status) { 614 psMetadataAdd(md, PS_LIST_TAIL, strName+1, pType, mdType, strComment, tempVec); 600 psMetadataAdd(md, PS_LIST_TAIL, strName+1, mdType, strComment, tempVec); 601 } else { 602 status = 0; 603 (*nFail)++; 604 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, 605 strType, lineCount, fileName); 606 continue; 607 } 608 psFree(tempVec); 609 break; 610 case PS_META_BOOL: 611 tempBool = parseBool(strValue, &status); 612 if(!status) { 613 psMetadataAdd(md, PS_LIST_TAIL, strName, mdType, strComment, tempBool); 615 614 } else { 616 615 status = 0; … … 621 620 } 622 621 break; 623 case PS_META_PRIMITIVE: 624 switch (pType) { 625 case PS_TYPE_BOOL: 626 tempBool = parseBool(strValue, &status); 627 if(!status) { 628 psMetadataAdd(md, PS_LIST_TAIL, strName, pType, mdType, strComment, tempBool); 629 } else { 630 status = 0; 631 (*nFail)++; 632 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, 633 strType, lineCount, fileName); 634 continue; 635 } 636 break; 637 case PS_TYPE_S32: 638 tempInt = (psS32)parseValue(strValue, &status); 639 if(!status) { 640 psMetadataAdd(md, PS_LIST_TAIL, strName, pType, mdType, strComment, tempInt); 641 } else { 642 status = 0; 643 (*nFail)++; 644 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, 645 strType, lineCount, fileName); 646 continue; 647 } 648 break; 649 case PS_TYPE_F32: 650 case PS_TYPE_F64: 651 tempDbl = parseValue(strValue, &status); 652 if(!status) { 653 psMetadataAdd(md, PS_LIST_TAIL, strName, pType, mdType, strComment, tempDbl); 654 } else { 655 status = 0; 656 (*nFail)++; 657 psError(PS_ERR_IO, true, 658 PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType, lineCount, 659 fileName); 660 continue; 661 } 662 break; 663 default: 622 case PS_META_S32: 623 tempInt = (psS32)parseValue(strValue, &status); 624 if(!status) { 625 psMetadataAdd(md, PS_LIST_TAIL, strName, mdType, strComment, tempInt); 626 } else { 627 status = 0; 664 628 (*nFail)++; 665 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID, mdType, lineCount, 629 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, 630 strType, lineCount, fileName); 631 continue; 632 } 633 break; 634 case PS_META_F32: 635 case PS_META_F64: 636 tempDbl = parseValue(strValue, &status); 637 if(!status) { 638 psMetadataAdd(md, PS_LIST_TAIL, strName, mdType, strComment, tempDbl); 639 } else { 640 status = 0; 641 (*nFail)++; 642 psError(PS_ERR_IO, true, 643 PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType, lineCount, 666 644 fileName); 667 645 continue; 668 } // switch646 } 669 647 break; 670 648 default: … … 682 660 } 683 661 684 static void p_saxStartElement(void *ctx, const xmlChar *tagName, const xmlChar **atts)662 static void saxStartElement(void *ctx, const xmlChar *tagName, const xmlChar **atts) 685 663 { 686 664 psU64 i = 0; … … 709 687 // Metadata containter for housing element attributes used by other SAX events 710 688 htAtts = psHashAlloc(10); 689 711 690 712 691 // Get tag name … … 745 724 746 725 // Add attributes to metadata 747 psMetadataAdd(md, PS_LIST_TAIL, "htAtts", PS_TYPE_PTR, PS_META_HASH, NULL, htAtts); 726 727 psMetadataAdd(md, PS_LIST_TAIL, "htAtts", PS_META_HASH, NULL, htAtts); 748 728 749 729 psFree(psTagName); 730 psFree(htAtts); 750 731 751 732 return; 752 733 } 753 734 754 static void p_psInitMetadataItemXml(void *ctx, char *tagName)735 static void initMetadataItemXml(void *ctx, char *tagName) 755 736 { 756 737 psBool overwrite = false; … … 760 741 psF64 tempDbl = 0.0; 761 742 psS32 tempInt = 0.0; 762 psElemType pType = PS_TYPE_PTR; 763 psMetadataType mdType = PS_META_PRIMITIVE; 743 psMetadataType mdType = PS_META_UNKNOWN; 764 744 char *fileName = NULL; 765 745 char *strName = NULL; … … 802 782 if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psString")) { 803 783 mdType = PS_META_STR; 804 pType = PS_TYPE_PTR;805 784 } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psBool")) { 806 mdType = PS_META_PRIMITIVE; 807 pType = PS_TYPE_U8; 785 mdType = PS_META_BOOL; 808 786 } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psS32")) { 809 mdType = PS_META_PRIMITIVE; 810 pType = PS_TYPE_S32; 787 mdType = PS_META_S32; 811 788 } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF32")) { 812 mdType = PS_META_PRIMITIVE; 813 pType = PS_TYPE_F32; 789 mdType = PS_META_F32; 814 790 } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF64")) { 815 mdType = PS_META_PRIMITIVE; 816 pType = PS_TYPE_F64; 791 mdType = PS_META_F64; 817 792 } else { 818 793 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_TYPE_INVALID_LINE_FILE, strType, lineNumber, … … 853 828 switch(mdType) { 854 829 case PS_META_LIST: 855 psMetadataAdd(md, PS_LIST_TAIL, strName, pType,mdType, NULL, NULL);830 psMetadataAdd(md, PS_LIST_TAIL, strName, mdType, NULL, NULL); 856 831 break; 857 832 case PS_META_STR: 858 psMetadataAdd(md, PS_LIST_TAIL, strName, pType,mdType, NULL, strValue);833 psMetadataAdd(md, PS_LIST_TAIL, strName, mdType, NULL, strValue); 859 834 break; 860 case PS_META_PRIMITIVE: 861 switch(pType) { 862 case PS_TYPE_BOOL: 863 tempBool = parseBool((char*)strValue, &status); 864 if(!status) { 865 psMetadataAdd(md, PS_LIST_TAIL, strName, pType, mdType, NULL, tempBool); 866 } else { 867 status = 0; 868 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType, 869 lineNumber, fileName); 870 } 871 break; 872 case PS_TYPE_S32: 873 tempInt = (psS32)parseValue((char*)strValue, &status); 874 if(!status) { 875 psMetadataAdd(md, PS_LIST_TAIL, strName, pType, mdType, NULL, tempInt); 876 } else { 877 status = 0; 878 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType, 879 lineNumber, fileName); 880 } 881 break; 882 case PS_TYPE_F32: 883 case PS_TYPE_F64: 884 tempDbl = parseValue((char*)strValue, &status); 885 if(!status) { 886 psMetadataAdd(md, PS_LIST_TAIL, strName, pType, mdType, NULL, tempDbl); 887 } else { 888 status = 0; 889 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType, 890 lineNumber, fileName); 891 } 892 break; 893 default: 894 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID, strType, lineNumber, fileName); 895 } // End switch 835 case PS_META_BOOL: 836 tempBool = parseBool((char*)strValue, &status); 837 if(!status) { 838 psMetadataAdd(md, PS_LIST_TAIL, strName, mdType, NULL, tempBool); 839 } else { 840 status = 0; 841 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType, 842 lineNumber, fileName); 843 } 844 break; 845 case PS_META_S32: 846 tempInt = (psS32)parseValue((char*)strValue, &status); 847 if(!status) { 848 psMetadataAdd(md, PS_LIST_TAIL, strName, mdType, NULL, tempInt); 849 } else { 850 status = 0; 851 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType, 852 lineNumber, fileName); 853 } 854 break; 855 case PS_META_F32: 856 case PS_META_F64: 857 tempDbl = parseValue((char*)strValue, &status); 858 if(!status) { 859 psMetadataAdd(md, PS_LIST_TAIL, strName, mdType, NULL, tempDbl); 860 } else { 861 status = 0; 862 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType, 863 lineNumber, fileName); 864 } 896 865 break; 897 866 default: … … 899 868 } // End switch 900 869 901 902 870 return; 903 871 } 904 872 905 873 906 static void p_psInitVectorXml(void *ctx, char *tagName)874 static void initVectorXml(void *ctx, char *tagName) 907 875 { 908 876 bool overwrite = false; … … 910 878 psU32 lineNumber = 0; 911 879 psElemType pType = PS_TYPE_PTR; 912 psMetadataType mdType = PS_META_PRIMITIVE;913 880 char *strName = NULL; 914 881 char *strType = NULL; … … 952 919 strType = psHashLookup(htAtts, "psType"); 953 920 if(strType!= NULL) { 954 if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psString")) { 955 mdType = PS_META_STR; 956 pType = PS_TYPE_PTR; 957 } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psBool")) { 958 mdType = PS_META_PRIMITIVE; 921 if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psBool")) { 959 922 pType = PS_TYPE_U8; 960 923 } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psS32")) { 961 mdType = PS_META_PRIMITIVE;962 924 pType = PS_TYPE_S32; 963 925 } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF32")) { 964 mdType = PS_META_PRIMITIVE;965 926 pType = PS_TYPE_F32; 966 927 } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF64")) { 967 mdType = PS_META_PRIMITIVE;968 928 pType = PS_TYPE_F64; 969 929 } else { … … 1006 966 vec = parseVector((char*)strValue, pType, &status); 1007 967 if(!status) { 1008 psMetadataAdd(md, PS_LIST_TAIL, strName+1, pType, mdType, NULL, vec);968 psMetadataAdd(md, PS_LIST_TAIL, strName+1, PS_META_VEC, NULL, vec); 1009 969 } else { 1010 970 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType, … … 1014 974 } 1015 975 1016 static void p_saxEndElement(void *ctx, const xmlChar *tagName)976 static void saxEndElement(void *ctx, const xmlChar *tagName) 1017 977 { 1018 978 char *psStartTagName = NULL; … … 1052 1012 // Initialize psLib structs 1053 1013 if(!strcmp(psEndTagName, "psMetadataItem")) { 1054 p_psInitMetadataItemXml(ctx, psEndTagName);1014 initMetadataItemXml(ctx, psEndTagName); 1055 1015 } else if(!strcmp(psEndTagName, "psVector")) { 1056 p_psInitVectorXml(ctx, psEndTagName);1016 initVectorXml(ctx, psEndTagName); 1057 1017 } else if(strcmp(psEndTagName, "psRoot")) { 1058 1018 psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_TAG_UNKNOWN, psEndTagName); … … 1095 1055 saxHandler.startDocument = NULL; 1096 1056 saxHandler.endDocument = NULL; 1097 saxHandler.startElement = p_saxStartElement;1098 saxHandler.endElement = p_saxEndElement;1057 saxHandler.startElement = saxStartElement; 1058 saxHandler.endElement = saxEndElement; 1099 1059 saxHandler.reference = NULL; 1100 1060 saxHandler.characters = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.
