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
RevLine 
[17806]1from WriteData import WriteData
[13043]2from EnumDefinitions import *
[12667]3
[12827]4def marshall(md):
5 """
6 MARSHALL - outputs a compatible binary file from @model md, for certain solution type.
[12667]7
[12944]8 The routine creates a compatible binary file from @model md
9 This binary file will be used for parallel runs in JPL-package
[12667]10
[12944]11 Usage:
12 marshall(md)
[12827]13 """
[12667]14
15 print "marshalling file '%s.bin'." % md.miscellaneous.name
16
17 #open file for binary writing
18 try:
[12733]19 fid=open(md.miscellaneous.name+'.bin','wb')
[12667]20 except IOError as e:
[12733]21 raise IOError("marshall error message: could not open '%s.bin' file for binary writing." % md.miscellaneous.name)
[12667]22
23 #First, write MaximumNumberOfEnum to make sure that the Enums are synchronized
[16137]24 WriteData(fid,'enum',MaximumNumberOfDefinitionsEnum(),'data',True,'format','Boolean')
[12667]25
26 #Go through all model fields: check that it is a class and call checkconsistency
27 fields=vars(md)
28
[13097]29# for field in fields.iterkeys():
[13116]30 for field in md.properties():
[12667]31
32 #Some properties do not need to be marshalled
[15396]33 if field in ['results','radaroverlay','toolkits','cluster','flaim','private']:
[12667]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
[13107]41 #print "marshalling %s ..." % field
[15396]42 exec("md.%s.marshall(md,fid)" % field)
[12667]43
[16560]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
[12667]47 #close file
48 try:
[13043]49 fid.close()
[12667]50 except IOError as e:
[12733]51 raise IOError("marshall error message: could not close file '%s.bin'." % md.miscellaneous.name)
[12667]52
Note: See TracBrowser for help on using the repository browser.