Actual source code: gcreatev.c

      1: #define PETSCVEC_DLL

      3: #include "petscvec.h"    /*I "petscvec.h" I*/

      5: #include "engine.h"   /* Matlab include file */
      6: #include "mex.h"      /* Matlab include file */
     10: PetscErrorCode PETSCVEC_DLLEXPORT VecMatlabEnginePut_Default(PetscObject obj,void *mengine)
     11: {
     13:   PetscInt       n;
     14:   Vec            vec = (Vec)obj;
     15:   PetscScalar    *array;
     16:   mxArray        *mat;

     19:   VecGetArray(vec,&array);
     20:   VecGetLocalSize(vec,&n);
     21: #if !defined(PETSC_USE_COMPLEX)
     22:   mat  = mxCreateDoubleMatrix(n,1,mxREAL);
     23: #else
     24:   mat  = mxCreateDoubleMatrix(n,1,mxCOMPLEX);
     25: #endif
     26:   PetscMemcpy(mxGetPr(mat),array,n*sizeof(PetscScalar));
     27:   PetscObjectName(obj);
     28:   engPutVariable((Engine *)mengine,obj->name,mat);
     29:
     30:   VecRestoreArray(vec,&array);
     31:   return(0);
     32: }

     38: PetscErrorCode PETSCVEC_DLLEXPORT VecMatlabEngineGet_Default(PetscObject obj,void *mengine)
     39: {
     41:   PetscInt       n;
     42:   Vec            vec = (Vec)obj;
     43:   PetscScalar    *array;
     44:   mxArray        *mat;

     47:   VecGetArray(vec,&array);
     48:   VecGetLocalSize(vec,&n);
     49:   mat  = engGetVariable((Engine *)mengine,obj->name);
     50:   if (!mat) SETERRQ1(PETSC_ERR_LIB,"Unable to get object %s from matlab",obj->name);
     51:   PetscMemcpy(array,mxGetPr(mat),n*sizeof(PetscScalar));
     52:   VecRestoreArray(vec,&array);
     53:   return(0);
     54: }