Hi,
I've been converting masses of binary files to text files for a while. Using some code I wrote, I initially convert these binary files (just full of numbers of data I look at on a daily basis - they are split up into smaller files as opposed to having one monster file) at a rate of 3 files/min. However, as time goes on, the whole process slows down a LOT -> after 3 hours, i'm going at a rate of 1 file/10 min.
I thought I had a memory leak somewhere or I was not closing the binary files properly as I loaded up new ones, but it doesn't seem to be the case. I threw in some extra commands to try to force close any files that were open, but i still get this inexplicable slowdown in file conversion. I looked at memory usage and nothing seems to be building - I get regular spikes as the .dat file is loaded, processed, and closed.
Here is the basic code with very little modified (FYI, I'm not a programmer at all so excuse any ugliness in my code).
Btw I'm aware that with STUFF0 I'm using a vercat operation which is slow, but at most that array is only a few thousand long ,and 3000x1 shouldn't be creating minutes of slowdown as vercat goes to 3001x1.
Even though I specifically close the file using its FID, I purposely force a close(all) and then just try to set FID=[] to see if blanking it out helps.
I'd appreciate any help, thanks!
STUFF1 = -56*ones(XXXX,1)
STUFF2 = -56*ones(XXXX,1)
for i=1:length(Files)
[FID,MESSAGE]=fopen(char(Files(i))) ; % load up the ith file
status=fseek(FID,0,'eof') ;% place the marker at the origin which is EOF
length_of_file = ftell(FID) - 1 ; % -1 because the last byte index is the EOF which simply marks the end of file
% check for successful load
if status == 0
disp('Binary File loaded Successfully')
elseif status == -1
disp('Failed Loading of Binary File')
return
end
fseek(FID,0,'bof') ;
fileversion=fread(FID,1,'uchar'); % pull out fileversion - shoud always be 1
timestamp=fread(FID,1,'uint64'); % should be some weird in msec dating from 1970
while ftell(FID) < length_of_file
STUFF0=[STUFF0; fread(FID,1,'uint32')];
STUFF1(u:u+49)=[fread(FID,50,'float32')];
ftell(FID);
STUFF2(u:u+49)=[fread(FID,50,'float32')];
TEMP=[TEMP; STUFF0(end) STUFF1(u:u+49)' STUFF2(u:u+49)'];
u=u+50;
end
% save([PATHNAME 'HIHI' num2str(i) '.txt' ],'-ascii', '-double', '-tabs','TEMP')
disptitle = ['File #' num2str(i) ' Complete'];
disp(disptitle)
fclose(FID);
fclose('all');
pause(5)
FID=[];
end
I've been converting masses of binary files to text files for a while. Using some code I wrote, I initially convert these binary files (just full of numbers of data I look at on a daily basis - they are split up into smaller files as opposed to having one monster file) at a rate of 3 files/min. However, as time goes on, the whole process slows down a LOT -> after 3 hours, i'm going at a rate of 1 file/10 min.
I thought I had a memory leak somewhere or I was not closing the binary files properly as I loaded up new ones, but it doesn't seem to be the case. I threw in some extra commands to try to force close any files that were open, but i still get this inexplicable slowdown in file conversion. I looked at memory usage and nothing seems to be building - I get regular spikes as the .dat file is loaded, processed, and closed.
Here is the basic code with very little modified (FYI, I'm not a programmer at all so excuse any ugliness in my code).
Btw I'm aware that with STUFF0 I'm using a vercat operation which is slow, but at most that array is only a few thousand long ,and 3000x1 shouldn't be creating minutes of slowdown as vercat goes to 3001x1.
Even though I specifically close the file using its FID, I purposely force a close(all) and then just try to set FID=[] to see if blanking it out helps.
I'd appreciate any help, thanks!
STUFF1 = -56*ones(XXXX,1)
STUFF2 = -56*ones(XXXX,1)
for i=1:length(Files)
[FID,MESSAGE]=fopen(char(Files(i))) ; % load up the ith file
status=fseek(FID,0,'eof') ;% place the marker at the origin which is EOF
length_of_file = ftell(FID) - 1 ; % -1 because the last byte index is the EOF which simply marks the end of file
% check for successful load
if status == 0
disp('Binary File loaded Successfully')
elseif status == -1
disp('Failed Loading of Binary File')
return
end
fseek(FID,0,'bof') ;
fileversion=fread(FID,1,'uchar'); % pull out fileversion - shoud always be 1
timestamp=fread(FID,1,'uint64'); % should be some weird in msec dating from 1970
while ftell(FID) < length_of_file
STUFF0=[STUFF0; fread(FID,1,'uint32')];
STUFF1(u:u+49)=[fread(FID,50,'float32')];
ftell(FID);
STUFF2(u:u+49)=[fread(FID,50,'float32')];
TEMP=[TEMP; STUFF0(end) STUFF1(u:u+49)' STUFF2(u:u+49)'];
u=u+50;
end
% save([PATHNAME 'HIHI' num2str(i) '.txt' ],'-ascii', '-double', '-tabs','TEMP')
disptitle = ['File #' num2str(i) ' Complete'];
disp(disptitle)
fclose(FID);
fclose('all');
pause(5)
FID=[];
end