source:
issm/oecreview/Archive/19101-20495/ISSM-20096-20097.diff
Last change on this file was 20498, checked in by , 9 years ago | |
---|---|
File size: 2.1 KB |
-
../trunk-jpl/scripts/BinRead.py
5 5 import numpy 6 6 import math 7 7 import struct 8 import argparse 9 from MatlabFuncs import * 10 from EnumDefinitions import * 11 from EnumToString import EnumToString 8 12 9 def BinRead(filin,filout=''): 13 def BinRead(filin,filout=''): #{{{ 10 14 11 from MatlabFuncs import *12 from EnumDefinitions import *13 from EnumToString import EnumToString14 15 15 print "reading binary file." 16 16 f=open(filin,'rb') 17 17 … … 104 104 print "data[%d,%d] = %f" % (i,j,data[i][j]) 105 105 106 106 elif code == FormatToCode('MatArray'): 107 f id.seek(reclen-4,1)107 f.seek(reclen-4,1) 108 108 print "skipping %d bytes for code %d." % (code, reclen-4) 109 109 110 110 elif code == FormatToCode('StringArray'): 111 f id.seek(reclen-4,1)111 f.seek(reclen-4,1) 112 112 print "skipping %d bytes for code %d." % (code, reclen-4) 113 113 114 114 else: 115 115 raise TypeError('BinRead error message: data type: %d not supported yet! (%s)' % (code,EnumToString(enum)[0])) 116 116 117 117 f.close() 118 118 #}}} 119 119 def FormatToCode(format): # {{{ 120 120 """ 121 121 This routine takes the format string, and hardcodes it into an integer, which 122 122 is passed along the record, in order to identify the nature of the dataset being 123 123 sent. 124 124 """ 125 from MatlabFuncs import *126 125 127 126 if strcmpi(format,'Boolean'): 128 127 code=1 … … 148 147 return code 149 148 # }}} 150 149 151 if __name__ == '__main__': 150 if __name__ == '__main__': #{{{ 152 151 if 'PYTHONSTARTUP' in os.environ: 153 152 PYTHONSTARTUP=os.environ['PYTHONSTARTUP'] 154 153 print 'PYTHONSTARTUP =',PYTHONSTARTUP … … 160 159 else: 161 160 print "PYTHONSTARTUP file '%s' does not exist." % PYTHONSTARTUP 162 161 163 import argparse164 162 parser = argparse.ArgumentParser(description='BinRead - function to read binary input file.') 165 163 parser.add_argument('-f','--filin', help='name of binary input file', default='') 164 parser.add_argument('-o','--filout', help='optional name of text output file', default='') 166 165 args = parser.parse_args() 167 166 168 BinRead(args.filin) 169 167 BinRead(args.filin, args.filout) 168 #}}} 169 No newline at end of file
Note:
See TracBrowser
for help on using the repository browser.