forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Direct access record length problem

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
silicondale



Joined: 15 Mar 2007
Posts: 243
Location: Matlock, Derbyshire, UK

PostPosted: Fri Mar 01, 2024 3:58 pm    Post subject: Direct access record length problem Reply with quote

I have unformatted direct access files with a wide range of different record lengths, but when reading the files these are not known in advance. However, the record length is always given as an INTEGER*4 in the first word of the first record of each file.

I try to open the files with RECL=4 (or something similarly small: the record length is always much greater than that), so that I can then close the file and reopen it with the correct record length - but I just get the execution error 108 "Direct access record length mismatch".
I have tried opening files without specifying RECL but then get error 106 "A valid record length must be specified if access is direct".

Is there any way to open a direct access file without knowing the correct exact record length in advance?
_________________
(Steve Henley)
Back to top
View user's profile Send private message Visit poster's website
wahorger



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Fri Mar 01, 2024 4:23 pm    Post subject: Reply with quote

You will get that error if the total file length is not a multiple of 4 with a RECL=4.

I have the same issue, extracting a "type" from the first "record". I have defined this as an INTEGER*2, and open the file with a record length=2. It always works for the reason below.

All my files are created with INTEGER*2 as the minimum size multiple of any data that is present, including characters. The reasons are "lost in antiquity".

You could open the file with a record length of 1, then extract the first 4 records, byte by byte. That should always work.
Back to top
View user's profile Send private message Visit poster's website
silicondale



Joined: 15 Mar 2007
Posts: 243
Location: Matlock, Derbyshire, UK

PostPosted: Fri Mar 01, 2024 4:31 pm    Post subject: Reply with quote

Many thanks! Tried a little test program and it works. Simple solution, and probably the last suggestion is the best, because i can't guarantee that all files will have even numbered record lengths. They are exported from a database application.
_________________
(Steve Henley)
Back to top
View user's profile Send private message Visit poster's website
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Sat Mar 02, 2024 7:18 am    Post subject: Reply with quote

I have received this message "A valid record length must be specified if access is direct", if the file length is not a multiple of the "length=4"

Rather than first opening as direct access, you could try access=stream and then read the first 4 bytes.

Stream access is very useful for integogating unknown files. You can use this approach to read unformatted sequential records and interogate the Header|data|trailer structure of these files. You can even go to the extent of generating a table of records for record length and start address of each record or start address of the data in each record.

This then becomes a variable length random access file, which can be used as a more flexible database. You can then combine the complex I/O lists that generated the data with the file positioning using pos=.

Combining with /64, this works for large data records.
Back to top
View user's profile Send private message
silicondale



Joined: 15 Mar 2007
Posts: 243
Location: Matlock, Derbyshire, UK

PostPosted: Sat Mar 02, 2024 10:51 am    Post subject: Reply with quote

Wow! Just wow, John! Something I didn't think of, because I have never used access=stream. This seems an extremely flexible option. It's effectively what I am doing in a rather clunky way, because the header information doesn't map to the standard record length but rather is mapped across the first few records of the file, and reassembled as required when reading the file. All the data records following the header are fixed length. However, what you suggest would give an upgrade path that could save a lot of space if I want to include variable-length text fields.

I'm now retired from paid work so (in principle) have plenty of time to experiment with this. Though some people knowing of my retirement have started volunteering me to do other unpaid things. Thus I've been co-opted on to an advisory group for a museum that is being relocated.
_________________
(Steve Henley)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group