Reader.h 4.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/


/** \file Reader.h */

#ifndef AMDIS_READER_H
#define AMDIS_READER_H

#include <cstring>
28
29
#include <boost/filesystem.hpp>

30
31
32
33
34
#include "DOFVector.h"
#include "SystemVector.h"

#include "ArhReader.h"
#include "Arh2Reader.h"
Siqi Ling's avatar
Siqi Ling committed
35
#include "Arh3Reader.h"
36
37
#include "MacroReader.h"
#include "ValueReader.h"
38
#include "XYZReader.h"
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

#ifdef HAVE_PNG
#include "PngReader.h"
#endif

#ifdef HAVE_EXTENSIONS
#include "VtkReader.h"
#endif

#include "detail/ReaderWriter.h"


namespace AMDiS 
{
  namespace io
  {
    
    /** \ingroup Input
     * \brief reader interface that selects a reader depending on the file extension of the filename.
     * 
     * @param filename Filename of the input file, used to extract extension.
     * @param container One of DOFVector&, std::vector<DOFVector*>, 
     * 			SystemVector&, Mesh&.
     **/
    template<typename Container> 
    void readFile(std::string filename,
		  Container &container)
    {
67
68
69
      using boost::filesystem::path;
      std::string ext = path(filename).extension().string(); 

70
71
72
73
74
75
76
77
78
      Mesh* mesh = detail::getMesh(container);
      if (ext == ".1d" || ext == ".2d" || ext == ".3d")
      {
	std::string periodicFilename = "";
	int check = 1;
	Parameters::get(mesh->getName() + "->periodic file", periodicFilename);
	Parameters::get(mesh->getName() + "->check", check);
	MacroReader::readMacro(filename, mesh, periodicFilename, check);
      }
79
      else if (ext == ".arh" || ext == ".parh")
80
      {
81
        if (Arh3Reader::isReadable(filename))
82
	  Arh3Reader::readFile(filename, container);
83
84
        else if (Arh2Reader::isReadable(filename))
          Arh2Reader::readFile(filename, container);
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
	else
	  ArhReader::readFile(filename, container);
      }
      else if (ext == ".dat")
      {
	bool preserveMacroFileInfo = false;
	Parameters::get(mesh->getName() + "->preserve macroFileInfo", 
			preserveMacroFileInfo);
	TEST_EXIT(mesh->getMacroFileInfo() != NULL && preserveMacroFileInfo)
	  ("Yout have to set the flag 'mesh_name->preserve macroFileInfo' "
	    "to 'true' (%d), in order to read .dat-files",
	    int(preserveMacroFileInfo));    
	  
	ValueReader::readValue(filename, mesh, container, 
				mesh->getMacroFileInfo());
      }  
#ifdef HAVE_PNG
      else if (ext == ".png")
      {
	PngReader::readFile(filename, container);
      }
#endif 

#ifdef HAVE_EXTENSIONS
      else if (ext == ".vtu")
      {
	VtkReader::readFile(filename, container);
      }
#endif
      else
      {
	ERROR_EXIT("File-extensions %s can not be assigned to a reader!\n", ext.c_str());
      }
    }
    
    
    /** \ingroup Output
     * \brief Wrapper for pointers to container types
     **/
    template<typename Container> 
    void readFile(std::string filename,
		  Container *container)
    {
      readFile(filename, *container);
    }
    
    
    /** \ingroup Output
     * \brief specialization for read meshes
     **/
    inline
    void readFile(std::string filename,
		  Mesh *mesh)
    {
139
140
141
      using boost::filesystem::path;
      std::string ext = path(filename).extension().string();

142
143
144
145
146
147
148
149
      if (ext == ".1d" || ext == ".2d" || ext == ".3d")
      {
	std::string periodicFilename = "";
	int check = 1;
	Parameters::get(mesh->getName() + "->periodic file", periodicFilename);
	Parameters::get(mesh->getName() + "->check", check);
	MacroReader::readMacro(filename, mesh, periodicFilename, check);
      }
150
      else if (ext == ".arh" || ext == ".parh")
151
      {
152
        if (Arh3Reader::isReadable(filename))
Siqi Ling's avatar
Siqi Ling committed
153
	  Arh3Reader::readFile(filename, mesh);
154
155
        else if (Arh2Reader::isReadable(filename))
          Arh2Reader::readFile(filename, mesh);
156
157
158
159
160
161
162
163
164
165
166
167
	else
	  ArhReader::readFile(filename, mesh);
      }
      else
      {
	ERROR_EXIT("File-extensions %s can not be assigned to a reader!\n", ext.c_str());
      }
    }
  } // end namespace io
} // end namespace AMDiS

#endif // AMDIS_READER_H