source: inundation/extras/m2ferret.py @ 2197

Last change on this file since 2197 was 1790, checked in by ole, 19 years ago

Scripts for writing ferret scripts for converting MOST bathymetries into netcdf.
Need to write a proper converter.

File size: 2.5 KB
Line 
1#input_file = 'wool_100m.txt'
2#output_file = 'wool_100m_fer.txt'
3#variable = 'wool_100m'
4#journal_file = 'wool_100m.jnl'
5#journal_file = 'Port_Kembla_10m.jnl'
6#variable = 'Port_Kembla_10m'
7#input_file = 'Port_Kembla_10m.txt'
8#output_file = 'Port_Kembla_10m_fer.txt'
9#input_file = 'Botany_Bay_10m.txt'
10#output_file = 'Botany_Bay_fer_10m.txt'
11#variable = 'Botany_Bay_10m'
12#journal_file = 'Botany_Bay_10m.jnl'
13
14#input_file = 'Botany_Bay_100m.txt'
15#output_file = 'Botany_Bay_fer_100m.txt'
16#variable = 'Botany_Bay_100m'
17#journal_file = 'Botany_Bay_100m.jnl'
18
19#input_file = 'Botany_Bay_200m.txt'
20#output_file = 'Botany_Bay_fer_200m.txt'
21#variable = 'Botany_Bay_200m'
22#journal_file = 'Botany_Bay_200m.jnl'
23
24input_file = 'wool_200m.txt'
25output_file = 'wool_200m_fer.txt'
26variable = 'wool_200m'
27journal_file = 'wool_200m.jnl'
28
29#input_file = 'aus_coast_most_smooth.txt'
30#output_file = 'aus_coast_fer_smooth.txt'
31
32in_file = open(input_file,'r')
33print 'reading header'
34nx_ny_str = in_file.readline()
35nx_str,ny_str = nx_ny_str.split()
36nx = int(nx_str)
37ny = int(ny_str)
38h1_list=[]
39for i in range(nx):
40    h1_list.append(in_file.readline())
41
42x_min = float(h1_list[0])
43x_max = float(h1_list[-1])
44x_inc = (x_max-x_min)*1.0000001/float(nx-1)
45
46h2_list=[]
47for j in range(ny):
48    h2_list.append(in_file.readline())
49
50y_min = float(h2_list[-1])
51y_max = float(h2_list[0])
52y_inc = (y_max-y_min)*1.00000001/float(ny-1)
53
54print 'reading depths'
55in_depth_list = in_file.readlines()
56in_file.close()
57
58out_depth_list = []
59
60for j in range(ny):
61    out_depth_list.append('')
62
63print 'processing depths'
64k=1
65for in_line in in_depth_list:
66    for string in in_line.split():
67        #j = k/nx
68        out_depth_list[(k-1)/nx]=out_depth_list[(k-1)/nx]+('%s    '%string)
69        if k-(k/nx)*nx ==0:
70            out_depth_list[(k-1)/nx]=out_depth_list[(k-1)/nx]+'\n'
71        if k==nx*ny:
72            break
73        k+=1
74
75in_file.close()
76
77out_depth_list.reverse()
78
79depth_list = out_depth_list
80
81print 'writing results'
82out_file = open(output_file,'w')
83
84for line in depth_list:
85    out_file.write(line)
86
87out_file.close()
88
89
90jnl_file = open(journal_file,'w')
91
92jnl_file.write('DEFINE AXIS/X=%10.10fe:%10.10fe:%10.10f/unit=degree xlong\n'%(x_min,x_max,x_inc))
93jnl_file.write('DEFINE AXIS/Y=%10.10fn:%10.10fn:%10.10f/unit=degree ylat\n'%(y_min,y_max,y_inc))
94jnl_file.write('DEFINE GRID/x=xlong/y=ylat Pacific\n')
95jnl_file.write('FILE/VARIABLES=%s/COLUMNS=%i/GRID=Pacific %s\n'%(variable,nx,output_file))
96jnl_file.write('shade/pal=land_sea/lev=(-60,60,1) -1*%s\n'%variable)
97jnl_file.close()
98
99 
Note: See TracBrowser for help on using the repository browser.