Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The illegal floating point operation is probably not from <code>not(eof(1))</code> but from <code>readf, 1, line</code> or carried over from another portion of the code.</p> <p>IDL is expecting to read in 41 32-bit float values, but some or all of the values it reads in are not valid floating point numbers. Not all 32-bit series of 1s and 0s make a valid IEEE float32 (the "float" values used in IDL and most other languages). If you inadvertently encounter the end of the file, there's a high chance that some of the data read from the file won't fit nicely into a float32. When that happens, IDL will attempt to make an informed guess as to which float number your data should have been, but doing so is not technically part of the IEEE standard, so it raises the <code>Program caused arithmetic error: Floating illegal operand</code> error.</p> <p>To investigate, you might like to try substituting the following code:</p> <pre><code>close, 1 &amp; openr, 1, filename, error=err if (err ne 0) then begin close, 1 n = 0 return endif line = bytarr(41 * 4) while not(eof(1)) do begin readf, 1, line endwhile </code></pre> <p>In this case, because you are reading into a byte array instead of a float array, the only error should be <code>READF: End of file encountered. Unit: 1, File: results</code>.</p> <p>Another possible issue is the use of <code>not(eof(1))</code>, which is non-standard. In IDL, <code>not</code> is the bit-wise not, meaning it inverts all the bits of the next term. The more appropriate operator here would be "logical not", <code>~</code>. Thus instead of <code>not(eof(1))</code> or <code>not eof(1)</code>, consider using <code>~eof(1)</code>. In this particular case, it's unlikely to matter, since <code>eof</code> should return either <code>1B</code> or <code>0B</code>, the bit-wise inverse of which are identical to the logical inverse. All the same, it's another thing to try which debugging.</p> <p>Finally, it's possible that the <code>Floating illegal operand</code> error is actually being caused <strong>before</strong> the <code>READF: End of file encountered</code> error. As unintuitive as this is, consider the following block of code:</p> <pre><code>x = sqrt(-1.0) print, 'Hello, World.' </code></pre> <p>This outputs:</p> <pre><code>Hello, World. % Program caused arithmetic error: Floating illegal operand </code></pre> <p>Notice that <code>Hello, World.</code> printed <strong>before</strong> the floating point illegal operand error. That's because IDL doesn't actually report floating point errors until either a function returns, the program ends/crashes, or the <code>check_math()</code> function is called. To check if your program is generating the floating point error before this block, place <code>print, check_math()</code> at the top of the code block. If doing so prints anything besides 0, then floating point errors occurred before the block. Using <code>check_math()</code> also resets these error states, so you can inhibit the floating point error messages by placing <code>math_err = check_math()</code> after each statement which might cause a floating point error.</p> <p>Here is a modified version of your original code which might handle all the errors above:</p> <pre><code>math_err = check_math() ; remove any lingering floating point errors close, 1 openr, 1, filename, error=err if err ne 0 then begin close, 1 n = 0 return endif line = fltarr(41) catch, err ; return here if a non-math error happens if err ne 0 then begin catch, /cancel ; prevent infinite loop between catch and message if !error_state.name eq 'IDL_M_FILE_EOF' then begin ; Handle premature end-of-file here. endif else begin message, /reissue_last ; issue non-eof errors normally endelse endif else begin while ~eof(1) do begin readf, 1, line ; Handle new line here. endwhile catch, /cancel ; stop error checking endelse </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload