Changeset 25694
- Timestamp:
- 10/20/20 00:21:07 (4 years ago)
- Location:
- issm/trunk-jpl/src/m/solve
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/solve/parseresultsfromdisk.m
r25688 r25694 129 129 results(index).(result.fieldname)=result.field; 130 130 end 131 132 disp(results) 133 disp(length(results)) 134 pause 135 131 136 % }}} 132 137 function results=parseresultsfromdiskioserialsequential(md,filename) % {{{ -
issm/trunk-jpl/src/m/solve/parseresultsfromdisk.py
r25688 r25694 78 78 79 79 def parseresultsfromdiskioserial(md, filename): # {{{ 80 # Open file80 # Open file 81 81 try: 82 82 fid = open(filename, 'rb') 83 83 except IOError as e: 84 84 raise IOError("parseresultsfromdisk error message: could not open {} for binary reading".format(filename)) 85 86 #initialize results: 87 saveres = [] 88 89 #Read fields until the end of the file. 90 loadres = ReadData(fid, md) 91 92 counter = 0 93 check_nomoresteps = 0 94 step = loadres['step'] 95 96 while loadres: 97 #check that the new result does not add a step, which would be an error: 98 if check_nomoresteps: 99 if loadres['step'] >= 1: 100 raise TypeError("parsing results for a steady-state core, which incorporates transient results!") 101 102 #Check step, increase counter if this is a new step 103 if(step != loadres['step'] and loadres['step'] > 1): 104 counter = counter + 1 105 step = loadres['step'] 106 107 #Add result 108 if loadres['step'] == 0: 109 #if we have a step = 0, this is a steady state solution, don't expect more steps. 110 index = 0 111 check_nomoresteps = 1 112 elif loadres['step'] == 1: 113 index = 0 114 else: 115 index = counter 116 117 if index > len(saveres) - 1: 118 for i in range(len(saveres) - 1, index - 1): 119 saveres.append(None) 120 saveres.append(resultsclass.results()) 121 elif saveres[index] is None: 122 saveres[index] = resultsclass.results() 123 124 #Get time and step 125 if loadres['step'] != -9999.: 126 saveres[index].__dict__['step'] = loadres['step'] 127 if loadres['time'] != -9999.: 128 saveres[index].__dict__['time'] = loadres['time'] 129 130 #Add result 131 saveres[index].__dict__[loadres['fieldname']] = loadres['field'] 132 133 #read next result 134 loadres = ReadData(fid, md) 135 85 86 # Collect all results in a list 87 allresults = [] 88 while True: 89 # Read next result 90 result = ReadData(fid, md) 91 92 if result == None: 93 if allresults == []: 94 raise Exception('no results found in binary file ' + filename) 95 else: 96 break 97 98 allresults.append(result) 136 99 fid.close() 137 100 138 return saveres 101 # Now, process all results and find out how many steps we have 102 numresults = len(allresults) 103 allsteps = np.zeros((numresults, 1)) 104 for i in range(numresults): 105 allsteps[i] = allresults[i]['step'] 106 pos = np.where(allsteps != -9999) 107 allsteps = np.sort(np.unique(allsteps[pos])) 108 109 # Ok, now construct structure 110 results = [] 111 for i in range(len(allsteps)): 112 results.append(resultsclass.results()) 113 for i in range(numresults): 114 result = allresults[i] 115 index = 0 116 if result['step'] != -9999: 117 index = np.where(result['step'] == allsteps)[0][0] 118 setattr(results[index], 'step', result['step']) 119 if result['time'] != -9999: 120 setattr(results[index], 'time', result['time']) 121 setattr(results[index], result['fieldname'], result['field']) 122 123 return results 139 124 # }}} 140 125
Note:
See TracChangeset
for help on using the changeset viewer.