Changeset 19348


Ignore:
Timestamp:
05/07/15 22:40:01 (10 years ago)
Author:
Eric.Larour
Message:

CHG: transmitting new way of dealing with steps -1, 0 and 1 in the parseresultsfromdisk from matlab to python.

Location:
issm/trunk-jpl/src/m/solve
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/solve/parseresultsfromdisk.m

    r19343 r19348  
    6161        end
    6262        results(index).step=result.step;
    63         if result.time~=-9999,
    64                 results(index).time=result.time;
    65         end
    6663        results(index).(result.fieldname)=result.field;
    6764
  • issm/trunk-jpl/src/m/solve/parseresultsfromdisk.py

    r19336 r19348  
    3434                raise IOError("loadresultsfromdisk error message: could not open '%s' for binary reading." % filename)
    3535
     36        #initialize results:
    3637        results=[]
     38        results.append(None)
    3739
    3840        #Read fields until the end of the file.
    3941        result=ReadData(fid)
    40         while result:
    41                 print result['step']
    42                 if   result['step'] > len(results):
    43                         for i in xrange(len(results),result['step']-1):
     42
     43        counter=0
     44        check_nomoresteps=0
     45        step=result['step']
     46
     47        while result:
     48
     49                if check_nomoresteps:
     50                        #check that the new result does not add a step, which would be an error:
     51                        if result['step']>=1:
     52                                raise TypeError("parsing results for a steady-state core, which incorporates transient results!")
     53
     54                #Check step, increase counter if this is a new step
     55                if(step!=result['step'] and result['step']>1):
     56                        counter = counter + 1
     57                        step    = result['step']
     58
     59                #Add result
     60                if result['step']==-1:
     61                        #specialty case, put this result at the beginning of the structure
     62                        index = 0
     63                        result['step']=0
     64                elif result['step']==0:
     65                        #if we have a step = 0, this is a steady state solutoin, don't expect more steps.
     66                        index = 0;
     67                        check_nomoresteps=1
     68       
     69                elif result['step']==1:
     70                        index = 0
     71                else:
     72                        index = counter;
     73       
     74                if index > len(results)-1:
     75                        for i in xrange(len(results)-1,index-1):
    4476                                results.append(None)
    4577                        results.append(resultsclass.results())
    46                 elif results[result['step']-1] is None:
    47                         results[result['step']-1]=resultsclass.results()
     78               
     79                elif results[index] is None:
     80                        results[index]=resultsclass.results()
     81
     82                if index==0 and  step==3:
     83                        print result
     84                       
    4885                #Get time and step
    49                 setattr(results[result['step']-1],'step',result['step'])
    50                 setattr(results[result['step']-1],'time',result['time'])
     86                setattr(results[index],'step',result['step'])
     87                setattr(results[index],'time',result['time'])
    5188       
    5289                #Add result
    53                 if hasattr(results[result['step']-1],result['fieldname']) and not m.strcmp(result['fieldname'],'SolutionType'):
    54                         setattr(results[result['step']-1],result['fieldname'],numpy.vstack((getattr(results[result['step']-1],result['fieldname']),result['field'])))
    55                 else:
    56                         setattr(results[result['step']-1],result['fieldname'],result['field'])
     90                if hasattr(results[index],result['fieldname']) and not m.strcmp(result['fieldname'],'SolutionType'):
     91                        setattr(results[index],result['fieldname'],numpy.vstack((getattr(results[index],result['fieldname']),result['field'])))
     92                else:
     93                        setattr(results[index],result['fieldname'],result['field'])
    5794
    5895                #read next result
Note: See TracChangeset for help on using the changeset viewer.