/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/
 
#define ARRAYSIZE	12 

Interface sample; 
 
Array Real(48,10) realarray[ARRAYSIZE]; 

Array realarray realmatrix[ARRAYSIZE]; 
 
   Invoke iop 5 
      realmatrix,realmatrix; 
 
End; 

  
main(argc,argv) 
   int argc; 
   char *argv[]; 
{ 
   realmatrix src1,src2,dest1,dest2; 
   Control (sample) inst; 
  
   int i,j; 
   static double a[ARRAYSIZE] = {1.1, 7.0, 2.0, 0.5, 255, 
			  123.45, -1.1, -8.7, -2, 0, 
			  959.3E-17, 24.5E8 }; 
   int c1=ARRAYSIZE,c2=ARRAYSIZE/2+1; 
 
   if (argc != 2) 
      exit(1);    
 
   for (i=0; i<ARRAYSIZE; i++) 
      for (j=0; j<ARRAYSIZE; j++) 
      { 
         src1[i][j] = a[(i+j)%ARRAYSIZE]; 
         src2[i][j] = a[(i+j+1)%ARRAYSIZE]; 
         dest1[i][j] = dest2[i][j] = 1.0; 
      } 
  
/***************** send it out ************************/

   Bind_STUB(inst,argv[1],"w",Asn_1_ber); 
   Give inst 
   { 
      iop(src1, src2 {ARRAYSIZE/2}); 
   } 
   Unbind(inst); 
  
/***************** receive it back ********************/

   Bind_STUB(inst,argv[1],"r",Asn_1_ber); 
 
   Accept inst 
   { 
      On iop(dest1 {c1}, dest2 {c2}) 
       { 
/***************** report results *********************/

         if (c1 != ARRAYSIZE) 
            printf("###c1(%d) should be %d\n",c1,ARRAYSIZE); 
         if (c2 != ARRAYSIZE/2) 
            printf("###c2(%d) should be %d\n",c2,ARRAYSIZE); 
         for (i=0; i<ARRAYSIZE; i++) 
            for (j=0; j<ARRAYSIZE; j++) 
            { 
               if (src1[i][j] != dest1[i][j]) 
                  printf("dest1[%d][%d] (%lf) should be %lf\n",i,j,dest1[i][j],src1[i][j]); 
               if ((i<ARRAYSIZE/2 ? src2[i][j] : 1) != dest2[i][j]) 
                  printf("dest2[%d][%d] (%lf) should be %lf\n",i,j,dest2[i][j],i<ARRAYSIZE/2 ? src2[i][j] : 1); 
               src2[i][j] = a[(i+j)%ARRAYSIZE]; 
            } 
 
      }  
   } 
   Unbind(inst); 
  
   printf("test completed\n");
   return(0); 
} 
  
 
 
