Changeset 7003


Ignore:
Timestamp:
May 8, 2009, 4:07:30 PM (15 years ago)
Author:
ole
Message:

Added errorcheck in convert_dem_from_ascii2netcdf in case lines are too short or too long.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r6884 r7003  
    27782778# @param verbose True if this function is to be verbose.
    27792779def _convert_dem_from_ascii2netcdf(basename_in, basename_out = None,
    2780                                   verbose = False):
     2780                                   verbose = False):
    27812781    """Read Digital Elevation model from the following ASCII format (.asc)
    27822782
     
    29102910    elevation = fid.variables['elevation']
    29112911
    2912     #Store data
     2912    # Store data
    29132913    n = len(lines[6:])
    29142914    for i, line in enumerate(lines[6:]):
     
    29162916        if verbose and i % ((n+10)/10) == 0:
    29172917            print 'Processing row %d of %d' % (i, nrows)
     2918
     2919           
     2920        if len(fields) != ncols:
     2921            msg = 'Wrong number of columns in file "%s" line %d\n' % (basename_in + '.asc', i)
     2922            msg += 'I got %d elements, but there should have been %d\n' % (len(fields), ncols)
     2923            raise Exception, msg
     2924
    29182925        elevation[i, :] = num.array([float(x) for x in fields])
    29192926
Note: See TracChangeset for help on using the changeset viewer.