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 | ftref='t_profil.nc' |
---|
12 | |
---|
13 | # Output files |
---|
14 | fTSinit='TS_init_tprof_'+str(resname)+'.nc' |
---|
15 | |
---|
16 | DEPTH1=31 |
---|
17 | |
---|
18 | print ' creating TS init file '+fTSinit+'...' |
---|
19 | |
---|
20 | # Reading coordinates file |
---|
21 | nccoord=netcdf(fcoord,'r') |
---|
22 | nav_lon=nccoord.variables['glamt'] |
---|
23 | nav_lat=nccoord.variables['gphit'] |
---|
24 | LON1= nav_lon.shape[1] |
---|
25 | LAT1= nav_lon.shape[0] |
---|
26 | # Reading votemper value from t_profil.nc file: average of levitus monthly file, between x=38,106 y=52,94 |
---|
27 | nctref=netcdf(ftref,'r') |
---|
28 | ncvotemper=nctref.variables['votemper'] |
---|
29 | |
---|
30 | end=int(len(ncvotemper)) |
---|
31 | |
---|
32 | # Creating TS init netcdf file |
---|
33 | nc=netcdf(fTSinit,'w') |
---|
34 | nc.createDimension('z',DEPTH1) |
---|
35 | nc.createDimension('y',LAT1) |
---|
36 | nc.createDimension('x',LON1) |
---|
37 | nc.createDimension('time_counter',None) |
---|
38 | |
---|
39 | cdflon=nc.createVariable('nav_lon','f',('y','x')) |
---|
40 | cdflat=nc.createVariable('nav_lat','f',('y','x')) |
---|
41 | cdfdepth=nc.createVariable('deptht','f',('z')) |
---|
42 | cdftimecounter=nc.createVariable('time_counter','f',('time_counter')) |
---|
43 | cdfthetao=nc.createVariable('thetao','f',('time_counter','z','y','x')) |
---|
44 | cdfso=nc.createVariable('so','f',('time_counter','z','y','x')) |
---|
45 | |
---|
46 | cdflon[:,:]=nav_lon[:,:] |
---|
47 | cdflat[:,:]=nav_lat[:,:] |
---|
48 | |
---|
49 | ## test 1 : T & S Constants |
---|
50 | cdfso[0,:,:,:]=35 |
---|
51 | #cdfthetao[0,:,:,:]=10 |
---|
52 | count=0 |
---|
53 | while count < end : |
---|
54 | cdfthetao[:,count,:,:]=ncvotemper[count] |
---|
55 | count=count+1 |
---|
56 | |
---|
57 | |
---|
58 | #sys.exit() |
---|
59 | |
---|
60 | nc.close() |
---|
61 | nccoord.close() |
---|
62 | |
---|