VtkWriter.cc 1.88 KB
Newer Older
1
#include <stdio.h>
2
3
#include <string>
#include <fstream>
Peter Gottschling's avatar
Peter Gottschling committed
4
#include <cmath>
5
6
7
8
9
10
11
12
13

#include "VtkWriter.h"
#include "DataCollector.h"
#include "DOFVector.h"
#include "SurfaceRegion_ED.h"
#include "ElementRegion_ED.h"

namespace AMDiS { 

14
15
  int VtkWriter::writeFile(const char *name)
  {
16
#ifdef HAVE_BOOST
17
    
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    boost::iostreams::filtering_ostream file;
    switch (compress) {
    case GZIP:
      file.push(boost::iostreams::gzip_compressor());
      file.push(boost::iostreams::file_descriptor_sink(strcat((char*)name, ".gz")));    
      break;
    case BZIP2:
      file.push(boost::iostreams::bzip2_compressor());
      file.push(boost::iostreams::file_descriptor_sink(strcat((char*)name, ".bz2")));
      break;
    default:
      file.push(boost::iostreams::file_descriptor_sink(name));
      break;
    } 
    writeFile(file);

#else

Thomas Witkowski's avatar
Thomas Witkowski committed
36
    std::ofstream file;
37
    file.open(name);
Thomas Witkowski's avatar
Thomas Witkowski committed
38
    TEST_EXIT(file.is_open())("Cannot open file %s for writing\n", name);
39
    writeFile(file);    
40
    file.close();
41

Thomas Witkowski's avatar
Thomas Witkowski committed
42
#endif
43
      
44
    return 0;
45
46
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
47
48
  int VtkWriter::updateAnimationFile(std::string valueFilename,
				     std::vector< std::string > *paraViewAnimationFrames,
49
50
51
52
53
				     const char *animationFilename)
  {
    size_t found = valueFilename.find_last_of("/\\");
    paraViewAnimationFrames->push_back(valueFilename.substr(found + 1));

Thomas Witkowski's avatar
Thomas Witkowski committed
54
    std::ofstream file;
55
56
    file.open(animationFilename);

Thomas Witkowski's avatar
Thomas Witkowski committed
57
58
59
    file << "<?xml version=\"1.0\"?>\n";
    file << "<VTKFile type=\"Collection\" version=\"0.1\" >"  << "\n";
    file << "<Collection>\n";
60
61

    int counter = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
62
    std::vector< std::string >::iterator it;
63
64
65
66
    for (it = paraViewAnimationFrames->begin(); 
	 it < paraViewAnimationFrames->end(); 
	 ++it, counter++) {
      file << "<DataSet timestep=\"" << counter
Thomas Witkowski's avatar
Thomas Witkowski committed
67
	   << "\" part=\"0\" file=\"" << (*it) << "\"/>\n";      
68
69
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
70
71
    file << "</Collection>\n";
    file << "</VTKFile>\n";
72
73
74
75
76

    file.close();
    
    return 0;
  }
77
78


79
}