how to read a large binary file(*.dat file format) and store it in another file?

Hello, I have a binary data in a *.dat file format (i.e temp.dat). Its a 4DVar data (i.e lat.,lon.,pressure and temp). how to read these data files in MatLab and store it in another file? I cannot attach these files here as it shows that files are unsupported. Please, help me to get the values of temperature from these file formats. If there is any toolbox to read these files, kindly help me regarding this. I have MatLab version "R2013a".
Thanks & regards

Antworten (1)

Girija - do you have four files, one for latitude, longitude, pressure and temperature? Or are all four pieces of information stored within the same file? Do you know how many (say) temperature values there are?
Since the data is in binary, you must know the data type of each element (integer, double, float, etc.) so check out using fopen to open the file, and fread to read the data in.
For example (and this is taken from the link to fread)
% open the file for writing
fid = fopen('temp.dat','wb');
if fid>0
% create a 5x5 matrix
A = magic(5);
% write the matrix data to file
fwrite(fid,A,'double');
% close the file
fclose(fid);
end
% open the file for reading
fid = fopen('temp.dat','rb');
if fid>0
% continue reading until end-of-file is reached
while ~feof(fid)
% read a double
dblVal = fread(fid,1,'double');
% do something with dblVal
if ~isempty(dblVal)
fprintf('dblVal = %f\n',dblVal);
end
end
% close the file
fclose(fid);
end
You can do more than just read in one element at a time (which can be slow) and so can read in multiple elements instead. See the documentation for fread for more details.
In the above code, we write double data to file, and so must read back in the same data type. You will have to do the same for your code given the data type of that data within the binary files.

7 Kommentare

Sir, I have a single file. The data is like this: suppose at xxx degree North and yyy degree east, at pressure level 1000 the temperature is 230(in kelvin).....and so on.Yes, I know the values of temperature data. Thanku Sir, as u have suggested will try and let u know....!!!
Sir, I am sending u the details of data. Kindly, find the attachment and guide me regarding this. Thanks & Regards
Girija - the attached document doesn't really indicate how the data is organized in the binary file. How is the file created? Do you have the code for this?
I dont ve the codes, but I can send the data to ur email, if u feel comfortable.
I think that you will need to contact the author of the software to find out how the data is organized within the (output) binary data file. From that, you should be able to determine how you might go about reading the data from that file.
By the way, where are you getting this data? From the NOAA Earth System Research Laboratory or similar website?
similar website....!!
Which website, because it might provide details on how the data files are constructed?
Do you have to download software to create the data, or do you run it from the web?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import and Analysis finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 3 Sep. 2014

Kommentiert:

am 4 Sep. 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by