1 | from WriteData import WriteData
|
---|
2 |
|
---|
3 |
|
---|
4 | def marshall(md):
|
---|
5 | """
|
---|
6 | MARSHALL - outputs a compatible binary file from @model md, for certain solution type.
|
---|
7 |
|
---|
8 | The routine creates a compatible binary file from @model md
|
---|
9 | This binary file will be used for parallel runs in JPL - package
|
---|
10 |
|
---|
11 | Usage:
|
---|
12 | marshall(md)
|
---|
13 | """
|
---|
14 | if md.verbose.solution:
|
---|
15 | print(("marshalling file '%s.bin'." % md.miscellaneous.name))
|
---|
16 |
|
---|
17 | #open file for binary writing
|
---|
18 | try:
|
---|
19 | fid = open(md.miscellaneous.name + '.bin', 'wb')
|
---|
20 | except IOError as e:
|
---|
21 | raise IOError("marshall error message: could not open '%s.bin' file for binary writing. Due to: ".format(md.miscellaneous.name), e)
|
---|
22 |
|
---|
23 | for field in md.properties():
|
---|
24 | #Some properties do not need to be marshalled
|
---|
25 | if field in ['results', 'radaroverlay', 'toolkits', 'cluster', 'private']:
|
---|
26 | continue
|
---|
27 |
|
---|
28 | #Check that current field is an object
|
---|
29 | if not hasattr(getattr(md, field), 'marshall'):
|
---|
30 | raise TypeError("field '{}' is not an object.".format(field))
|
---|
31 |
|
---|
32 | #Marshall current object
|
---|
33 | #print "marshalling %s ..." % field
|
---|
34 | exec("md.{}.marshall('md.{}', md, fid)".format(field, field))
|
---|
35 |
|
---|
36 | #Last, write "md.EOF" to make sure that the binary file is not corrupt
|
---|
37 | WriteData(fid, 'XXX', 'name', 'md.EOF', 'data', True, 'format', 'Boolean')
|
---|
38 |
|
---|
39 | #close file
|
---|
40 | try:
|
---|
41 | fid.close()
|
---|
42 | except IOError as e:
|
---|
43 | print("marshall error message: could not close file '{}.bin' due to:".format(md.miscellaneous.name), e)
|
---|