help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fseek fails, I can not understand why


From: chbe
Subject: fseek fails, I can not understand why
Date: Wed, 15 Sep 2010 05:20:17 -0700 (PDT)

I have the following function which I use to read some large/huge binary
files storing image data I need to analyze.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Reads an image from a BLOB created by MxScannerTest
%
%Parameters in:
%          path: path to file
% pixelsPerLine: number of pixels per line
%         lines: number of lines to read, default whole file
%     firstLine: number of the first line to read
%   
%Parameters out:
%          data: lines x pixelsPerLine array
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function data = ReadBinaryData(path, pixelsPerLine, lines = -1, firstLine =
0)
        fileInfo = lstat( path );
        [ fileId msg ]= fopen( path, "r" );
        
        if( fileId == -1 )
                error( [ 'Failed to find file: ' path ' msg: ' msg ] );
        end
        
        if lines == -1
                lines = fileInfo.size / ( 2 * pixelsPerLine );
        end
        
        pos = firstLine * 2 * pixelsPerLine;

        
        if -1 == fseek(fileId,pos,'bof')
                fclose( fileId );
                error( [ 'Failed to seek to: ' int2str( pos ) " in file " path 
] );
        end

        
        [ data, count ] = fread( fileId, [pixelsPerLine, lines], 
'uint16=>double'
);
        fclose( fileId );
        
        if count != pixelsPerLine * lines
                error( 'Failed to read enough lines' )
        end
        
        data = data';

---
The call to fseek fails sometimes, and I have not been able to find any
reason or pattern.

I can run a script, containing two or more consecutive calls to
ReadBinaryData, to different files in different folders, the first call
succeeding the second filing. I can take the file for which it fails and
copy it to the folder where it succeeds, and it keep failing. I rename the
file so that i has the same name as the file for which it was succeeding,
and it continues to fail. I change the target position in the file, it
continues to fail. 

One example of a failure gives me this data in my error message:
error: Failed to seek to: 191488000 in file
F:\rawdata\domsjo\100907_empty_belt\100907_1_1.bin

the seek position is well inside the file as shown by

-------
C:\Documents and Settings\chbe>dir
F:\rawdata\domsjo\100907_empty_belt\100907_1_1.bin
 Volume in drive F is Iomega HDD
 Volume Serial Number is 7431-B6D7

 Directory of F:\rawdata\domsjo\100907_empty_belt

2010-09-07  10:30     3 086 336 000 100907_1_1.bin
               1 File(s)  3 086 336 000 bytes
               0 Dir(s)  689 796 939 776 bytes free
-------
The file is not used by any other process

C:\Documents and Settings\chbe>handle 100907_1_1.bin

Handle v3.42
Copyright (C) 1997-2008 Mark Russinovich
Sysinternals - www.sysinternals.com

No matching handles found.

C:\Documents and Settings\chbe>

-------

I am running octave 3.2.3
> version
ans = 3.2.3

On a windows XP SP 3 machine, 32 bit


Does anyone have any suggestions, either if my function is doing something
wrong, or about any way to get more information about what the actual reason
for the failure is?


-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/fseek-fails-I-can-not-understand-why-tp2540425p2540425.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]