28 namespace inputCSVStream{
43 if (in >> dummy && in >> delim && !in.bad()) { x = dummy;}
59 if (in >> dummy && !in.bad()) { x = dummy;}
71 std::fstream&
ifstreamcsv(std::fstream &in, std::vector< T > &x){
76 if (
ifstreamcsv(in,dummy) && !in.bad()) { x.push_back(dummy); }
98 template <
typename T,
size_t d>
99 std::fstream&
ifstreamcsv(std::fstream &in, std::array< T, d> &x){
104 while ((in.good()) && (i < d-1)) {
122 template <
typename T,
size_t d>
133 template <
typename T>
140 long sizeData = 0, readSizeData;
149 sizeData = long(readSizeData);
152 for(
long count = 0; count<sizeData; ++count){
166 template<
typename T,
size_t d >
169 std::array<T,d> dummy;
173 long sizeData = 0, readSizeData;
179 if(x.intIsValidLocation(location)) x.setDataLocation(
static_cast<MPVLocation>(location));
182 if (readSizeData < std::numeric_limits<long>::max())
183 sizeData = long(readSizeData);
188 for(
long count = 0; count<sizeData; ++count){
243 m_result = std::move(std::unique_ptr<IOData>(
new IODataT<T>(*data)));
252 m_result = std::move(std::unique_ptr<IOData>(
new IODataT<T>(data)));
261 GenericInput::_setInput(T* data){
262 m_input = std::move(std::unique_ptr<IOData>(
new IODataT<T>(*data)));
271 GenericInput::_setInput(T& data){
272 m_input = std::move(std::unique_ptr<IOData>(
new IODataT<T>(data)));
281 GenericInput::_getInput(){
282 return(
static_cast<IODataT<T>*
>(m_input.get())->getData());
291 GenericInput::_setResult(T* data){
292 m_result = std::move(std::unique_ptr<IOData> (
new IODataT<T>(*data)));
301 GenericInput::_setResult(T& data){
302 m_result = std::move(std::unique_ptr<IOData> (
new IODataT<T>(data)));
311 GenericInput::_getResult(){
312 return(
static_cast<IODataT<T>*
>(m_result.get())->getData());
331 file.open(m_dir+
"/"+m_filename, std::fstream::in);
341 (*m_log) <<
"Error GenericInput: file not open --> exit" << std::endl;
342 throw std::runtime_error (
m_name +
" : cannot open " + m_filename +
" requested");
349 if(m_nprocs > 1) sendReadDataToAllProcs(data);
356 return *
static_cast<IODataT<T>*
>(m_result.get())->getData();
367 GenericInput::sendReadDataToAllProcs(T & dataTC){
373 dataBuffer << dataTC;
374 long dataBufferSize = dataBuffer.getSize();
376 for (
int sendRank=1; sendRank<m_nprocs; sendRank++){
377 MPI_Send(&dataBufferSize, 1, MPI_LONG, sendRank, 100, m_communicator);
378 MPI_Send(dataBuffer.data(), dataBuffer.getSize(), MPI_CHAR, sendRank, 110, m_communicator);
384 MPI_Recv(&dataBufferSize, 1, MPI_LONG, 0, 100, m_communicator, MPI_STATUS_IGNORE);
386 MPI_Recv(dataBuffer.data(), dataBuffer.getSize(), MPI_CHAR, 0, 110, m_communicator, MPI_STATUS_IGNORE);
388 dataBuffer >> dataTC;
404 template <
typename T>
405 MimmoPiercedVector< T > *
407 return _getResult< T >() ;
426 GenericInputMPVData::_setResult(MimmoPiercedVector< T > & data){
427 m_result = std::move(std::unique_ptr<IOData> (
new IODataT<MimmoPiercedVector < T > >(data)));
437 MimmoPiercedVector< T >*
438 GenericInputMPVData::_getResult(){
440 MimmoPiercedVector< T > data;
441 MimmoSharedPointer<MimmoObject> refgeo =
getGeometry();
449 long nSize = 0, readNSize;
453 if(m_csv) m_binary =
false;
456 file.open(m_dir+
"/"+m_filename, std::fstream::in);
460 bitpit::genericIO::absorbBINARY(file, length);
461 std::vector<char> namevector(length);
462 for (std::size_t i=0; i<length; i++){
463 bitpit::genericIO::absorbBINARY(file, namevector[i]);
465 name = std::string(name.begin(), name.end());
466 bitpit::genericIO::absorbBINARY(file, n_loc);
467 bitpit::genericIO::absorbBINARY(file, nSize);
469 for(
int i=0; i<nSize; ++i){
470 bitpit::genericIO::absorbBINARY(file,
id);
471 bitpit::genericIO::absorbBINARY(file, data_T);
472 data.insert(
id,data_T);
474 data.setDataLocation(n_loc);
480 bitpit::genericIO::absorbASCII(file, name);
481 bitpit::genericIO::absorbASCII(file, n_loc);
482 bitpit::genericIO::absorbASCII(file, readNSize);
483 if(file.good()) nSize = long(readNSize);
485 for(
long i=0; i<nSize; ++i){
486 bitpit::genericIO::absorbASCII(file,
id);
487 bitpit::genericIO::absorbASCII(file, data_T);
488 data.insert(
id,data_T);
490 data.setDataLocation(n_loc);
495 (*m_log) <<
"file not open --> exit" << std::endl;
496 throw std::runtime_error (
m_name +
" : cannot open " + m_filename +
" requested");
502 if(m_nprocs > 1) sendReadDataToAllProcs(data);
505 if(refgeo ==
nullptr){
508 data.setGeometry(refgeo);
509 MimmoPiercedVector<T> data2 = data.resizeToCoherentDataIds();
513 return static_cast<IODataT<MimmoPiercedVector< T >
>*>(m_result.get())->getData();
525 GenericInputMPVData::sendReadDataToAllProcs(MimmoPiercedVector<T> & dataTC){
531 dataBuffer << dataTC;
532 long dataBufferSize = dataBuffer.getSize();
535 for (
int sendRank=1; sendRank<m_nprocs; sendRank++){
536 MPI_Send(&dataBufferSize, 1, MPI_LONG, sendRank, 100, m_communicator);
537 MPI_Send(dataBuffer.data(), dataBuffer.getSize(), MPI_CHAR, sendRank, 110, m_communicator);
543 MPI_Recv(&dataBufferSize, 1, MPI_LONG, 0, 100, m_communicator, MPI_STATUS_IGNORE);
546 MPI_Recv(dataBuffer.data(), dataBuffer.getSize(), MPI_CHAR, 0, 110, m_communicator, MPI_STATUS_IGNORE);
548 dataBuffer >> dataTC;