PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 04 Feb 2003 09:30 PM by  Nathan Hagen
Conversion to type double -- problem with READS procedure?
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

Nathan Hagen



New Member


Posts:
New Member


--
04 Feb 2003 09:30 PM
    I have an ordinary ASCII data file formatted in columns with whitespace between them. So, I've been using the IDL "READS" procedure to import the data into IDL variables. However, after some hunting for errors propagating through the code, I discovered that the "READS" procedure was truncating the double-precision variables into float variables before storing them in my type double array. (The numbers I'm using have up to 13-digit precision.) I've been trying to find reasonable ways around this, but everything I've been able to come up so far would be slow and cumbersome. Is there a simple way around this? And, for that matter, I've had to write my own (slow and ugly) code for printing doubles to the screen since PRINT, given an optional argument of, say, FORMAT='(D18.15)', actually distorts the displayed output of a type double variable, such that anything beyond the first 8 characters displayed on the screen are incorrect. Has anyone else had to struggles with these issues as well?

    Peter Mason



    New Member


    Posts:
    New Member


    --
    04 Feb 2003 09:30 PM
    Hi Nathan, I don't think there's a precision problem with IDL's READS (or READF). At least, not on the platform that I use (Win2k). For example: d=0.0d0 t='1234567.8901234567' reads,t,d print,d,format='(d18.10)' 1234567.8901234567 (The same applies for a text file and READF.) What I think is going on is that a FLOAT is creeping into your logic somewhere. Most probably, you aren't declaring the recipient variable for READS, in which case IDL automatically gives you a FLOAT variable. If you want DOUBLE, you have to declare the recipient variable as DOUBLE prior to READS (like in my example). It is no good casting the variable to double afterwards because the damage is already done by then. e.g., ;A is undefined at this point READS,'1234567.8901234567',a ;IDL creates float A val=double(a) ;too late! print,val,,format='(d18.10)' 1234567.8750000000 ;see, too late! HTH Cheers Peter Mason
    You are not authorized to post a reply.


    SIGN UP AND STAY INFORMED

    Sign up to receive the latest news, events, technologies, and special offers.

    SIGN ME UP