[21341] | 1 | import numpy as np
|
---|
[13341] | 2 |
|
---|
| 3 |
|
---|
[24313] | 4 | def expwrite(contours, filename):
|
---|
[26744] | 5 | """EXPWRITE - write an Argus file from a dictionary given in input
|
---|
[13341] | 6 |
|
---|
[26744] | 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.
|
---|
[13341] | 11 |
|
---|
[26744] | 12 | Usage:
|
---|
| 13 | expwrite(contours, filename)
|
---|
[13341] | 14 |
|
---|
[26744] | 15 | Example:
|
---|
| 16 | expwrite(coordstruct, 'domainoutline.exp')
|
---|
[13341] | 17 |
|
---|
[26744] | 18 | See also EXPDOC, EXPREAD, EXPWRITEASVERTICES
|
---|
[24313] | 19 | """
|
---|
[14310] | 20 |
|
---|
[24313] | 21 | fid = open(filename, 'w')
|
---|
| 22 | for x, y in zip(contours['x'], contours['y']):
|
---|
| 23 | if len(x) != len(y):
|
---|
[26744] | 24 | raise RuntimeError('contours x and y coordinates must be of identical size')
|
---|
| 25 |
|
---|
[24313] | 26 | if 'name' in contours:
|
---|
[26744] | 27 | fid.write('{}{}\n'.format('# Name:', contours['name']))
|
---|
[24313] | 28 | else:
|
---|
[26744] | 29 | fid.write('{}{}\n'.format('# Name:', filename))
|
---|
[13341] | 30 |
|
---|
[26744] | 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'))
|
---|
[24313] | 41 | for xi, yi in zip(x, y):
|
---|
[26744] | 42 | fid.write('%10.10f %10.10f\n' % (xi, yi))
|
---|
| 43 | fid.write('\n')
|
---|
[24313] | 44 |
|
---|
| 45 | fid.close()
|
---|