Actual source code: gcreatev.c
petsc-3.7.1 2016-05-15
Report Typos and Errors

      2: #include <petscvec.h>    /*I "petscvec.h" I*/
      3: #include <petsc/private/petscimpl.h>

      5: #include <engine.h>   /* MATLAB include file */
      6: #include <mex.h>      /* MATLAB include file */

     10: PETSC_EXTERN PetscErrorCode  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);

     30:   VecRestoreArray(vec,&array);
     31:   return(0);
     32: }

     36: PETSC_EXTERN PetscErrorCode  VecMatlabEngineGet_Default(PetscObject obj,void *mengine)
     37: {
     39:   PetscInt       n;
     40:   Vec            vec = (Vec)obj;
     41:   PetscScalar    *array;
     42:   mxArray        *mat;

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