Ignore:
Timestamp:
02/09/15 17:35:01 (4 years ago)
Author:
mjuckes
Message:

various

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CMIP6dreqbuild/trunk/srcMisc/dreqSX.py

    r374 r375  
    4343## dictionary to carry short names of old variables. 
    4444eeold = {} 
    45 for ee,shv in [(ee0,sh),(eenv,shnv),(eeold,shold)]: 
     45###for ee,shv in [(ee0,sh),(eenv,shnv),(eeold,shold)]: 
     46for ee,shv in [(ee0,sh),(eenv,shnv)]: 
    4647  for k in shv.keys(): 
    4748    ee[k] = shv[k] 
    4849 
    49 for ee,fn in [(ee_xref,'vlsc5_xref_v20150713.xls'),(ee_mip,'vlsc5_mip_v20150713.xls')]: 
    50   wb = workbook( fn ) 
    51   sh = wb.book.sheet_by_name( 'Sheet1' ) 
    52   for i in range(sh.nrows): 
    53     r = map( lambda x: string.strip(str(uniCleanFunc(x.value))), sh.row(i) ) 
    54     ee[r[0]] = r 
     50rmod = 'csv' 
     51eeoldl = collections.defaultdict( list ) 
     52if rmod == 'xls': 
     53  for ee,fn in [(ee_xref,'vlsc5_xref_v20150826.xls'),(ee_mip,'vlsc5_mip_v20150826.xls'),(eeold,'vlsc5b_v20150826.xls')]: 
     54    wb = workbook( fn ) 
     55    sh = wb.book.sheet_by_name( 'Sheet1' ) 
     56    for i in range(sh.nrows): 
     57      r = map( lambda x: string.strip(str(uniCleanFunc(x.value))), sh.row(i) ) 
     58      ee[r[0]] = r 
     59else: 
     60  for ee,fn,sep,xxx in [(ee_xref,'vlsc5_xref_v20150826.csv',',',False),(ee_mip,'vlsc5_mip_v20150826.csv', '\t',False),(eeoldl,'vlsc5b_v20150826.csv', '\t',True)]: 
     61    for i in open(fn).readlines(): 
     62      r = map( lambda x: string.strip(str(uniCleanFunc(x))), string.split( string.strip(i), sep ) ) 
     63      while len(r) < 9: 
     64        r.append( '' ) 
     65      if xxx: 
     66        ee[r[0]].append( r ) 
     67      else: 
     68        ee[r[0]] = r 
     69 
     70 
     71for h in eeoldl.keys(): 
     72  if len( eeoldl[h] ) == 1: 
     73    eeold[h] = eeoldl[h][0] 
     74  else: 
     75    ll = [] 
     76    for k in range( len( eeoldl[h] ) ): 
     77      if eeoldl[h][k][8] == '': 
     78        ll.append(k) 
     79    if len(ll) == 0: 
     80      print 'ERROR.004.0001: no unforwarded record in vlsc5b for h=%s' % h 
     81      eeold[h] = eeoldl[h][0] 
     82    elif len(ll) > 1: 
     83      print 'ERROR.004.0002: multiple unforwarded records in vlsc5b for h=%s (%s)' % (h,eeoldl[h][ll[0]][1]) 
     84      eeold[h] = eeoldl[h][ll[0]] 
     85    else: 
     86      eeold[h] = eeoldl[h][ll[0]] 
    5587 
    5688k2m = [] 
     
    70102## had bug here due to extension of ee_mip to include dimensions. 
    71103## 
     104ee_byvar = collections.defaultdict(list) 
    72105for k in ee_mip.keys(): 
    73106  tid = ee_mip[k][-2] 
     
    75108  ee_miptables_vars_old[tid].append(  ee_mip[k][-3] ) 
    76109  ee_ovars_old['%s.%s' % (tid,ee_mip[k][-3]) ].append(  k ) 
     110  ee_byvar[ ee_mip[k][-3] ].append( k ) 
    77111 
    78112for s in shlist: 
Note: See TracChangeset for help on using the changeset viewer.