IDL's lun stands for "logical unit number", and it serves the same purpose as MATLAB's fileid.
fid = fopen('GSS1_t001_cx_ImgRall.dat', 'r');
var0a = fread(fid, [1 4], '*uint8');
var0b = fread(fid, [1 4], '*uint8');
var1 = fread(fid, [1 1], '*float');
var2 = fread(fid, [1 2], '*long');
var3 = fread(fid, [1 4], '*double');
fclose(fid);
Note: the above code assumes that the data in the file is the same "endian" as the system running the code. All current releases of MATLAB happen to be on architectures that are "little endian", so the code assumes that as well. If that does not match the file (certainly possible if you got the file somewhere else) then on the fopen() command line, after the 'r', add an addition parameter 'b' (big-endian)
"endian" in files and in memory refers to whether a memory address is to refer to the "Most Significant Byte" or to the "Least Significant Byte" of the data. So if you have two consecutive bytes in memory, such as hex 01 and then hex 02 in that order, and if you are reading 16 bits ("short", int16), is the 01 the most significant byte of the short or is it the least significant byte of the short? To put it a different way, if the file has hex 01 then 02, is the numeric value to be 1 * 256 + 2, or is it to be 1 + 256 * 2 ? Just like writing coefficients of a polynomial, do you write the coefficient of x^0 then the coefficient of x^1 then the coefficient of x^2 and so on, or do you write the coefficient of x^2 followed by the coefficient of x^1 followed by the coefficient of x^0 ? The two orders are not compatible with each other, but are both internally inconsistent. "Little endian" architectures like all of the x86 and x64 architectures, would say that the order in memory should correspond to 1 + 256 * 2 = 513, whereas "Big endian" architectures would say the order in memory should correspond to 1 * 256 + 2 = 258 . The Internet standards say that when data is transmitted between systems where the byte order is not specifically indicated, that "big endian" order should be used, but that is not the same as what Intel processors use. So if you got your file from outside, such as from a research site, it might be in big-endian order.
Best Answer