Changeset 13341


Ignore:
Timestamp:
09/12/12 11:20:47 (13 years ago)
Author:
jschierm
Message:

NEW: Python version of expwrite (plus some cleanup).

Location:
issm/trunk-jpl/src/m/exp
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/exp/expread.py

    r13338 r13341  
    1616
    1717           Usage:
    18               Struct=expread(filename)
     18              contours=expread(filename)
    1919
    2020           Example:
    21               Struct=expread('domainoutline.exp')
    22               Struct=expread('domainoutline.exp')
     21              contours=expread('domainoutline.exp')
     22              contours=expread('domainoutline.exp')
    2323
    2424           See also EXPDOC, EXPWRITEASVERTICES
     
    3030
    3131        #initialize number of profile
    32         Structs=[]
     32        contours=[]
    3333
    3434        #open file
     
    3939
    4040                #update number of profiles
    41                 Struct=OrderedDict()
     41                contour=OrderedDict()
    4242
    4343                #Get file name
     
    5151                        break
    5252                if len(A[1])>5:
    53                         Struct['name']=A[1][5:-1]
     53                        contour['name']=A[1][5:-1]
    5454                else:
    55                         Struct['name']=''
     55                        contour['name']=''
    5656
    5757                #Get Icon
     
    6767                #Get number of nodes and density
    6868                A=fid.readline().split()
    69                 Struct['nods']   =float(A[0])
    70                 Struct['density']=float(A[1])
     69                contour['nods']   =float(A[0])
     70                contour['density']=float(A[1])
    7171
    7272                #Get Info
     
    7777
    7878                #Get Coordinates
    79                 Struct['x']=numpy.empty(Struct['nods'])
    80                 Struct['y']=numpy.empty(Struct['nods'])
    81                 for i in xrange(int(Struct['nods'])):
     79                contour['x']=numpy.empty(contour['nods'])
     80                contour['y']=numpy.empty(contour['nods'])
     81                for i in xrange(int(contour['nods'])):
    8282                        A=fid.readline().split()
    83                         Struct['x'][i]=float(A[0])
    84                         Struct['y'][i]=float(A[1])
    85 
    86 #               if(Struct['nods']~=length(Struct['x']))error(['Profile ' num2str ' reports incorrect length']); end;
     83                        contour['x'][i]=float(A[0])
     84                        contour['y'][i]=float(A[1])
    8785
    8886                #Check if closed
    89                 if (Struct['nods'] > 1) and \
    90                    (Struct['x'][-1] == Struct['x'][0]) and \
    91                    (Struct['y'][-1] == Struct['y'][0]):
    92                         Struct['closed']=True
     87                if (contour['nods'] > 1) and \
     88                   (contour['x'][-1] == contour['x'][0]) and \
     89                   (contour['y'][-1] == contour['y'][0]):
     90                        contour['closed']=True
    9391                else:
    94                         Struct['closed']=False
     92                        contour['closed']=False
    9593
    96                 Structs.append(Struct)
     94                contours.append(contour)
    9795
    9896        #close file
    9997        fid.close()
    10098
    101         return Structs
     99        return contours
    102100
  • issm/trunk-jpl/src/m/exp/expwrite.m

    r13021 r13341  
    2121        end
    2222   
    23    if isfield(a,'name'),
    24            if ~isempty(a(n).name),
    25                    fprintf(fid,'%s%s\n','## Name:',a(n).name);
    26            else
    27                    fprintf(fid,'%s\n','## Name:');
    28            end
    29    else
    30            fprintf(fid,'%s\n','## Name:');
    31    end
     23        if isfield(a,'name'),
     24                if ~isempty(a(n).name),
     25                        fprintf(fid,'%s%s\n','## Name:',a(n).name);
     26                else
     27                        fprintf(fid,'%s\n','## Name:');
     28                end
     29        else
     30                fprintf(fid,'%s\n','## Name:');
     31        end
    3232   
    33    fprintf(fid,'%s\n','## Icon:0');
    34    fprintf(fid,'%s\n','# Points Count Value');
    35    fprintf(fid,'%i %f\n',[length(a(n).x) a(n).density]);
    36    fprintf(fid,'%s\n','# X pos Y pos');
     33        fprintf(fid,'%s\n','## Icon:0');
     34        fprintf(fid,'%s\n','# Points Count Value');
     35        fprintf(fid,'%i %f\n',[length(a(n).x) a(n).density]);
     36        fprintf(fid,'%s\n','# X pos Y pos');
    3737        fprintf(fid,'%10.10f %10.10f\n',[a(n).x a(n).y]');
    38         fprintf(fid,'\n','');
    39    
     38        fprintf(fid,'\n');
     39
    4040end
    4141fclose(fid);
Note: See TracChangeset for help on using the changeset viewer.