Convert DataArrayDouble * to double*
This forum is DEPRECATED, please create new topics in the new SALOME forum.
For existing topics please transfer them to the new forum.
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:ataArrayDouble *d2=ParaMEDMEM:ataArrayDouble::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.
Hi,
MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_CELLS,MEDFILE,msName,0,fieldName,iter,order);
ParaMEDMEM:ataArrayDouble *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,
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 whichheaders to include ?
Regards,
Thomas
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."
Yes sorry, the code is the following. "f2->getConstPointer()"->"d2->getConstPointer()"
------------------------
MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_CELLS,MEDFILE,msName,0,fieldName,iter,order);
ParaMEDMEM:ataArrayDouble *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
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:ataArrayDouble *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,
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.