Personal tools
You are here: Home Forum Use Convert DataArrayDouble * to double*

Convert DataArrayDouble * to double*

Up to Use


This forum is DEPRECATED, please create new topics in the new SALOME forum.
For existing topics please transfer them to the new forum.

Convert DataArrayDouble * to double*

Posted by tpedot at December 18. 2012

Hi,

I need to access value of a field I load from a MEDFile but I fail to do it.

 

This method fails :

MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_CELLS,MEDFILE,msName,0,fieldName,iter,order);

ParaMEDMEM::DataArrayDouble *d2=ParaMEDMEM::DataArrayDouble::New();

d2->alloc(f2->getNumberOfValues(),f2->getNumberOfComponents());

d2 = f2->getArray();

double * dble = d2->getPointer();

for (int it ; it<f2->getNumberOfValues(); ++it) {  

  std::cout << dble[it] <<"\n";

   }

d2->decrRef();

f2->decrRef();

 

Do you have any clue on this ? Exemple ?

Thanks in advance.

Re: Convert DataArrayDouble * to double*

Posted by agy at December 18. 2012

 

Hi,

MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_CELLS,MEDFILE,msName,0,fieldName,iter,order);

ParaMEDMEM::DataArrayDouble *d2=f2->getArray();

const double *pt=f2->getConstPointer();

for(int it=0;it!=d2->getNbOfElems();it++)

    std::cout << pt[it] << std::endl;

f2->decrRef();

 

Regards,

Re: Convert DataArrayDouble * to double*

Posted by tpedot at December 18. 2012

Hi,

thank you for your answer.

However, I missed this solution. I don't know which header to include for method getConstPointer() for MEDCouplingFieldDouble.

Can you tell me which

headers to include ?

 

Regards,

Thomas

 

 

Re: Convert DataArrayDouble * to double*

Posted by agy at December 19. 2012

Hi,

You have to include MEDCouplingMemArray.hxx

Regards,

Re: Convert DataArrayDouble * to double*

Posted by tpedot at December 19. 2012

Hi,

I already have MEDCouplingMemArray.hxx included. f2 instance, which is MEDCouplingFieldDouble, doesnot have getConstPointer() methods. Only d2, which is DataArrayDouble, have this methods.

So, I make 'pt' pointer to receive d2 pointer :

const double *pt=d2->getConstPointer();

It compiles but the code raises an errors:

"Unhandled exception at 0x1002b281 in ParaMED_Test.exe: 0xC0000005: Access violation reading location 0x00000050."

Re: Convert DataArrayDouble * to double*

Posted by agy at December 19. 2012

Yes sorry, the code is the following. "f2->getConstPointer()"->"d2->getConstPointer()"

------------------------

MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_CELLS,MEDFILE,msName,0,fieldName,iter,order);

ParaMEDMEM::DataArrayDouble *d2=f2->getArray();

const double *pt=d2->getConstPointer();

for(int it=0;it!=d2->getNbOfElems();it++)

    std::cout << pt[it] << std::endl;

f2->decrRef();

--------------

If this code does not work send me med file (if tiny enough) fieldname, meshname, iteration, order and salome version

Regards

 

Re: Convert DataArrayDouble * to double*

Posted by tpedot at December 19. 2012
The code still doesnot work.
My version of Salome is : SALOME-6.5.0-WIN32-DEV-DEBUG
 
fieldname : TEMPERATURE
meshname : MAILLAGE
iteration : 0
order 0
 
I attached a zip file containing : cpp code, medfile and a snapshot of the medfile.
 
I will try to see if there is warning at compiling time I didnot see.
Thanks
Attachments

Re: Convert DataArrayDouble * to double*

Posted by agy at December 19. 2012

I've tested on Linux with 6.5.0 and all is OK with the given code.

--------------------

//g++ -c -I$MED_ROOT_DIR/include/salome -I$MED3HOME/include -I$HDF5HOME/include main.cxx
//g++ main.o -L$MED_ROOT_DIR/lib/salome -lmedloader -lmedcoupling -linterpkernel
#include "MEDLoader.hxx"
#include "MEDCouplingFieldDouble.hxx"
using namespace ParaMEDMEM;
int main()
{
  MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_CELLS,"medthomas.med","MAILLAGE",0,"TEMPERATURE",0,0);
  ParaMEDMEM::DataArrayDouble *d2=f2->getArray();
  const double *pt=d2->getConstPointer();
  for(int it=0;it!=d2->getNbOfElems();it++)
    std::cout << pt[it] << std::endl;
  f2->decrRef();
  return 0;
}

----------------------

Sorry but I don't have time now to test it under Windows.

Which version of visual C++ are you using ?

 

- try to launch $MED_ROOT_DIR/bin/salome/TestMEDLoader.exe (with environement of SALOME set) -> it should generate a  file "UnitTestsResult" containing (22 OK)

- Check that your project under Visual is Debug and not Release (as you are in Win32 DEBUG).

 

Regards,

Re: Convert DataArrayDouble * to double*

Posted by tpedot at December 20. 2012

Hi,

It works finally with proper compilation options. I was in debug mode but in Visual Studio 10, I built with /MTd options (Multithreaded and static lib) instead of /MDd and other parameters like changing platform from VC10 to VC9 in properties. I didnot noticed that libraries were built with VC9

Thanks for your time !


This forum is DEPRECATED, please create new topics in the new SALOME forum.
For existing topics please transfer them to the new forum.

Powered by Ploneboard
Document Actions