Changeset 6423 for trunk/NEMOGCM/TOOLS/REBUILD_NEMO/icb_combrest.py
- Timestamp:
- 2016-04-05T10:12:33+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/NEMOGCM/TOOLS/REBUILD_NEMO/icb_combrest.py
r6140 r6423 1 import os 1 2 from netCDF4 import Dataset 2 3 from argparse import ArgumentParser … … 63 64 if procnum < 1: 64 65 print('Need some files to collate! procnum = ',procnum) 65 sys.exit( )66 sys.exit(11) 66 67 67 68 icu = [] … … 79 80 except: 80 81 print 'Error: unable to open input file: ' + pathstart+nn+'.nc' 81 sys.exit( )82 sys.exit(12) 82 83 for d in fw.dimensions : 83 84 if d == 'n' : … … 151 152 print 'Error accessing output file: ' + pathout 152 153 print 'Check it is a writable location.' 153 sys.exit( )154 sys.exit(13) 154 155 else : 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). 155 159 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') 157 167 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')) 163 181 # 164 182 add_k = 1 … … 166 184 if d == 'n' : 167 185 print 'Error: dimension n already exists in output file' 168 sys.exit( )186 sys.exit(16) 169 187 if d == 'k' : 170 188 add_k = 0
Note: See TracChangeset
for help on using the changeset viewer.