X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 02 Mar 2011 06:13 AM by  anon
missing digtis by importing textfile
 4 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
02 Mar 2011 06:13 AM
    Hello, i have a textfile, which contains an array: Example: 1234567.26 1234567.72 1098765.27 1098765.29 5394310.26 3572300.72 5393548.27 3572694.29 i want to import and print this array in idl and started my code with: textfile = read_ascii('textfile.txt') textfile = textfile.field1 textfile = double(textfile) Print, textfile IDL prints: 1234567.3 1234567.8 1098765.3 1098765.3 5394310.5 3572300.8 5393548.5 3572694.3 Wheres the other digits? i want to print my array with full digits without rounding. And the rounding ist also wrong... Hope you unterstand what i want and mean! Thanks for every reply Greetings, TDN

    Deleted User



    New Member


    Posts:
    New Member


    --
    23 Mar 2011 05:07 PM
    Hi there, Well, two things: 1- print procedure needs to have the FORMAT keyword so that you can "display" all the digits that you would like to see on the screen, for example: print, textfile, , format='(f10.2)' 2- You need to declare the input numbers as double, before using any function on them, like double(). In other words, in the text file, the numbers should have a D at the end: 1234567.26D Then, a double precision memory address will be reserved for that number, ie. a 4 byte number. Otherwise, without the D, the number is considered single precision, ie. only 6 or 7 significant digits are used. In double precision, approx. 14 significant digits are used. I hope this helps. Please, take a look at the IDL Help table on "IDL Data Types". Cheers, Fernando

    Deleted User



    New Member


    Posts:
    New Member


    --
    29 Mar 2011 03:46 AM
    Hi Fernando, thank you for your reply. I tried with your advice... I added the D in my inputfile and used the FORMAT keyword with Format='(F10.2,5X,F10.2)'. My inputfile: 1234567.26D 1234567.72D 1098765.27D 1098765.29D 5394310.26D 3572300.72D 5393548.27D 3572694.29D IDL prints: 1234567.25 1234567.75 1098765.25 1098765.25 5394310.50 3572300.75 5393548.50 3572694.25 All digits are displayed, but i want my input-elements without rounding. Hope you have an idea! Cheers, TDN

    Deleted User



    New Member


    Posts:
    New Member


    --
    30 Mar 2011 05:30 PM
    Hi there, What happens is that read_ascii(file) only reads single precision float numbers. You will need instead to do something like: file='C:\path\to\datafile.txt' data = DBLARR(2,4) ; create first an array to keep the double precision numbers. openr, lun, file, /GET_LUN READF, lun, data print, data, format='(f10.2,1x,f10.2)' free_lun, lun Cheers, Fernando

    Deleted User



    New Member


    Posts:
    New Member


    --
    31 Mar 2011 02:53 AM
    Hi, thank you very much. It works now! Cheers, tdn
    You are not authorized to post a reply.