Menu

[r152]: / trunk / contrib / dge2vtk / main.cpp  Maximize  Restore  History

Download this file

66 lines (56 with data), 1.9 kB

 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
28
29
30
31
32
33
34
35
36
37
38
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
#include <cpplapack.h>
//=============================================================================
int main(int argc, char** argv)
{
//////// argc check ////////
if(argc!=2){
std::cerr << "[ERROR] invalid usage" << std::endl;
std::cerr << "USAGE: " << argv[0] << " xxxx.dgematrix" << std::endl;
exit(1);
}
//////// open ////////
CPPL::dgematrix mat(argv[1]);
std::cerr << "mat size = " << mat.m << "x" << mat.n << std::endl;
const long mn(mat.m*mat.n);
/////// write header ///////
std::cout << "# vtk DataFile Version 2.0" << std::endl;
std::cout << "made by dge2vtk" << std::endl;
std::cout << "ASCII" << std::endl;
std::cout << "DATASET UNSTRUCTURED_GRID" << std::endl;
std::cout << std::endl;
/////// write POINTS ///////
std::cout << "POINTS " << mn << " double" << std::endl;
for(long i=0; i<mat.m; i++){
for(long j=0; j<mat.n; j++){
std::cout << j << " " << i << " " << "0" << std::endl;
}
}
std::cout << std::endl;
/////// write CELLS ///////
std::cout << "CELLS " << mn << " " << 2*mn << std::endl;
for(long i=0; i<mn; i++){
std::cout << "1 " << i << std::endl;
}
std::cout << std::endl;
/////// write CELL_TYPES ///////
std::cout.unsetf(std::ios::showpos);
std::cout << "CELL_TYPES " << mn << std::endl;
std::cout.setf(std::ios::showpos);
for(long i=0; i<mn; i++){
std::cout << "1" << std::endl; // VTK_VERTEX = 1
}
std::cout << std::endl;
//////// write CELL_DATA ////////
std::cout.unsetf(std::ios::showpos);
std::cout << "CELL_DATA " << mn << std::endl;
std::cout.setf(std::ios::showpos);
std::cout << "SCALARS value double 1" << std::endl;// SCALAR = 1
std::cout << "LOOKUP_TABLE default" << std::endl;
for(long i=0; i<mat.m; i++){
for(long j=0; j<mat.n; j++){
std::cout << mat(i,j) << std::endl;
}
}
std::cout << std::endl;
return 0;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.