c
c	iseof.f 1.5 92/07/01 15:52:25
c
c  Copyright 1991 Intel Corporation, Inc.
c  See the "Copyright" file for complete rights and liability information.
c
c  Requires at least a two-node cube.  Node 0 creates and writes to the file;
c  other nodes read from it.
c
c  Note:  To ensure that the cfs file "/cfs/mydata" exists in a
c         known state, load the program in the file "myfile.f" first.

      include 'fcube.h'

      character*20 sbuf
      character*1  char

c    Open existing file.

      open(unit = 12, file = '/cfs/mydata',
     1     status = 'old', form = 'unformatted')
      call setiomode(12, 0)

c  Identify self.

      iam = mynode()

c  If node 0, then ...

      if(iam .eq. 0) then
         print *,'Starting ...'

c    Write to the file.

            write (sbuf, 100) iam
100         format(i1, ':  Hello, world! ')

            call cwrite(12, sbuf, 17)

            write(*, 200) iam, sbuf
200         format('Node ', i3, ' wrote: ', a17)

c    Force other nodes to wait for the write to complete.

         call gsync()

c  If not node 0, then ...

      else

c    Wait for the write to complete.

         call gsync()

c    Read and display the file.

         do while(iseof(12) .eq. 0)

            call cread(12, char, 1)

            write(*, 300) iam, char
300         format('Node ', i3, ' read:  ', a1)

         end do

      endif

      end
