X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 14 Feb 2017 09:08 AM by  anon
write a binary file
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
14 Feb 2017 09:08 AM
    dear all I have a density file ( array file) with x-dimension=300 and y-demnsion=240, density=array [300,240]. i want to write it as a binary file with the double precesion format. i used the following commands: openw, lun, 'density.dat', /get_lun writeu, lun, density close, lun but the problem is that if I open the binary file with the MATLAB the dimension of the density, now, is density=array [6,12000]. I know I have to do some manipulation for writing the binary file to keep the original size but I don't know how. any body can help me?? thanks in advance

    Deleted User



    Basic Member


    Posts:143
    Basic Member


    --
    17 Feb 2017 12:06 PM
    I suspect that Matlab might be reading the raw byte data out of the file. In IDL, you typically specify the type of data that is supposed to read in from a binary file. For example: pro dj_forum_2172017_1150 compile_opt idl2 data = dblarr(300,240) data += 5 help, data print, data[0:3, 0:3] openw, lun, "density.dat", /get_lun writeu, lun, data close, lun openr, lun, "density.dat", /get_lun density = dblarr(300,240, /NOZERO) readu, lun, density free_lun, lun help, density print, density[0:3, 0:3] openr, lun, "density.dat", /get_lun byte_density = bytarr(6,12000, /NOZERO) readu, lun, byte_density free_lun, lun help, byte_density print, byte_density[0:3, 0:3] end This outputs: DATA DOUBLE = Array[300, 240] 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 DENSITY DOUBLE = Array[300, 240] 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 5.0000000 BYTE_DENSITY BYTE = Array[6, 12000] 0 0 0 0 20 64 0 0 0 0 20 64 0 0 0 0 I am not sure how you specify the data type and dimensions being read from a binary file in Matlab but I suspect that might be the problem. -David Harris GS
    You are not authorized to post a reply.