Changeset 6423


Ignore:
Timestamp:
2016-04-05T10:12:33+02:00 (4 years ago)
Author:
davestorkey
Message:
  1. Bug fix for icb_combrest.py. Will now cope with a set of iceberg restart files with icebergs on the zeroth processor.
  2. Add nonzero sys.exit codes for icb_combrest.py and icb_pp.py.

See ticket #1708

Location:
trunk/NEMOGCM/TOOLS
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEMOGCM/TOOLS/MISCELLANEOUS/icb_pp.py

    r4990 r6423  
    5555if procnum < 1: 
    5656   print('Need some files to collate! procnum = ',procnum) 
    57    sys.exit() 
     57   sys.exit(11) 
    5858 
    5959icu = [] 
  • trunk/NEMOGCM/TOOLS/REBUILD_NEMO/icb_combrest.py

    r6140 r6423  
     1import os 
    12from netCDF4 import Dataset 
    23from argparse import ArgumentParser 
     
    6364if procnum < 1: 
    6465   print('Need some files to collate! procnum = ',procnum) 
    65    sys.exit() 
     66   sys.exit(11) 
    6667 
    6768icu = [] 
     
    7980 except: 
    8081   print 'Error: unable to open input file: ' + pathstart+nn+'.nc' 
    81    sys.exit() 
     82   sys.exit(12) 
    8283 for d in fw.dimensions : 
    8384  if d == 'n' : 
     
    151152    print 'Error accessing output file: ' + pathout 
    152153    print 'Check it is a writable location.' 
    153     sys.exit() 
     154    sys.exit(13) 
    154155else : 
     156  # Copy 2D variables across to output file from input file. This step avoids problems if rebuild_nemo  
     157  # has created an "n" dimension in the prototype rebuilt file (ie. if there are icebergs on the zeroth  
     158  # processor).  
    155159  try: 
    156     fo = Dataset(pathout, 'r+', format='NETCDF4') 
     160    os.rename(pathout,pathout.replace('.nc','_WORK.nc')) 
     161  except OSError: 
     162    print 'Error: unable to move icebergs restart file: '+pathout 
     163    sys.exit(14) 
     164  # 
     165  try: 
     166    fi = Dataset(pathout.replace('.nc','_WORK.nc'), 'r') 
    157167  except: 
    158     print 'Error accessing output file: ' + pathout 
    159     print 'Check it exists and is writable.' 
    160     print 'Or run adding the -O option to create an output file which will' 
    161     print 'contain the iceberg state data only.' 
    162     sys.exit() 
     168    print 'Error: unable to open icebergs restart file: '+pathout.replace('.nc','_WORK.nc') 
     169    sys.exit(15) 
     170  fo = Dataset(pathout, 'w') 
     171  for dim in ['x','y','c']: 
     172    indim = fi.dimensions[dim] 
     173    fo.createDimension(dim, len(indim)) 
     174  for var in ['calving','calving_hflx','stored_ice','stored_heat']: 
     175    invar = fi.variables[var] 
     176    fo.createVariable(var, invar.datatype, invar.dimensions) 
     177    fo.variables[var][:] = invar[:] 
     178    fo.variables[var].long_name = invar.long_name 
     179    fo.variables[var].units = invar.units 
     180    os.remove(pathout.replace('.nc','_WORK.nc')) 
    163181# 
    164182add_k = 1 
     
    166184  if d == 'n' : 
    167185    print 'Error: dimension n already exists in output file' 
    168     sys.exit() 
     186    sys.exit(16) 
    169187  if d == 'k' : 
    170188    add_k = 0 
Note: See TracChangeset for help on using the changeset viewer.