Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CMIP6dreqbuild/trunk/src/framework/loadcf_xx.py@940
Rev | Line | |
---|
[909] | 1 | """loadcf |
---|
| 2 | ------ |
---|
| 3 | The loadcf module reads the cf standard name table into two dictionaries: |
---|
| 4 | names[<standard_name>] = (description, canonical units) |
---|
| 5 | alias[<alias>] = standard_name |
---|
| 6 | """ |
---|
| 7 | |
---|
| 8 | import xml |
---|
| 9 | import xml.dom, xml.dom.minidom |
---|
| 10 | |
---|
| 11 | class cf(object): |
---|
| 12 | def __init__(self): |
---|
| 13 | vocabs = xml.dom.minidom.parse( '../workbook/cf-standard-name-table_v37.xml' ) |
---|
| 14 | |
---|
| 15 | el = vocabs.getElementsByTagName( 'entry' ) |
---|
| 16 | self.names = {} |
---|
| 17 | self.alias = {} |
---|
| 18 | |
---|
| 19 | for e in el: |
---|
| 20 | sn = e.getAttribute('id') |
---|
| 21 | unitsE = e.getElementsByTagName( 'canonical_units' ) |
---|
| 22 | u = '' |
---|
| 23 | if len(unitsE) > 0 and type( unitsE[0] ) != type(None): |
---|
| 24 | c1 = unitsE[0].firstChild |
---|
| 25 | if type( c1 ) != type(None): |
---|
| 26 | u = c1.data |
---|
| 27 | descE = e.getElementsByTagName( 'description' ) |
---|
| 28 | d = '' |
---|
| 29 | if len(descE) > 0 and type( descE[0] ) != type(None): |
---|
| 30 | c1 = descE[0].firstChild |
---|
| 31 | if type( c1 ) != type(None): |
---|
| 32 | d = c1.data |
---|
| 33 | |
---|
| 34 | self.names[sn] = (d,u ) |
---|
| 35 | el = vocabs.getElementsByTagName( 'alias' ) |
---|
| 36 | for e in el: |
---|
| 37 | sn = e.getAttribute('id') |
---|
| 38 | x = e.getElementsByTagName( 'entry_id' ) |
---|
| 39 | self.alias[sn] = x[0].firstChild.data |
---|
Note: See
TracBrowser
for help on using the repository browser.