From 0a2d309bdf3249cedda021ee82cd1fa1b72a1811 Mon Sep 17 00:00:00 2001 From: jean-pierre roux Date: Tue, 3 May 2011 16:24:22 +0000 Subject: [PATCH] add ReadVectorFromFile --- packages/std/src/bbstdReadVectorFromFile.cxx | 91 ++++++++++++++++++++ packages/std/src/bbstdReadVectorFromFile.h | 50 +++++++++++ 2 files changed, 141 insertions(+) create mode 100644 packages/std/src/bbstdReadVectorFromFile.cxx create mode 100644 packages/std/src/bbstdReadVectorFromFile.h diff --git a/packages/std/src/bbstdReadVectorFromFile.cxx b/packages/std/src/bbstdReadVectorFromFile.cxx new file mode 100644 index 0000000..32e5cde --- /dev/null +++ b/packages/std/src/bbstdReadVectorFromFile.cxx @@ -0,0 +1,91 @@ +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +#include "bbstdReadVectorFromFile.h" +#include "bbstdPackage.h" +#include +namespace bbstd +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,ReadVectorFromFile) +BBTK_BLACK_BOX_IMPLEMENTATION(ReadVectorFromFile,bbtk::AtomicBlackBox); +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +void ReadVectorFromFile::Process() +{ + std::vector< std::vector< double > > Data; + std::ifstream openfile( bbGetInputFileName().c_str() ); + std::string Input; + unsigned int LineLength=bbGetInputLineLength(); + int skip = 0; + while ( getline( openfile, Input ) ) + { + std::stringstream Parse; + Parse << Input; + double Value; + std::vector Line; + // -------- une ligne sur 10! + skip++; + if(skip%10 != 0) + continue; + else + skip=1; + //-------- + while ( Parse >> Value ) + Line.push_back( Value ); + if ( Line.size() != LineLength ) + { + std::cout << "Line " << Data.size() + 1 << " expected " << + LineLength << " values, received " << Line.size() << " values, aborting." < >; + +} +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +void ReadVectorFromFile::bbUserFinalizeProcessing() +{ + +// THE FINALIZATION METHOD BODY : +// Here does nothing +// but this is where you should desallocate the internal/output pointers +// if any + //delete Data; + +} +} +// EO namespace bbstd + + diff --git a/packages/std/src/bbstdReadVectorFromFile.h b/packages/std/src/bbstdReadVectorFromFile.h new file mode 100644 index 0000000..65580a3 --- /dev/null +++ b/packages/std/src/bbstdReadVectorFromFile.h @@ -0,0 +1,50 @@ +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +#ifndef __bbstdReadVectorFromFile_h_INCLUDED__ +#define __bbstdReadVectorFromFile_h_INCLUDED__ +#include "bbstd_EXPORT.h" +#include "bbtkAtomicBlackBox.h" +#include "iostream" + + +namespace bbstd +{ + +class bbstd_EXPORT ReadVectorFromFile + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(ReadVectorFromFile,bbtk::AtomicBlackBox); +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== + BBTK_DECLARE_INPUT(FileName,std::string); + BBTK_DECLARE_OUTPUT(Out,std::vector >); + BBTK_DECLARE_INPUT(LineLength,int); + BBTK_PROCESS(Process); + void Process(); +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +}; + +BBTK_BEGIN_DESCRIBE_BLACK_BOX(ReadVectorFromFile,bbtk::AtomicBlackBox); + BBTK_NAME("ReadVectorFromFile"); + BBTK_AUTHOR("jpr"); + BBTK_DESCRIPTION("Read any Vector from a text file"); + BBTK_CATEGORY("read/write"); + BBTK_INPUT(ReadVectorFromFile,FileName,"3D Points file name",std::string,""); + BBTK_INPUT(ReadVectorFromFile,LineLength,"(default 1) - The number of columns of the file",int,""); + BBTK_OUTPUT(ReadVectorFromFile,Out,"vector of data",std::vector< std::vector >,""); + +BBTK_END_DESCRIBE_BLACK_BOX(ReadVectorFromFile); +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== + +} +// EO namespace bbstd + +#endif // __bbstdReadVectorFromFile_h_INCLUDED__ + -- 2.47.1