source: anuga_validation/Hinwood_2008/prepare_time_boundary.py @ 5691

Last change on this file since 5691 was 5691, checked in by duncan, 16 years ago

Adding a header to the boundary files

File size: 2.1 KB
RevLine 
[5686]1"""
2Script for running a breaking wave simulation of Jon Hinwoods wave tank.
3Note: this is based on the frinction_ua_flume_2006 structure.
4
5
6Duncan Gray, GA - 2007
7
8"""
9
10
11#----------------------------------------------------------------------------
12# Import necessary modules
13#----------------------------------------------------------------------------
14
15from Scientific.IO.NetCDF import NetCDFFile
16from Numeric import zeros, Float
17 
18from anuga.utilities.numerical_tools import ensure_numeric
19from anuga.utilities.interp import interp
20
21
22def csv2tms(filename, offshore_bed_elevation):
23    """Convert benchmark 2 time series to NetCDF tms file.
24    the filename is the name of the output tms file, eg 'hi.tsm'.
25    There must be an equivalent .csv file, eg 'hi.csv'.
26   
27    """
28    print 'Creating', filename
29
30    # Read the ascii (.csv) version of this file
31    fid = open(filename[:-4] + '.csv')
32
[5691]33    #Skip first line
34    line = fid.readline()
35   
[5686]36    # Read remaining lines
37    lines = fid.readlines()
38    fid.close()
39
40    N = len(lines)
41    T = zeros(N, Float)  #Time
42    Q = zeros(N, Float)  #Stage
43    X = zeros(N, Float)  #XMomentum
44    Y = zeros(N, Float)  #YMomentum
45
46    for i, line in enumerate(lines):
47        fields = line.split(',')
48
49        T[i] = float(fields[0])
50        Q[i] = float(fields[1])
51        depth = Q[i] - offshore_bed_elevation
52        X[i] = float(fields[2]) * depth
53        Y[i] = float(fields[3]) * depth
54   
55    # Create tms NetCDF file
56    fid = NetCDFFile(filename, 'w')
57    fid.institution = 'Geoscience Australia'
58    fid.description = 'Input wave for Benchmark 2'
59    fid.starttime = 0.0
60    fid.createDimension('number_of_timesteps', len(T))
61    fid.createVariable('time', Float, ('number_of_timesteps',))
62    fid.variables['time'][:] = T
63
64    fid.createVariable('stage', Float, ('number_of_timesteps',))
65    fid.variables['stage'][:] = Q[:]
66
67    fid.createVariable('xmomentum', Float, ('number_of_timesteps',))
68    fid.variables['xmomentum'][:] =  X[:]
69
70    fid.createVariable('ymomentum', Float, ('number_of_timesteps',))
71    fid.variables['ymomentum'][:] =  Y[:]
72
73    fid.close()
Note: See TracBrowser for help on using the repository browser.