www.cemf.ir
fileSeries.cpp
Go to the documentation of this file.
1 #include "fileSeries.hpp"
2 #include "oFstream.hpp"
3 #include "streams.hpp"
4 
6 {
7  auto& fList = timeFiles_[baseName];
8  word fileName = baseName + ".vtk.series";
9  oFstream os(destDir_+fileName);
10 
11  REPORT(1)<<"Writing to "<<os.name()<<END_REPORT;
12 
13  os<<"{\n";
14  os<<" \"file-series-version\" : \"1.0\",\n";
15  os<<" \"files\" : [\n";
16  const auto lastItem = std::prev(fList.end());
17  for(auto iter = fList.begin(); iter != fList.end(); ++iter)
18  {
19  os<<" {\"name\" : \"";
20  os<< iter->second;
21  os<<"\", \"time\" :";
22  os<<iter->first;
23  if(iter == lastItem)
24  os<<"}\n";
25  else
26  os<<"},\n";
27  }
28  os<<" ]\n";
29  os<<"}\n";
30 
31 }
32 
34  : destDir_(dest)
35 {
36 
37 
38 }
39 
41 {
42  REPORT(0)<<"Writing time series files..."<<END_REPORT;
43  for(const auto& fSeries:timeFiles_)
44  {
45  writeOneBaseName(fSeries.first);
46  }
47 }
48 
49 bool pFlow::PFtoVTK::fileSeries::addTimeFile(const word& baseName, real time, const word &fileName)
50 {
51  fileSystem fs(fileName);
52  word relFileName = fs.relative(destDir_).wordPath();
53 
54  if( auto [iter, found]=timeFiles_.findIf(baseName); found )
55  {
56  return iter->second.insertIf(time, relFileName);
57  }
58  else
59  {
60  TimeFileType newList;
61  newList.insertIf(time, relFileName);
62  return timeFiles_.insertIf(baseName, newList);
63  }
64 
65 }
66 
67 bool pFlow::PFtoVTK::fileSeries::addTimeFile(const wordList &baseNames, real time, const wordList &fileNames)
68 {
69  if(baseNames.size()!= fileNames.size() )
70  {
71  fatalErrorInFunction<<"sizes of base names and file names are not equal\n";
72  return false;
73  }
74 
75  for(size_t i=0; i<baseNames.size(); i++)
76  {
77  if(!addTimeFile(baseNames[i], time, fileNames[i]))
78  {
79  fatalErrorInFunction<<"Error in adding multiple time files\n";
80  return false;
81  }
82  }
83 
84  return true;
85 }
pFlow::List< word >
pFlow::PFtoVTK::fileSeries::writeOneBaseName
void writeOneBaseName(const word &baseName)
Definition: fileSeries.cpp:5
pFlow::real
float real
Definition: builtinTypes.hpp:45
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::PFtoVTK::fileSeries::destDir_
fileSystem destDir_
Definition: fileSeries.hpp:22
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
fileSeries.hpp
oFstream.hpp
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
pFlow::baseName
word baseName(const word &w, char sep='.')
Find the base in a group separated by "." and return it.
Definition: bTypesFunctions.cpp:185
pFlow::Ostream::name
virtual const word & name() const
Return the name of the stream.
Definition: Ostream.hpp:71
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::Map::insertIf
bool insertIf(const keyType &k, const mappedType &v)
Definition: MapI.hpp:23
pFlow::PFtoVTK::fileSeries::fileSeries
fileSeries(const fileSystem dest)
Definition: fileSeries.cpp:33
pFlow::PFtoVTK::fileSeries::timeFiles_
Map< word, TimeFileType > timeFiles_
Definition: fileSeries.hpp:20
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
streams.hpp
pFlow::oFstream
Output file stream to send binary or ascii data to a file.
Definition: oFstream.hpp:38
pFlow::PFtoVTK::fileSeries::~fileSeries
~fileSeries()
Definition: fileSeries.cpp:40
pFlow::List::size
size_t size() const
Definition: ListI.hpp:82
pFlow::PFtoVTK::fileSeries::addTimeFile
bool addTimeFile(const word &baseName, real time, const word &fileName)
Definition: fileSeries.cpp:49
pFlow::Map
Definition: Map.hpp:36
pFlow::fileSystem::relative
fileSystem relative(const fileSystem &base) const
relative path of this this with respect to base
Definition: fileSystem.cpp:170
pFlow::fileSystem::wordPath
word wordPath() const
Path in word type.
Definition: fileSystem.hpp:160