I am stuck on trying to extract the data of a .jsf file to produce an image of the binary data. When viewing the format of the data I have the following:
From what I was told by the creator: Each message starts with a SonarMessageHeaderType structure (from SonarMessages.h) which is 16 bytes long. The key field, byteCount indicates the bytes to follow. So to read a JSF file, read the 16-byte header, and then read the number of bytes to follow to get to the next message.To create a time series for this format, extract the array of 16-bit unsigned integers, scale by 2 ** -n where N is the weighting factor in the header.
For this extraction I am trying to use Matlab to read the specific file and then input the data into a function to output an image. From a previous post I have posted,Previous post, my code so far looks as followed:
clear
clc
fid= fopen('20160503.143239.0000000.jsf', 'r', 'l')
if fid == -1
error('File is not opened');
end
record=0;
while ~feof(fid)
data = fread(fid,1,'uint16');
record=record+1;
end
fclose(fid);
I am opening the data file to read binary data (rb) and then using ' l ' to use little endain as the machinefmt states machinefmt . I set an if statement to determine if the file is opened correctly, which when I run the above code it does not produce an error. I then run into two situations that I am stuck on. If I am supposed to read the binary data which follows a 16 byte header and a 240 byte sub header , should I use the X = fseek(fid, 256, 'cof')
to skip over the header and sub header and start at the binary data before reading the data?
Second problem is when I am trying to read the data. I created a while statement to have the fread function read the file until the end. The file contains over 22,000 lines of data. From what the creator said I need to extract a 16-bit unsigned integer array, so i used the 'uint16' in the fread. When I run the code however, I am receiving an empty 0x0 array for data. The attached image shows part of the file in a jsf viewer for more detail about the file. Could anyone put me in the right direction onto how exactly I should be extracting the file to get the array and plug it into a function like image() to see the acoustic images? Would I have to get some kind of count on the file being read to be able to set data = zeros(x,y) before, then reopen the file and extract? Sorry in advance for the lack of coding skill, this is my first time trying to extract a file using Matlab.
4 Comments
Guillaume (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/455140-how-to-read-binary-data-little-endain-from-a-jsf-file-and-display-an-image#comment_691407
James McGinley (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/455140-how-to-read-binary-data-little-endain-from-a-jsf-file-and-display-an-image#comment_691418
Guillaume (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/455140-how-to-read-binary-data-little-endain-from-a-jsf-file-and-display-an-image#comment_691441
James McGinley (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/455140-how-to-read-binary-data-little-endain-from-a-jsf-file-and-display-an-image#comment_691445
Sign in to comment.