- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Everyone,
I am trying to use fseek with a file opened as 'form = binary' and I write a large integer(kind=18) at 0, 8, 16, 24 and so on. I can see the hexdump and it shows me the records.
When I skip a location(*) and write at 0 8 24 the compiler doesn seem to protest. The hex dump shows zeroes at that location.
Now when I do a seek to the location i had skipped namely 16 and write the record the records thereafter are deleted. So it seems either I have to write in increasing order or maybe theres a way of "inserting" that record in without
deleting the ones that are infront.
*I know its against the standard but I have not other choice. I had tried to use direct access files but it doesn work for me for quite a few reasons.
Here's the test program that explains what Im trying to do:
1)
$ hexdump -v testhash
0000000 ffff ffff ffff 7fff ffff ffff ffff 7fff
0000010 ffff ffff ffff 7fff ffff ffff ffff 7fff
0000020 ffff ffff ffff 7fff
0000028
2)
$ hexdump -v testhash
0000000 ffff ffff ffff 7fff 0000 0000 0000 0000
0000010 ffff ffff ffff 7fff ffff ffff ffff 7fff
0000020 ffff ffff ffff 7fff
0000028
3)
$ hexdump -v testhash
0000000 ffff ffff ffff 7fff ffff ffff ffff 7fff
0000010
I am trying to use fseek with a file opened as 'form = binary' and I write a large integer(kind=18) at 0, 8, 16, 24 and so on. I can see the hexdump and it shows me the records.
When I skip a location(*) and write at 0 8 24 the compiler doesn seem to protest. The hex dump shows zeroes at that location.
Now when I do a seek to the location i had skipped namely 16 and write the record the records thereafter are deleted. So it seems either I have to write in increasing order or maybe theres a way of "inserting" that record in without
deleting the ones that are infront.
*I know its against the standard but I have not other choice. I had tried to use direct access files but it doesn work for me for quite a few reasons.
Here's the test program that explains what Im trying to do:
The hexdump result
program test_hash_bin
use ifport
INTEGER(SELECTED_INT_KIND(18)) :: i,j,k,iseek, k1,k2
i = 9223372036854775807 ! 9223372036854775808 = 2^63 - 1
open(101,file='testhash',form='binary',status='unknown')
write(*,*)"Enter 1, 2 or 3"
read(*,*)j
select case(j)
case(1)
do j = 0, 4
k = j*8
iseek = fseek (101,k,0)
write(101,iostat=ios)i
ipos=getpos(101)
write(*,*)iseek,ios,ipos
end do
case(2)
do j = 0, 4
k = j*8
if (j.ne.1) then
iseek = fseek (101,k,0)
write(101,iostat=ios)i
ipos=getpos(101)
write(*,*)iseek,ios,ipos
end if
end do
case(3)
do j = 0, 4
k = j*8
if (j.ne.1) then
iseek = fseek (101,k,0)
write(101,iostat=ios)i
ipos=getpos(101)
write(*,*)iseek,ios,ipos
end if
end do
iseek = fseek (101,8,0)
write(101,iostat=ios)i
ipos=getpos(101)
write(*,*)iseek,ios,ipos
end select
close(101)
end program test_hash_bin
1)
$ hexdump -v testhash
0000000 ffff ffff ffff 7fff ffff ffff ffff 7fff
0000010 ffff ffff ffff 7fff ffff ffff ffff 7fff
0000020 ffff ffff ffff 7fff
0000028
2)
$ hexdump -v testhash
0000000 ffff ffff ffff 7fff 0000 0000 0000 0000
0000010 ffff ffff ffff 7fff ffff ffff ffff 7fff
0000020 ffff ffff ffff 7fff
0000028
3)
$ hexdump -v testhash
0000000 ffff ffff ffff 7fff ffff ffff ffff 7fff
0000010
Sorry for the long post.
It would be great if some could tell me if its at all possible to
enter values in this fashion.
Thanks a lot,
Bhupender.
Link Copied
0 Replies

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page