Changeset 0f010c9 in sasview


Ignore:
Timestamp:
Jul 20, 2017 11:50:00 AM (7 years ago)
Author:
lewis
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
19296dc
Parents:
58a255b
Message:

Catch error when incorrect number of intensity/error points in file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/file_converter/ascii2d_loader.py

    r58a255b r0f010c9  
    117117        current_line += 1 
    118118 
    119         current_line, I = _load_points(all_lines, current_line, width*height) 
    120         dI = np.zeros(width*height) 
     119        try: 
     120            current_line, I = _load_points(all_lines, current_line, width*height) 
     121            dI = np.zeros(width*height) 
    121122 
    122         # Load error data if it's provided 
    123         if iflag == 3: 
    124             _, dI = _load_points(all_lines, current_line, width*height) 
     123            # Load error data if it's provided 
     124            if iflag == 3: 
     125                _, dI = _load_points(all_lines, current_line, width*height) 
     126        except Exception as e: 
     127            err_msg = "File incorrectly formatted.\n" 
     128            if str(e).find("list index") != -1: 
     129                err_msg += ("Incorrect number of data points. Expected {} intensity").format(width*height) 
     130                if iflag == 3: 
     131                    err_msg += " and error" 
     132                err_msg += " points." 
     133            else: 
     134                err_msg += str(e) 
     135            raise ValueError(err_msg) 
    125136 
    126137        # Format data for use with Data2D 
Note: See TracChangeset for help on using the changeset viewer.