Ignore:
Timestamp:
May 16, 2005, 11:06:22 AM (19 years ago)
Author:
duncan
Message:

refactoring dealing with point files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pmesh/load_mesh/loadASCII.py

    r1377 r1394  
    55
    66for example:
    7 elevation
    8 0.6 0.7 4.9
    9 1.9 2.8 5
    10 2.7 2.4 5.2
     7elevation, friction
     80.6, 0.7, 4.9, 0.3
     91.9, 2.8, 5, 0.3
     102.7, 2.4, 5.2, 0.3
    1111
    1212The first two columns are always implicitly assumed to be x, y coordinates.
    13 
     13Use the same delimiter for the attribute names and the data
    1414
    1515The format for a Points dictionary is:
     
    9797    Note: This might throw a can't load file error
    9898    """
    99    
    100     if ofile[-4:]== ".tsh":
    101         dict = _read_tsh_file(ofile)
    102     elif ofile[-4:]== ".msh":
    103         dict = _read_msh_file(ofile)
    104     else:     
    105         msg = 'Extension %s is unknown' %ofile[-4:]
    106         raise IOError, msg       
     99    try:
     100        if ofile[-4:]== ".tsh":
     101            dict = _read_tsh_file(ofile)
     102        elif ofile[-4:]== ".msh":
     103            dict = _read_msh_file(ofile)
     104        else:     
     105            msg = 'Extension %s is unknown' %ofile[-4:]
     106            raise IOError, msg
     107    except SyntaxError:
     108            msg = 'File could not be opened'
     109            raise IOError, msg
     110    except IndexError:
     111            msg = 'File could not be opened'
     112            raise IOError, msg
     113       
    107114    return dict
    108115
     
    10521059            msg = 'Could not open file %s ' %ofile
    10531060            raise IOError, msg
     1061        except SyntaxError:
     1062            msg = 'File could not be opened'
     1063            raise IOError, msg
     1064        except IndexError:
     1065            msg = 'File could not be opened'
     1066            raise IOError, msg
    10541067       
    10551068    elif ofile[-4:]== ".pts":
     
    12601273                if len(att_names) != len(numbers):
    12611274                    fd.close()
    1262                     raise TitleAmountError
    1263                    
     1275                    # It might not be a problem with the title
     1276                    #raise TitleAmountError
     1277                    raise IOError
    12641278                for i,num in enumerate(numbers):
    12651279                    num.strip()
     
    13111325   
    13121326#FIXME (DSG) need an export_points_file method..               
    1313 def export_xya_file( file_name, xya_dict, title, delimiter = ','):
     1327def _write_xya_file( file_name, xya_dict, delimiter = ','):
    13141328    """
    13151329    export a file, ofile, with the format
     
    13241338    #FIXME, move the test for this from meshharness to loadasciiharness
    13251339    points = xya_dict['pointlist']
    1326     pointattributes = xya_dict['pointattributelist']
     1340    pointattributes = xya_dict['attributelist']
    13271341   
    13281342    fd = open(file_name,'w')
    1329    
    1330     fd.write(title+"\n")
     1343 
     1344    titlelist = ""
     1345    for title in pointattributes.keys():
     1346        titlelist = titlelist + title + delimiter
     1347    titlelist = titlelist[0:-len(delimiter)] # remove the last delimiter
     1348    fd.write(titlelist+"\n")
    13311349    #<vertex #> <x> <y> [attributes]
    1332     for vert, vertatts in map(None, points, pointattributes):
     1350    for i,vert in enumerate( points):
     1351       
    13331352        attlist = ""
    1334         for att in vertatts:
    1335             attlist = attlist + str(att)+ delimiter
     1353        for att in pointattributes.keys():
     1354            attlist = attlist + str(pointattributes[att][i])+ delimiter
    13361355        attlist = attlist[0:-len(delimiter)] # remove the last delimiter
    13371356        attlist.strip()
Note: See TracChangeset for help on using the changeset viewer.