#include <mpl.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int * addr;		/* base address of array */
	int   rank;		/* rank of array */
        int   onDPU;		/* if base address is FE or BE */
	int   extents[7];	/* extents of the array */
} DopeVector;

extern void mpl_isamax( 
#ifdef __STDMPL__
int, plural float *, int *
#endif
  );
MPL_ISAMAX ( fe, be )
    int * fe[];        /*  FE(vax) address of FE(vax) arguments */
    DopeVector * be[]; /* a BE(acu) address of BE(acu) dopevectors */
  {
    int * var1;
    int   dpuVar1;
    plural float  * var2;
    plural float    dpuVar2;
    int  * var3;
    int    dpuVar3;
      
      /* copy in scalar argument from front-end */
      {
        int * ptr;
        var1 = &dpuVar1;
        copyIn( (char*)(fe+1), (char*)(&ptr), sizeof(ptr));
        if (ptr) 
           copyIn( (char*)(ptr),(char*)(var1), sizeof(*var1));
        else 
          {
            fprintf(stderr, "Error in MPL_ISAMAX.m : No address to FE argument 1 \n");
            exit(1); 
          }
      }
      
    if (be[2]->onDPU) 
      var2 = (plural float  *)be[2]->addr;
    else  /* Arrays must be on DPU */
      { 
         fprintf(stderr, "Error in MPL_ISAMAX.m : argument 2 must be on DPU\n");
         exit(1); 
      }
     
      /* copy in scalar argument from front-end */
      {
        int  * ptr;
        var3 = &dpuVar3;
        copyIn( (char*)(fe+3), (char*)(&ptr), sizeof(ptr));
        if (ptr) 
           copyIn( (char*)(ptr),(char*)(var3), sizeof(*var3));
        else 
          {
            fprintf(stderr, "Error in MPL_ISAMAX.m : No address to FE argument 3 \n");
            exit(1); 
          }
      }
      
    /* call the mpl function */ 
    mpl_isamax( *var1, var2, var3);
      
      { /* copy scalar call-by-reference argument back to FE */
        int  * ptr;
        copyIn((char*) (fe+3),(char*)(&ptr), sizeof(ptr));
        copyOut((char*)(var3),(char*)(ptr), sizeof(*var3));
      }
  }
