1 | #!/opt/local/bin/python |
---|
2 | |
---|
3 | import os,sys |
---|
4 | from netCDF4 import Dataset as netcdf |
---|
5 | import numpy as np |
---|
6 | |
---|
7 | resname='r025' |
---|
8 | |
---|
9 | # input file |
---|
10 | fcoord='coordinates_'+str(resname)+'.nc' |
---|
11 | |
---|
12 | # Output files |
---|
13 | fTSinit='TScst_init_'+str(resname)+'.nc' |
---|
14 | |
---|
15 | DEPTH1=31 |
---|
16 | |
---|
17 | print ' creating TS init file '+fTSinit+'...' |
---|
18 | |
---|
19 | # Reading coordinates file |
---|
20 | nccoord=netcdf(fcoord,'r') |
---|
21 | nav_lon=nccoord.variables['glamt'] |
---|
22 | nav_lat=nccoord.variables['gphit'] |
---|
23 | LON1= nav_lon.shape[1] |
---|
24 | LAT1= nav_lon.shape[0] |
---|
25 | |
---|
26 | # Creating TS init netcdf file |
---|
27 | nc=netcdf(fTSinit,'w') |
---|
28 | nc.createDimension('z',DEPTH1) |
---|
29 | nc.createDimension('y',LAT1) |
---|
30 | nc.createDimension('x',LON1) |
---|
31 | nc.createDimension('time_counter',None) |
---|
32 | |
---|
33 | cdflon=nc.createVariable('nav_lon','f',('y','x')) |
---|
34 | cdflat=nc.createVariable('nav_lat','f',('y','x')) |
---|
35 | cdfdepth=nc.createVariable('deptht','f',('z')) |
---|
36 | cdftimecounter=nc.createVariable('time_counter','f',('time_counter')) |
---|
37 | cdfthetao=nc.createVariable('thetao','f',('time_counter','z','y','x')) |
---|
38 | cdfso=nc.createVariable('so','f',('time_counter','z','y','x')) |
---|
39 | |
---|
40 | cdflon[:,:]=nav_lon[:,:] |
---|
41 | cdflat[:,:]=nav_lat[:,:] |
---|
42 | |
---|
43 | ## test 1 : T & S Constants |
---|
44 | cdfso[0,:,:,:]=35 |
---|
45 | cdfthetao[0,:,:,:]=10 |
---|
46 | |
---|
47 | #sys.exit() |
---|
48 | |
---|
49 | nc.close() |
---|
50 | nccoord.close() |
---|
51 | |
---|