00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_IO_RAW_GET_HEADER_HH
00027 # define MLN_IO_RAW_GET_HEADER_HH
00028 
00032 
00033 # include <iostream>
00034 # include <fstream>
00035 
00036 # include <mln/core/concept/image.hh>
00037 # include <mln/core/routine/initialize.hh>
00038 # include <mln/core/box_runstart_piter.hh>
00039 # include <mln/core/pixel.hh>
00040 # include <mln/data/memcpy_.hh>
00041 # include <mln/util/array.hh>
00042 
00043 namespace mln
00044 {
00045 
00046   namespace io
00047   {
00048 
00049     namespace raw
00050     {
00051 
00053       struct raw_header
00054       {
00055         unsigned dim;
00056         std::string value_type;
00057         util::array<unsigned> size;
00058       };
00059 
00060 
00062       raw_header get_header(const std::string& filename);
00063 
00064 
00065 # ifndef MLN_INCLUDE_ONLY
00066 
00067 
00068       raw_header get_header(const std::string& filename)
00069       {
00070         trace::entering("mln::io::raw::get_header");
00071 
00072         raw_header header;
00073 
00074         std::string info_filename = filename + ".info";
00075 
00076         std::ifstream info_file(info_filename.c_str());
00077         if (! info_file)
00078         {
00079           std::cerr << "io::raw::get_header - Error: cannot open file '"
00080                     << filename << "'!"
00081                     << std::endl;
00082           abort();
00083         }
00084 
00085         std::string file_type;
00086         info_file >> file_type;
00087         if (file_type != "milena/raw")
00088         {
00089           std::cerr << "io::raw::load - Error: invalid file type. '"
00090                     << filename
00091                     << "' is NOT a valid milena/raw info file!"
00092                     << std::endl;
00093           abort();
00094         }
00095 
00096         char dev_null[30];
00097 
00098         
00099         
00100         info_file.read(dev_null, 5);
00101         info_file >> header.dim;
00102 
00103         
00104         header.size.resize(header.dim);
00105         for (unsigned i = 0; i < header.dim; ++i)
00106           info_file >> header.size[i];
00107         
00108         char c;
00109         info_file.get(c);
00110 
00111 
00112         
00113         
00114         info_file.read(dev_null, 11);
00115         
00116         char value_type[255];
00117         info_file.getline(value_type, 255);
00118         header.value_type = value_type;
00119 
00120         info_file.close();
00121 
00122         trace::exiting("mln::io::raw::get_header");
00123         return header;
00124       }
00125 
00126 
00127 # endif // ! MLN_INCLUDE_ONLY
00128 
00129     } 
00130 
00131   } 
00132 
00133 } 
00134 
00135 #endif // ! MLN_IO_RAW_GET_HEADER_HH
00136