c
c	ctoh2.f 1.4 92/07/01 15:18:39
c
c  Copyright 1991 Intel Corporation, Inc.
c  See the "Copyright" file for complete rights and liability information.
c
c  Part 2:
c    Runs on the cube. Loaded by the host program in the "ctoh1.f" file.
c    Receives data from the host, divides it by 2,
c    and returns the result to the host.
c    Can run on a multi-node cube, but only node 0 does anything.

      program ctoh2

      include 'fcube.h'

      double precision dpvar
      real             rvar
      integer*4        i4var
      integer*2        i2var
      integer          hostid, iam

c  Identify self.

      iam = mynode()

c  If node 0, then ...

      if(iam .eq. 0) then

c    Receive data from host.

         call crecv(10, dpvar, 16)
         call crecv(11, rvar, 8)
         call crecv(12, i4var, 4)
         call crecv(13, i2var, 2)

         print *, 'Data received from host:'
         write(*, 100) dpvar, rvar, i4var, i2var
100      format('dpvar = ', d40.4, /,
     1          'rvar  = ', f40.4, /,
     2          'i4var = ', i40, /,
     3          'i2var = ', i40, /)

c    Divide data by 2.

         dpvar = dpvar/2.0
         rvar  = rvar/2.0
         i4var = i4var/2
         i2var = i2var/2

c    Identify host.

         hostid = myhost()

c    Send result to the host.

         call csend(20, dpvar, 16, hostid, 100)
         call csend(21, rvar, 8, hostid, 100)
         call csend(22, i4var, 4, hostid, 100)
         call csend(23, i2var, 2, hostid, 100)

         print *, 'Data sent to host:'
         write(*, 100) dpvar, rvar, i4var, i2var

      endif

      end
