#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_saxpy( 
#ifdef __STDMPL__
int, float, plural float *, plural float *
#endif
  );
MPL_SAXPY ( 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;
    float * var2;
    float   dpuVar2;
    plural float  * var3;
    plural float    dpuVar3;
    plural float  * var4;
    plural float    dpuVar4;
      
      /* 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_SAXPY.m : No address to FE argument 1 \n");
            exit(1); 
          }
      }
      
      /* copy in scalar argument from front-end */
      {
        float * ptr;
        var2 = &dpuVar2;
        copyIn( (char*)(fe+2), (char*)(&ptr), sizeof(ptr));
        if (ptr) 
           copyIn( (char*)(ptr),(char*)(var2), sizeof(*var2));
        else 
          {
            fprintf(stderr, "Error in MPL_SAXPY.m : No address to FE argument 2 \n");
            exit(1); 
          }
      }
      
    if (be[3]->onDPU) 
      var3 = (plural float  *)be[3]->addr;
    else  /* Arrays must be on DPU */
      { 
         fprintf(stderr, "Error in MPL_SAXPY.m : argument 3 must be on DPU\n");
         exit(1); 
      }
     
    if (be[4]->onDPU) 
      var4 = (plural float  *)be[4]->addr;
    else  /* Arrays must be on DPU */
      { 
         fprintf(stderr, "Error in MPL_SAXPY.m : argument 4 must be on DPU\n");
         exit(1); 
      }
     
    /* call the mpl function */ 
    mpl_saxpy( *var1, *var2, var3, var4);
  }
