source: issm/trunk/src/m/solve/marshall.py@ 17806

Last change on this file since 17806 was 17806, checked in by Mathieu Morlighem, 11 years ago

merged trunk-jpl and trunk for revision 17804

File size: 1.6 KB
Line 
1from WriteData import WriteData
2from EnumDefinitions import *
3
4def 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
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." % md.miscellaneous.name)
22
23 #First, write MaximumNumberOfEnum to make sure that the Enums are synchronized
24 WriteData(fid,'enum',MaximumNumberOfDefinitionsEnum(),'data',True,'format','Boolean')
25
26 #Go through all model fields: check that it is a class and call checkconsistency
27 fields=vars(md)
28
29# for field in fields.iterkeys():
30 for field in md.properties():
31
32 #Some properties do not need to be marshalled
33 if field in ['results','radaroverlay','toolkits','cluster','flaim','private']:
34 continue
35
36 #Check that current field is an object
37 if not hasattr(getattr(md,field),'marshall'):
38 raise TypeError("field '%s' is not an object." % field)
39
40 #Marshall current object
41 #print "marshalling %s ..." % field
42 exec("md.%s.marshall(md,fid)" % field)
43
44 #Last, write MaximumNumberOfEnum+1 to make sure that the binary file is not corrupt
45 WriteData(fid,'enum',MaximumNumberOfDefinitionsEnum()+1,'data',True,'format','Boolean');
46
47 #close file
48 try:
49 fid.close()
50 except IOError as e:
51 raise IOError("marshall error message: could not close file '%s.bin'." % md.miscellaneous.name)
52
Note: See TracBrowser for help on using the repository browser.