help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How unpack a charNDArray using pvm library?


From: Riccardo Corradini
Subject: How unpack a charNDArray using pvm library?
Date: Wed, 28 Feb 2007 11:55:01 +0100 (CET)

Hi all,
I successfully compiled and oct file  to pack infos to a Parallel Virtual machine about an octave charNDArray .. this is the code


#include <octave/oct.h>
#include <pvm3.h>


DEFUN_DLD(pvm_pkcharMAT,args,, "This function emulates the C function pvm_pkbyte of pvm3 library, but packs any char matrixes with any dimensions \n")
{



  octave_value_list retval;
  double nargin = args.length ();

  if (nargin != 2)
    {
      error ("expecting 2 input arguments");
      return retval;
    }

  const charNDArray tarray = args(0).char_array_value();
  int nitem = tarray.capacity();
  char *p  = const_cast<char*>( tarray.data() );
  int stride = args(1).int_value();
  if (error_state)
    {
      error ("expecting second argument to be an integer");
      return retval;
    }


     int info1 = pvm_pkint (&nitem, 1, stride);
    int info2 = pvm_pkbyte (p, nitem, stride);

 
  retval(0) = static_cast<int>(info1);
  retval(1) = static_cast<int>(info2);
   
  return octave_value_list(retval);
}

I would like to use the same strategy to unpack the CharNDArray using the pieces of information in contents property ..

This is the wrong code, because I don't have the octave_value as argument of the unpack functions

#include <octave/oct.h>

#include <pvm3.h>



DEFUN_DLD(pvm_upkcharMAT,args,, "This function emulates the C function pvm_upkdouble of pvm3 library to unpack a char ND array \n")
{



  octave_value_list retval;
  int nargin = args.length ();

  if (nargin != 2)
    {
      error ("expecting 2 input arguments");
      return retval;
    }

  int stride = args(1).int_value();
  if (error_state)
    {
      error ("expecting second argument to be an int");
      return retval;
    }
  if (args(0).is_char_nd_array() != 0)
    {
      error ("expecting first argument to be a char");
      return retval;
    }
 int   n  = args(0).ndims();       
  dim_vector dv = args(0).dims();

// Could I use an octave_local_buffer macro if so .. how?
  charNDArray   oar (dv);
  if( (n != oar.capacity()) )
    {
      error ("errors with dims");
      return retval;
    }

  char *preal   = const_cast<char*>( oar.data() );



    int info1 = pvm_upkbyte (preal, n, stride);

  retval(0) = static_cast<int>(info1);
  return octave_value_list(retval);
}


Are there any hints ...?
Thanks a  lot for all your help
Cheers
Riccardo


L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail
reply via email to

[Prev in Thread] Current Thread [Next in Thread]