Changeset 27839
- Timestamp:
- 07/19/23 13:46:00 (20 months ago)
- Location:
- issm/trunk-jpl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/scripts/BinRead.py
r24726 r27839 1 #!/usr/bin/env python 1 #!/usr/bin/env python3 2 2 import numpy as np 3 3 from os import environ, path … … 6 6 from argparse import ArgumentParser 7 7 8 def BinRead( filin, filout='', verbose=0): #{{{8 def BinRead(infile, outfile='', verbose=0): #{{{ 9 9 10 print( "reading binary file.")11 f = open( filin, 'rb')10 print('reading binary file') 11 f = open(infile, 'rb') 12 12 13 if filout:14 sys.stdout = open( filout, 'w')13 if outfile: 14 sys.stdout = open(outfile, 'w') 15 15 16 16 while True: 17 17 try: 18 # Step 1: read size of record name18 # Step 1: Read size of record name 19 19 recordnamesize = struct.unpack('i', f.read(struct.calcsize('i')))[0] 20 20 except struct.error as e: 21 print( "probable EOF: {}".format(e))21 print('probable EOF: {}'.format(e)) 22 22 break 23 23 24 print( "============================================================================ ")24 print('============================================================================') 25 25 if verbose > 2: 26 print( "\n recordnamesize = {}".format(recordnamesize))27 recordname = struct.unpack('{}s'.format(recordnamesize), f.read(recordnamesize))[0] 28 print( "field: {}".format(recordname))26 print('\n recordnamesize = {}'.format(recordnamesize)) 27 recordname = struct.unpack('{}s'.format(recordnamesize), f.read(recordnamesize))[0].decode('ASCII') 28 print('field: {}'.format(recordname)) 29 29 30 # Step 2: read the data itself.31 # first read length of record30 # Step 2: Read the data itself 31 # First read length of record 32 32 #reclen = struct.unpack('i', f.read(struct.calcsize('i')))[0] 33 33 reclen = struct.unpack('q', f.read(struct.calcsize('q')))[0] 34 34 if verbose > 1: 35 print( "reclen = {}".format(reclen))35 print('reclen = {}'.format(reclen)) 36 36 37 # read data code:37 # Read data code 38 38 code = struct.unpack('i', f.read(struct.calcsize('i')))[0] 39 print( "Format = {} (code {})".format(CodeToFormat(code), code))39 print('Format = {} (code {})'.format(CodeToFormat(code), code)) 40 40 41 41 if code == FormatToCode('Boolean'): 42 42 bval = struct.unpack('i', f.read(reclen - struct.calcsize('i')))[0] 43 print( "value = {}".format(bval))43 print('value = {}'.format(bval)) 44 44 45 45 elif code == FormatToCode('Integer'): 46 46 ival = struct.unpack('i', f.read(reclen - struct.calcsize('i')))[0] 47 print( "value = {}".format(ival))47 print('value = {}'.format(ival)) 48 48 49 49 elif code == FormatToCode('Double'): 50 50 dval = struct.unpack('d', f.read(reclen - struct.calcsize('i')))[0] 51 print( "value = {}".format(dval))51 print('value = {}'.format(dval)) 52 52 53 53 elif code == FormatToCode('String'): 54 54 strlen = struct.unpack('i', f.read(struct.calcsize('i')))[0] 55 55 if verbose > 1: 56 print( "strlen = {}".format(strlen))56 print('strlen = {}'.format(strlen)) 57 57 sval = struct.unpack('{}s'.format(strlen), f.read(strlen))[0] 58 print( "value = '{}'".format(sval))58 print('value = {}'.format(sval)) 59 59 60 60 elif code == FormatToCode('BooleanMat'): 61 # read matrix type:61 # Read matrix type 62 62 mattype = struct.unpack('i', f.read(struct.calcsize('i')))[0] 63 print( "mattype = {}".format(mattype))63 print('mattype = {}'.format(mattype)) 64 64 65 # now read matrix65 # Read matrix 66 66 s = [0, 0] 67 67 s[0] = struct.unpack('i', f.read(struct.calcsize('i')))[0] 68 68 s[1] = struct.unpack('i', f.read(struct.calcsize('i')))[0] 69 print( "size = [{}x{}]".format(s[0], s[1]))69 print('size = [{}x{}]'.format(s[0], s[1])) 70 70 data = np.zeros((s[0], s[1])) 71 71 for i in range(s[0]): 72 72 for j in range(s[1]): 73 data[i][j] = struct.unpack('d', f.read(struct.calcsize('d')))[0] #get to the "c" convention, hence the transpose73 data[i][j] = struct.unpack('d', f.read(struct.calcsize('d')))[0] 74 74 if verbose > 2: 75 print( "data[{}, {}] = {}".format(i, j, data[i][j]))75 print('data[{}, {}] = {}'.format(i, j, data[i][j])) 76 76 77 77 elif code == FormatToCode('IntMat'): 78 # read matrix type:78 # Read matrix type 79 79 mattype = struct.unpack('i', f.read(struct.calcsize('i')))[0] 80 print( "mattype = {}".format(mattype))80 print('mattype = {}'.format(mattype)) 81 81 82 # now read matrix82 # Read matrix 83 83 s = [0, 0] 84 84 s[0] = struct.unpack('i', f.read(struct.calcsize('i')))[0] 85 85 s[1] = struct.unpack('i', f.read(struct.calcsize('i')))[0] 86 print( "size = [{}x{}]".format(s[0], s[1]))86 print('size = [{}x{}]'.format(s[0], s[1])) 87 87 data = np.zeros((s[0], s[1])) 88 88 for i in range(s[0]): 89 89 for j in range(s[1]): 90 data[i][j] = struct.unpack('d', f.read(struct.calcsize('d')))[0] #get to the "c" convention, hence the transpose90 data[i][j] = struct.unpack('d', f.read(struct.calcsize('d')))[0] 91 91 if verbose > 2: 92 print( "data[{}, {}] = {}".format(i, j, data[i][j]))92 print('data[{}, {}] = {}'.format(i, j, data[i][j])) 93 93 94 94 elif code == FormatToCode('DoubleMat'): 95 # read matrix type:95 # Read matrix type 96 96 mattype = struct.unpack('i', f.read(struct.calcsize('i')))[0] 97 print( "mattype = {}".format(mattype))97 print('mattype = {}'.format(mattype)) 98 98 99 # now read matrix99 # Read matrix 100 100 s = [0, 0] 101 101 s[0] = struct.unpack('i', f.read(struct.calcsize('i')))[0] 102 102 s[1] = struct.unpack('i', f.read(struct.calcsize('i')))[0] 103 print( "size = [{}x{}]".format(s[0], s[1]))103 print('size = [{}x{}]'.format(s[0], s[1])) 104 104 data = np.zeros((s[0], s[1])) 105 105 for i in range(s[0]): 106 106 for j in range(s[1]): 107 data[i][j] = struct.unpack('d', f.read(struct.calcsize('d')))[0] #get to the "c" convention, hence the transpose107 data[i][j] = struct.unpack('d', f.read(struct.calcsize('d')))[0] 108 108 if verbose > 2: 109 print( "data[{}, {}] = {}".format(i, j, data[i][j]))109 print('data[{}, {}] = {}'.format(i, j, data[i][j])) 110 110 111 111 elif code == FormatToCode('MatArray'): 112 112 f.seek(reclen - 4, 1) 113 print( "skipping {} bytes for code {}.".format(code, reclen - 4))113 print('skipping {} bytes for code {}'.format(code, reclen - 4)) 114 114 elif code == FormatToCode('StringArray'): 115 115 f.seek(reclen - 4, 1) 116 print( "skipping {} bytes for code {}.".format(code, reclen - 4))116 print('skipping {} bytes for code {}'.format(code, reclen - 4)) 117 117 118 118 else: … … 123 123 124 124 def FormatToCode(format): # {{{ 125 """ 126 This routine takes the format string, and hardcodes it into an integer, which 127 is passed along the record, in order to identify the nature of the dataset being 128 sent. 125 """This routine takes the format string and converts it into an integer, 126 which is passed along with the record in order to identify the nature of 127 the data being sent. 129 128 """ 130 129 … … 154 153 155 154 def CodeToFormat(code): # {{{ 156 """ 157 This routine takes the format string, and hardcodes it into an integer, which 158 is passed along the record, in order to identify the nature of the dataset being 159 sent. 155 """This routine takes a datatype code and converts it to the corresponding 156 string in order to identify the nature of the data retrieved. 160 157 """ 161 158 … … 186 183 if __name__ == '__main__': #{{{ 187 184 parser = ArgumentParser(description='BinRead - function to read binary input file.') 188 parser.add_argument('-f', '-- filin', help='name of binary input file', default='')189 parser.add_argument('-o', '-- filout', help='optional name of text output file', default='')185 parser.add_argument('-f', '--infile', help='name of binary input file', default='') 186 parser.add_argument('-o', '--outfile', help='optional name of text output file', default='') 190 187 parser.add_argument('-v', '--verbose', help='optional level of output', default=0) 191 188 args = parser.parse_args() 192 189 193 BinRead(args. filin, args.filout, args.verbose)190 BinRead(args.infile, args.outfile, args.verbose) 194 191 #}}} -
issm/trunk-jpl/src/m/classes/initialization.m
r27505 r27839 181 181 WriteData(fid,prefix,'object',self,'fieldname','hydraulic_potential','format','DoubleMat','mattype',1); 182 182 WriteData(fid,prefix,'object',self,'fieldname','sample','format','DoubleMat','mattype',1); 183 WriteData(fid,prefix,'object',self,'fieldname','debris','format','DoubleMat','mattype',1,'scale',yts); 183 WriteData(fid,prefix,'object',self,'fieldname','debris','format','DoubleMat','mattype',1); 184 WriteData(fid,prefix,'object',self,'fieldname','age','format','DoubleMat','mattype',1,'scale',yts); 184 185 185 186 if md.thermal.isenthalpy, -
issm/trunk-jpl/test/NightlyRun/test2010.py
r27747 r27839 124 124 areaice = md.results.TransientSolution.SealevelBarystaticIceArea 125 125 areaice[np.isnan(areaice)] = 0 126 print(np.isnan(areaice))127 print(np.sum(areaice))128 126 loadice = md.results.TransientSolution.SealevelBarystaticIceLoad 129 127 rad_e = md.solidearth.planetradius
Note:
See TracChangeset
for help on using the changeset viewer.