X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 31 Jan 2003 02:39 AM by  anon
writing binary files using writeu
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
31 Jan 2003 02:39 AM
    Hello I am a beginner at IDL and I have a problem with writing a simple array to binary files using writeu. Writing the same file in ASCII works fine, but I cannot read a binary file written with writeu (I think there are type conversion errors -why?). The documentation on IDL basics is dreadful, hence I am writing to this group. Here is my code: pro bwriteu2 close, /all file_output2='banana_binary.out' file_output3='banana_ascii.out' openw,2,file_output2 openw,3,file_output3 nrows=89.0 ncols=89.0 my_array=fltarr(nrows, ncols) for e=0.0, nrows-1. do begin for f=0.0, ncols-1. do begin my_array(f,e)=(1+f)*(1+e) my_array(f,e)=float(my_array(f,e)) endfor endfor for k=0.0, nrows-1. do begin for l=0.0, ncols-1. do begin writeu,2,my_array(l,k) printf,3,my_array(l,k) endfor endfor close,/all stop end The ASCII file is written in one column fine, but the binary is not - why? Thanks a lot if you reply Eddie Graham

    Deleted User



    New Member


    Posts:
    New Member


    --
    31 Jan 2003 02:39 AM
    Hi Your code seems to work fine (I ran the exact code on my machine). I think how you're reading it in is the problem. First thing, when writing to binary, you can just use: writeu,2,my_array instead of putting it in the loop, this writes the entire array to the file. For instance, the banana_binary.out is 31684 bytes (89*89*4). This means it wrote out the right number of bytes (4 bytes for a real). The binary file stores the binary representation of the real numer array (which take up 4 bytes of memory per element) The ascii file stores the literal ascii data. This prints to the screen nicely, but takes up space with large arrays. For instance, the size of the ascii data file is 110894 bytes. That is because each line is 14 bytes ... and increase in size by 350% (that is, 14/4). I hope this helps. -Ken
    You are not authorized to post a reply.