Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
write_header.hh
1 // Copyright (C) 2008, 2009, 2010 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_IO_FLD_WRITE_HEADER_HH
28 # define MLN_IO_FLD_WRITE_HEADER_HH
29 
32 
33 # include <cstdlib>
34 
35 # include <iostream>
36 
37 # include <mln/io/fld/header.hh>
38 
39 namespace mln
40 {
41 
42  namespace io
43  {
44 
45  namespace fld
46  {
52  void write_header(std::ostream& file, const fld_header& h);
53 
54 # ifndef MLN_INCLUDE_ONLY
55 
56  inline
57  void
58  write_header(std::ostream& file, const fld_header& h)
59  {
60  file << "# AVS field file" << std::endl;
61  file << "# Generated by Milena 1.0 http://olena.lrde.epita.fr" << std::endl;
62  file << "# EPITA Research and Development Laboratory (LRDE)" << std::endl;
63 
64  file << "ndim=" << h.ndim << std::endl;
65  for (int i = 0; i < h.ndim; i++)
66  file << "dim" << (i + 1) << "=" << h.dim[i] << std::endl;
67  file << "nspace=" << h.nspace << std::endl
68  << "veclen=" << h.veclen << std::endl;
69 
70  switch (h.data)
71  {
72  case data_type::BYTE :
73  file << "data=byte" << std::endl;
74  break;
75  case data_type::SHORT :
76  file << "data=short" << std::endl;
77  break;
78  case data_type::INTEGER :
79  file << "data=integer" << std::endl;
80  break;
81  case data_type::FLOAT :
82  file << "data=float" << std::endl;
83  break;
84  case data_type::DOUBLE :
85  file << "data=double" << std::endl;
86  break;
87  default:
88  std::cerr << "Data type not supported: abort().";
89  std::abort();
90  }
91 
92  switch (h.field)
93  {
94  case field_type::UNIFORM :
95  file << "field=uniform" << std::endl;
96  break;
97  case field_type::IRREGULAR :
98  file << "field=irregular" << std::endl;
99  break;
100  case field_type::RECTILINEAR :
101  file << "field=rectilinear" << std::endl;
102  break;
103  default:
104  std::cerr << "Field type not suported: abort().";
105  std::abort();
106  }
107 
108  file << "min_ext=";
109  for (int i = 0; i < h.nspace; i++)
110  file << h.min_ext[i] << " ";
111  file << std::endl;
112 
113  file << "max_ext=";
114  for (int i = 0; i < h.nspace; i++)
115  file << h.max_ext[i] << " ";
116  file << std::endl;
117 
118  file << "\f\f";
119  }
120 
121 #endif // !MLN_INCLUDE_ONLY
122 
123  } // end of namespace mln::io::fld
124 
125  } // end of namespace mln::io
126 
127 } // end of namespace mln
128 
129 #endif // !MLN_IO_FLD_WRITE_HEADER_HH