Discussion:
Reading data from disk using wxFFile
Tim Burgess
2014-07-26 16:20:24 UTC
Permalink
Hi,

I'm reading a series of records in from a data file using wxFFile. The file
contains 100 records and opens for reading without error, but I only get the
first few records ( 7) before the read operation fails to read the correct
number of bytes:

FileRecords myRecords[ 100];

for (int nRecordNumber = 0; nRecordNumber < 100; nRecordNumber++)
{
size_t nResult = myFile.Read( myRecords[ nRecordNumber],
RECORD_LENGTH);

if (nResult != RECORD_LENGTH)
{
// ... I handle the error here. The record length (EWI_PATCH_LENGTH) is 206
bytes, but I only seem to read 99 for the 8th record
}

I have another version of the application which reads the same files and
successfully brings in all 100 records - this was written using QT and my
application is a WX port of the same code to solve some accessibility
problems. The QT equivalent functions for the open, read and seek operations
are trivial to port, so I'm pretty sure I'm getting that right. The data
file I'm reading is over 22k long and inspecting it in an editor shows more
records beyond the ones I successfully read in. How can I gather more
information to help me figure out why it's failing? Any and all ideas most
welcome.

Best wishes.
Tim Burgess
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Tim Burgess
2014-07-27 20:33:49 UTC
Permalink
Hi,

More information to add to this - attempting to read the 7th record tells me
that I've encountered eof(), which is untrue. I modified my code to not
assume that the read pointer is moved by each read operation - I now
calculate the offset for each record, seek to it then attempt to read. The
problem happens at position 2340 with a record length of 206 (I do an
initial seek to get beyond some header bytes), but the file itself is 22k
long, so the eof() returning true would seem to be erroneous.

Best wishes.
Tim Burgess

-----Original Message-----
From: wx-***@googlegroups.com [mailto:wx-***@googlegroups.com] On Behalf
Of Tim Burgess
Sent: 26 July 2014 17:20
To: wx-***@googlegroups.com
Subject: Reading data from disk using wxFFile

Hi,

I'm reading a series of records in from a data file using wxFFile. The file
contains 100 records and opens for reading without error, but I only get the
first few records ( 7) before the read operation fails to read the correct
number of bytes:

FileRecords myRecords[ 100];

for (int nRecordNumber = 0; nRecordNumber < 100; nRecordNumber++)
{
size_t nResult = myFile.Read( myRecords[ nRecordNumber],
RECORD_LENGTH);

if (nResult != RECORD_LENGTH)
{
// ... I handle the error here. The record length (EWI_PATCH_LENGTH) is 206
bytes, but I only seem to read 99 for the 8th record }

I have another version of the application which reads the same files and
successfully brings in all 100 records - this was written using QT and my
application is a WX port of the same code to solve some accessibility
problems. The QT equivalent functions for the open, read and seek operations
are trivial to port, so I'm pretty sure I'm getting that right. The data
file I'm reading is over 22k long and inspecting it in an editor shows more
records beyond the ones I successfully read in. How can I gather more
information to help me figure out why it's failing? Any and all ideas most
welcome.

Best wishes.
Tim Burgess


--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Eric Jensen
2014-07-27 21:08:52 UTC
Permalink
Hello Tim,

Sunday, July 27, 2014, 10:33:49 PM, you wrote:

TB> Hi,

TB> More information to add to this - attempting to read the 7th record tells me
TB> that I've encountered eof(), which is untrue. I modified my code to not
TB> assume that the read pointer is moved by each read operation - I now
TB> calculate the offset for each record, seek to it then attempt to read. The
TB> problem happens at position 2340 with a record length of 206 (I do an
TB> initial seek to get beyond some header bytes), but the file itself is 22k
TB> long, so the eof() returning true would seem to be erroneous.

TB> Best wishes.
TB> Tim Burgess

TB> -----Original Message-----
TB> From: wx-***@googlegroups.com
TB> [mailto:wx-***@googlegroups.com] On Behalf
TB> Of Tim Burgess
TB> Sent: 26 July 2014 17:20
TB> To: wx-***@googlegroups.com
TB> Subject: Reading data from disk using wxFFile

TB> Hi,

TB> I'm reading a series of records in from a data file using wxFFile. The file
TB> contains 100 records and opens for reading without error, but I only get the
TB> first few records ( 7) before the read operation fails to read the correct
TB> number of bytes:

TB> FileRecords myRecords[ 100];

TB> for (int nRecordNumber = 0; nRecordNumber < 100; nRecordNumber++)
TB> {
TB> size_t nResult = myFile.Read( myRecords[ nRecordNumber],
TB> RECORD_LENGTH);

TB> if (nResult != RECORD_LENGTH)
TB> {
TB> // ... I handle the error here. The record length (EWI_PATCH_LENGTH) is 206
TB> bytes, but I only seem to read 99 for the 8th record }

TB> I have another version of the application which reads the same files and
TB> successfully brings in all 100 records - this was written using QT and my
TB> application is a WX port of the same code to solve some accessibility
TB> problems. The QT equivalent functions for the open, read and seek operations
TB> are trivial to port, so I'm pretty sure I'm getting that right. The data
TB> file I'm reading is over 22k long and inspecting it in an editor shows more
TB> records beyond the ones I successfully read in. How can I gather more
TB> information to help me figure out why it's failing? Any and all ideas most
TB> welcome.

I can't see anything wrong at first sight, but i think it's safe to
assume that a fundamental and simple method like Eof() is not bugged.

What exactly is the "FileRecords" class? The following line would only
make sense if the array contains pointers:

size_t nResult = myFile.Read( myRecords[ nRecordNumber], RECORD_LENGTH);

Try reading the fileoffset after each read operation. Maybe this gives
a hint about what's going on.

Regards,
Eric
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Steve Barnes
2014-07-28 05:33:36 UTC
Permalink
Post by Tim Burgess
Hi,
I'm reading a series of records in from a data file using wxFFile. The file
contains 100 records and opens for reading without error, but I only get the
first few records ( 7) before the read operation fails to read the correct
FileRecords myRecords[ 100];
for (int nRecordNumber = 0; nRecordNumber < 100; nRecordNumber++)
{
size_t nResult = myFile.Read( myRecords[ nRecordNumber],
RECORD_LENGTH);
if (nResult != RECORD_LENGTH)
{
// ... I handle the error here. The record length (EWI_PATCH_LENGTH) is 206
bytes, but I only seem to read 99 for the 8th record
}
I have another version of the application which reads the same files and
successfully brings in all 100 records - this was written using QT and my
application is a WX port of the same code to solve some accessibility
problems. The QT equivalent functions for the open, read and seek operations
are trivial to port, so I'm pretty sure I'm getting that right. The data
file I'm reading is over 22k long and inspecting it in an editor shows more
records beyond the ones I successfully read in. How can I gather more
information to help me figure out why it's failing? Any and all ideas most
welcome.
Best wishes.
Tim Burgess
Tim,

It might be a daft question but are you opening the file in text mode,
(the default for wxFFile), of binary mode “rb” if the file contains
non-text elements then it is possible that you are encountering an ASCII
EOF (Ctrl-Z/0x1A) at that record which will be taken as a character with
a value of 0x1A in binary file mode but will end the file if opened in
text mode.

Gadget/Steve

​
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Tim Burgess
2014-07-28 13:14:01 UTC
Permalink
Steve,



Turned out not to be a daft question, just a daft programmer. “rb” did the trick, though:



OutFile.Open(myTargetPath, "wb")



Tells me that it can’t write to the file (I’ve checkd that the path is OK) – do I need to create the file first (I’d assumed that it would get created at the first write operation).



I know that these are stupid questions but I’ve never actually had to use c++ random access files before, as I’ve always dealt with streams, Boost serialisation and external databases previously.



Best wishes.

Tim Burgess



From: wx-***@googlegroups.com [mailto:wx-***@googlegroups.com] On Behalf Of Steve Barnes
Sent: 28 July 2014 06:34
To: wx-***@googlegroups.com
Subject: Re: Reading data from disk using wxFFile



On 26/07/14 17:20, Tim Burgess wrote:

Hi,

I'm reading a series of records in from a data file using wxFFile. The file
contains 100 records and opens for reading without error, but I only get the
first few records ( 7) before the read operation fails to read the correct
number of bytes:

FileRecords myRecords[ 100];

for (int nRecordNumber = 0; nRecordNumber < 100; nRecordNumber++)
{
size_t nResult = myFile.Read( myRecords[ nRecordNumber],
RECORD_LENGTH);

if (nResult != RECORD_LENGTH)
{
// ... I handle the error here. The record length (EWI_PATCH_LENGTH) is 206
bytes, but I only seem to read 99 for the 8th record
}

I have another version of the application which reads the same files and
successfully brings in all 100 records - this was written using QT and my
application is a WX port of the same code to solve some accessibility
problems. The QT equivalent functions for the open, read and seek operations
are trivial to port, so I'm pretty sure I'm getting that right. The data
file I'm reading is over 22k long and inspecting it in an editor shows more
records beyond the ones I successfully read in. How can I gather more
information to help me figure out why it's failing? Any and all ideas most
welcome.

Best wishes.
Tim Burgess



Tim,

It might be a daft question but are you opening the file in text mode, (the default for wxFFile), of binary mode “rb” if the file contains non-text elements then it is possible that you are encountering an ASCII EOF (Ctrl-Z/0x1A) at that record which will be taken as a character with a value of 0x1A in binary file mode but will end the file if opened in text mode.

Gadget/Steve

​
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Tim Burgess
2014-07-28 15:34:13 UTC
Permalink
Please ignore this last – now sorted.





Best wishes.

Tim Burgess



From: wx-***@googlegroups.com [mailto:wx-***@googlegroups.com] On Behalf Of Tim Burgess
Sent: 28 July 2014 14:14
To: wx-***@googlegroups.com
Subject: RE: Reading data from disk using wxFFile



Steve,



Turned out not to be a daft question, just a daft programmer. “rb” did the trick, though:



OutFile.Open(myTargetPath, "wb")



Tells me that it can’t write to the file (I’ve checkd that the path is OK) – do I need to create the file first (I’d assumed that it would get created at the first write operation).



I know that these are stupid questions but I’ve never actually had to use c++ random access files before, as I’ve always dealt with streams, Boost serialisation and external databases previously.



Best wishes.

Tim Burgess



From: wx-***@googlegroups.com [mailto:wx-***@googlegroups.com] On Behalf Of Steve Barnes
Sent: 28 July 2014 06:34
To: wx-***@googlegroups.com
Subject: Re: Reading data from disk using wxFFile



On 26/07/14 17:20, Tim Burgess wrote:

Hi,

I'm reading a series of records in from a data file using wxFFile. The file
contains 100 records and opens for reading without error, but I only get the
first few records ( 7) before the read operation fails to read the correct
number of bytes:

FileRecords myRecords[ 100];

for (int nRecordNumber = 0; nRecordNumber < 100; nRecordNumber++)
{
size_t nResult = myFile.Read( myRecords[ nRecordNumber],
RECORD_LENGTH);

if (nResult != RECORD_LENGTH)
{
// ... I handle the error here. The record length (EWI_PATCH_LENGTH) is 206
bytes, but I only seem to read 99 for the 8th record
}

I have another version of the application which reads the same files and
successfully brings in all 100 records - this was written using QT and my
application is a WX port of the same code to solve some accessibility
problems. The QT equivalent functions for the open, read and seek operations
are trivial to port, so I'm pretty sure I'm getting that right. The data
file I'm reading is over 22k long and inspecting it in an editor shows more
records beyond the ones I successfully read in. How can I gather more
information to help me figure out why it's failing? Any and all ideas most
welcome.

Best wishes.
Tim Burgess



Tim,

It might be a daft question but are you opening the file in text mode, (the default for wxFFile), of binary mode “rb” if the file contains non-text elements then it is possible that you are encountering an ASCII EOF (Ctrl-Z/0x1A) at that record which will be taken as a character with a value of 0x1A in binary file mode but will end the file if opened in text mode.

Gadget/Steve

​
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Steve Barnes
2014-07-28 18:43:32 UTC
Permalink
Post by Tim Burgess
Please ignore this last – now sorted.
Best wishes.
Tim Burgess
Glad it is sorted Tim.
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Loading...