c
c	cread.f 1.4 92/07/01 15:18:11
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 writes the file;
c  other nodes read it.

      include 'fcube.h'

      integer      iam
      integer      newpos(2), newsize(2), offset(2)
      character*13 buf

c  Identify self.

      iam = mynode()

c  Node 0 creates and writes the file.

      if(iam .eq. 0) then

c    Open file and set file size and file pointer to zero.

         open(unit = 12, file = '/cfs/jonsdata',
     1        status = 'unknown', form = 'unformatted')
         call stoe('0 ', offset)
         call esize(13, offset, 0, newsize)
         call eseek(12, offset, 0, newpos)

c    Write and close the file.

         buf = 'Hello, world!'
         call cwrite(12, buf, len(buf))

         write(*, 100) iam, buf
100      format('Node ', i3, ' wrote: ', a13)

         close(unit = 12, file = '/cfs/jonsdata', status = 'keep')

c    Force other nodes to wait until the write completes.

         call gsync()

c  Other nodes open and read the file.

      else

c    Wait for node 0 to create and write the file.

         call gsync()

c    Open file created by node 0.

         open(unit = 12, file = '/cfs/jonsdata',
     1        status = 'old', form = 'unformatted')

c    Read and close the file.

         call cread(12, buf, 13)

         write(*, 130) iam, buf
130      format('Node ', i3, ' read:  ', a13)

         close(unit = 12, file = '/cfs/jonsdata', status = 'keep')

      endif

      end
