#!/opt/local/bin/python import os,sys from netCDF4 import Dataset as netcdf import numpy as np resname='r025' # input file fcoord='coordinates_'+str(resname)+'.nc' ftref='t_profil.nc' # Output files fTSinit='TS_init_tprof_'+str(resname)+'.nc' DEPTH1=31 print ' creating TS init file '+fTSinit+'...' # Reading coordinates file nccoord=netcdf(fcoord,'r') nav_lon=nccoord.variables['glamt'] nav_lat=nccoord.variables['gphit'] LON1= nav_lon.shape[1] LAT1= nav_lon.shape[0] # Reading votemper value from t_profil.nc file: average of levitus monthly file, between x=38,106 y=52,94 nctref=netcdf(ftref,'r') ncvotemper=nctref.variables['votemper'] end=int(len(ncvotemper)) # Creating TS init netcdf file nc=netcdf(fTSinit,'w') nc.createDimension('z',DEPTH1) nc.createDimension('y',LAT1) nc.createDimension('x',LON1) nc.createDimension('time_counter',None) cdflon=nc.createVariable('nav_lon','f',('y','x')) cdflat=nc.createVariable('nav_lat','f',('y','x')) cdfdepth=nc.createVariable('deptht','f',('z')) cdftimecounter=nc.createVariable('time_counter','f',('time_counter')) cdfthetao=nc.createVariable('thetao','f',('time_counter','z','y','x')) cdfso=nc.createVariable('so','f',('time_counter','z','y','x')) cdflon[:,:]=nav_lon[:,:] cdflat[:,:]=nav_lat[:,:] ## test 1 : T & S Constants cdfso[0,:,:,:]=35 #cdfthetao[0,:,:,:]=10 count=0 while count < end : cdfthetao[count,:,:,:]=ncvotemper[count] count=count+1 #sys.exit() nc.close() nccoord.close()