source: issm/trunk/src/m/exp/expwrite.py@ 26744

Last change on this file since 26744 was 26744, checked in by Mathieu Morlighem, 3 years ago

merged trunk-jpl and trunk for revision 26742

File size: 1.5 KB
Line 
1import numpy as np
2
3
4def expwrite(contours, filename):
5 """EXPWRITE - write an Argus file from a dictionary given in input
6
7 This routine writes an Argus file from a dict containing the fields:
8 x and y of the coordinates of the points.
9 The first argument is the list containing the points coordinates and the
10 second one the file to be written.
11
12 Usage:
13 expwrite(contours, filename)
14
15 Example:
16 expwrite(coordstruct, 'domainoutline.exp')
17
18 See also EXPDOC, EXPREAD, EXPWRITEASVERTICES
19 """
20
21 fid = open(filename, 'w')
22 for x, y in zip(contours['x'], contours['y']):
23 if len(x) != len(y):
24 raise RuntimeError('contours x and y coordinates must be of identical size')
25
26 if 'name' in contours:
27 fid.write('{}{}\n'.format('# Name:', contours['name']))
28 else:
29 fid.write('{}{}\n'.format('# Name:', filename))
30
31 fid.write('{}\n'.format('## Icon:0'))
32 fid.write('{}\n'.format('# Points Count Value'))
33 if 'density' in contours:
34 if isinstance(contours['density'], int):
35 fid.write('{} {}\n'.format(np.size(x), contours['density']))
36 else:
37 fid.write('{} {}\n'.format(np.size(x), 1.))
38 else:
39 fid.write('{} {}\n'.format(np.size(x), 1.))
40 fid.write('{}\n'.format('# X pos Y pos'))
41 for xi, yi in zip(x, y):
42 fid.write('%10.10f %10.10f\n' % (xi, yi))
43 fid.write('\n')
44
45 fid.close()
Note: See TracBrowser for help on using the repository browser.