C Collection of code snippets by Arne Vajhøj 
C (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
      program isq
      implicit none
      write(*,*) 'Fortran'
      call test_write
      call test_read_sequential
      call test_read_random
      end
c
      subroutine test_write
      implicit none
      open(unit=1, file='for.isq', status='new',
     +     recordtype='fixed', form='unformatted', recl=8,
     +     organization='indexed', access='keyed',
     +     key=(1:4:character))
      call test_write_one('CCCC', 3)
      call test_write_one('BBBB', 2)
      call test_write_one('AAAA', 1)
      close(unit=1)
      end
c
      subroutine test_write_one(id, val)
      implicit none
      character*4 id
      integer*4 val
      structure /datarec/
        character*4 id
        integer*4 val
      end structure
      record /datarec/buf
      buf.id = id
      buf.val = val
      write(unit=1) buf
      end
c
      subroutine test_read_sequential
      implicit none
      structure /datarec/
        character*4 id
        integer*4 val
      end structure
      record /datarec/buf
      open(unit=1, file='for.isq', status='old',
     +     recordtype='fixed', form='unformatted', recl=8,
     +     organization='indexed', access='sequential',
     +     key=(1:4:character))
100   read(unit=1, end=200) buf
      write(*,*) buf.id, ' -> ', buf.val
      goto 100
200   close(unit=1)
      end
c
      subroutine test_read_random
      implicit none
      open(unit=1, file='for.isq', status='old',
     +     recordtype='fixed', form='unformatted', recl=8,
     +     organization='indexed', access='keyed',
     +     key=(1:4:character))
      call test_read_random_one('CCCC')
      call test_read_random_one('BBBB')
      call test_read_random_one('AAAA')
      close(unit=1)
      end
c
      subroutine test_read_random_one(id)
      implicit none
      character*4 id
      structure /datarec/
        character*4 id
        integer*4 val
      end structure
      record /datarec/buf
      read(unit=1, keyeq=id) buf
      write(*,*) buf.id, ' -> ', buf.val
      end
