source: issm/oecreview/Archive/19101-20495/ISSM-20096-20097.diff

Last change on this file was 20498, checked in by Mathieu Morlighem, 9 years ago

CHG: done with Archive/19101-20495

File size: 2.1 KB
  • ../trunk-jpl/scripts/BinRead.py

     
    55import numpy
    66import math
    77import struct
     8import argparse
     9from MatlabFuncs import *
     10from EnumDefinitions import *
     11from EnumToString import EnumToString
    812
    9 def BinRead(filin,filout=''):
     13def BinRead(filin,filout=''): #{{{
    1014
    11         from MatlabFuncs import *
    12         from EnumDefinitions import *
    13         from EnumToString import EnumToString
    14 
    1515        print "reading binary file."
    1616        f=open(filin,'rb')
    1717
     
    104104                                        print "data[%d,%d] = %f" % (i,j,data[i][j])
    105105
    106106                elif code == FormatToCode('MatArray'):
    107                         fid.seek(reclen-4,1)
     107                        f.seek(reclen-4,1)
    108108                        print "skipping %d bytes for code %d." % (code, reclen-4)
    109109
    110110                elif code == FormatToCode('StringArray'):
    111                         fid.seek(reclen-4,1)
     111                        f.seek(reclen-4,1)
    112112                        print "skipping %d bytes for code %d." % (code, reclen-4)
    113113
    114114                else:
    115115                        raise TypeError('BinRead error message: data type: %d not supported yet! (%s)' % (code,EnumToString(enum)[0]))
    116116
    117117        f.close()
    118 
     118#}}}
    119119def FormatToCode(format): # {{{
    120120        """
    121121        This routine takes the format string, and hardcodes it into an integer, which
    122122        is passed along the record, in order to identify the nature of the dataset being
    123123        sent.
    124124        """
    125         from MatlabFuncs import *
    126125
    127126        if   strcmpi(format,'Boolean'):
    128127                code=1
     
    148147        return code
    149148# }}}
    150149
    151 if __name__ == '__main__':
     150if __name__ == '__main__': #{{{
    152151        if 'PYTHONSTARTUP' in os.environ:
    153152                PYTHONSTARTUP=os.environ['PYTHONSTARTUP']
    154153                print 'PYTHONSTARTUP =',PYTHONSTARTUP
     
    160159                else:
    161160                        print "PYTHONSTARTUP file '%s' does not exist." % PYTHONSTARTUP
    162161
    163         import argparse
    164162        parser = argparse.ArgumentParser(description='BinRead - function to read binary input file.')
    165163        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='')
    166165        args = parser.parse_args()
    167166
    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.