Changeset 300


Ignore:
Timestamp:
Mar 27, 2013 7:20:17 PM (6 years ago)
Author:
prjemian
Message:

refs #23

Location:
1dwg/branches/v1.1
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 1dwg/branches/v1.1/CHANGES.txt

    r287 r300  
    2828        * clean up the examples, remove unnecessary material 
    2929        * remove the mediawiki directory, we are done with it now 
     30         
     31        2013-03-27, finishing up the bindings before moving back to trunk 
     32 
     33    * removed java/maven-eclipse directory as indicated by java/README.txt file 
     34    * TRAC #13: Need to pick a license model  <<<<<<<<<<<<< MUST DO THIS ! 
     35    * TRAC #25: PHP code updated to generate v1.1 data files 
     36    * TRAC #26: Python binding complete, reads both v1.0 and v1.1 
     37    * TRAC #28: IgorPro binding needs updating, should read both v1.0 and v1.1 
     38    * TRAC #29: FORTRAN binding needs to be updated (or withdrawn) 
     39    * TRAC #30: Won't allow arbitrary order of data columns in Idata group 
     40    * TRAC #31: began work on Java binding 
    3041 
    3142:v1.0: 
  • 1dwg/branches/v1.1/java/README.txt

    r186 r300  
    44 
    55$Id$ 
     6 
     7TODO: 
     8* need to update to v1.1 canSAS standard 
     9* need to change to http://www.cansas.org 
     10* need to relearn *and document* how to build the java files with JAXB from the XSD Schema 
     11 
    612 
    713 
  • 1dwg/branches/v1.1/python/cansas1d_example.py

    r292 r300  
    11#!/usr/bin/env python 
    22'''  
    3 Example use of Gnosis_utils to read cansas1d:1.1 file 
     3Example use of Gnosis_utils to read both cansas1d:1.1  
     4and cansas1d/1.0 files 
     5 
     6This demonstrates full access to the contents of  
     7the XML file using a single line to open the file:: 
     8 
     9    sasxml = readCanSasFile(xmlFile) 
     10 
     11.. note:: Since :meth:`readCanSasFile` raises exceptions  
     12   if the namespace or version does not match, it is best 
     13   to wrap this call in ``try ... except``` block, 
     14   as shown in :meth:`demo`. 
     15 
    416''' 
    517 
     
    1729import sys 
    1830import gnosis.xml.objectify     # easy_install -U gnosis 
     31 
     32 
     33    # support reading v1.0 and v1.1 data files 
     34    # v1.1 schema is backwards compatible, mostly 
     35CANSAS_NAMESPACES = { 
     36    '1.0': 'cansas1d/1.0', 
     37    '1.1': 'urn:cansas1d:1.1', 
     38} 
     39 
     40 
     41def readCanSasFile(xmlFile): 
     42    ''' 
     43    open a canSAS XML data file as a gnosis file object 
     44     
     45    usage:: 
     46     
     47        try: 
     48            sasxml = readCanSasFile(xmlFile) 
     49        except (Exception_canSAS_namespace, Exception_canSAS_version), answer: 
     50            print answer 
     51            return 
     52        print 'namespace:', sasxml.xmlns 
     53        print 'version:', sasxml.version 
     54        SASentry = sasxml.SASentry                  # just the first one 
     55        # ... 
     56     
     57    ''' 
     58    # read in the XML file 
     59    sasxml = gnosis.xml.objectify.XML_Objectify(xmlFile).make_instance() 
     60    # namespace check to accept file as canSAS XML 
     61    if sasxml.xmlns not in CANSAS_NAMESPACES.values(): 
     62        msg = "Not a canSAS data file (namespace found: %s)" % sasxml.xmlns 
     63        raise Exception_canSAS_namespace, msg 
     64    if sasxml.version not in CANSAS_NAMESPACES.keys(): 
     65        msg = "Not v1.1 file (found: %s)" % msg 
     66        raise Exception_canSAS_version, msg 
     67    return sasxml 
     68 
     69 
     70class Exception_canSAS_namespace(Exception): 
     71    '''canSAS XML file namespace''' 
     72    pass 
     73 
     74class Exception_canSAS_version(Exception): 
     75    '''version string of the canSAS standard''' 
     76    pass 
    1977 
    2078 
     
    102160    print 'XML:', xmlFile 
    103161    # read in the XML file 
    104     sasxml = gnosis.xml.objectify.XML_Objectify(xmlFile).make_instance() 
    105     # support reading v1.0 and v1.1 data files 
    106     # v1.1 schema is backwards compatible, mostly 
    107     if sasxml.xmlns not in ('urn:cansas1d:1.1', 'cansas1d/1.0'): 
    108         print "Not cansas1d:1.1 file (found: %s)" % sasxml.xmlns 
     162    try: 
     163        sasxml = readCanSasFile(xmlFile) 
     164    except (Exception_canSAS_namespace, Exception_canSAS_version), answer: 
     165        print answer 
    109166        return 
    110167    print 'namespace:', sasxml.xmlns 
    111     if sasxml.version not in ('1.1', '1.0'): 
    112         print "Not v1.1 file (found: %s)" % sasxml.version 
    113         return 
    114168    print 'version:', sasxml.version 
    115169    SASentry = sasxml.SASentry                  # just the first one 
Note: See TracChangeset for help on using the changeset viewer.