This file is indexed.

/usr/include/minc_1_rw.h is in libminc-dev 2.3.00-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
/* ----------------------------- MNI Header -----------------------------------
@NAME       : 
@DESCRIPTION: Primitive C++ interface to minc files, uses MINC1 API only
@COPYRIGHT  :
              Copyright 2007 Vladimir Fonov, McConnell Brain Imaging Centre, 
              Montreal Neurological Institute, McGill University.
              Permission to use, copy, modify, and distribute this
              software and its documentation for any purpose and without
              fee is hereby granted, provided that the above copyright
              notice appear in all copies.  The author and McGill University
              make no representations about the suitability of this
              software for any purpose.  It is provided "as is" without
              express or implied warranty.
---------------------------------------------------------------------------- */
#ifndef MINC_1_RW_H
#define MINC_1_RW_H

#include <vector>
#include <string>

#include "minc_io_exceptions.h"

#ifdef USE_MINC2
#define MINC2 1
#endif 

extern "C" {
#include <minc.h> 
}

#include <typeinfo>
#include <float.h>
#include <iostream>

namespace minc
{
  
  //! class for storing dimension information 
  struct dim_info
  {
    enum dimensions {DIM_UNKNOWN=0,DIM_X,DIM_Y,DIM_Z,DIM_TIME,DIM_VEC} ;
    dim_info():length(0),step(0),start(0),have_dir_cos(false),dim(DIM_UNKNOWN)
    {
      dir_cos[0]=dir_cos[1]=dir_cos[2]=0.0;
    }
    dim_info(int l, double sta,double spa,dimensions d,bool hd=false);
    size_t length;
    double step,start;
    bool have_dir_cos;
    double dir_cos[3];
    std::string name;
    dimensions  dim;
  };
  
  //! collection of dimensions describing a minc file
  typedef std::vector<dim_info> minc_info;
  
  //! minc file rw base class
  class minc_1_base
  {
  protected:
    int _slab_len;
    int _icvid;
    std::vector<long> _cur,_slab;
    size_t  _slice_dimensions;
    bool _last;
    bool _positive_directions;
    nc_type _datatype;
    nc_type _io_datatype;
    char _dimension_names[MAX_VAR_DIMS][MAX_NC_NAME];
    std::vector<double> _dir_cos;
    long vcount[MAX_VAR_DIMS];
    std::vector<double> _world_matrix;
    std::vector<int>    _voxel_matrix;
    int _ndims, mdims[MAX_VAR_DIMS];
    int _is_signed;
    int _mincid, _imgid;
    int _icmax,_icmin;
    double _image_range[2];
    std::vector<long> _dims;
    std::vector<int> _map_to_std;
    minc_info _info;
    bool _minc2;
  public:
    
    //! get the minc handle
    int mincid(void) const  //this is not really a const ?
    {
      return _mincid;
    }
    
    //! get the data type id (NC_BYTE,NC_INT etc)
    nc_type datatype(void) const
    {
      return _datatype;
    }
    
    //! byte size of the volume elements
    unsigned int element_size(void) const
    {
      switch(_io_datatype)
      {
        case NC_FLOAT: return sizeof(float);
        case NC_DOUBLE: return sizeof(double);
        case NC_SHORT: return sizeof(short);
        case NC_BYTE: return sizeof(char);
        default:return 0;//maybe throw exception here?
      }
    }
    
    //! is data stored in signed format
    bool is_signed(void) const
    {
      return _is_signed;
    }
  
    //! constructor
	  minc_1_base();

    //! destructor, closes minc file
    virtual ~minc_1_base();
    
    //! close the minc file
    virtual void close(void);

    //! is last slice was read?
    bool last(void) const 
    {
      return _last;
    }
    
    //! go to the beginning of file
    void begin(void)
    {
      fill(_cur.begin(),_cur.end(),0);
      _last=false;
    }
    
    //! advance to next slice 
    bool next_slice(void)
    {
      if(_last) return !_last;
        
      for(int i=_ndims-_slice_dimensions-1;i>=0;i--)
      {
        _cur[i]++;
        if(_cur[i]<static_cast<long>(_info[i].length))
          break;
        if(!i)
          _last=true;
        else 
          _cur[i]=0;
      }
      return !_last;
    }
    
    //! slice length in elements
    int slice_len(void) const
    {
      return _slab_len;
    }
    
    //! number of dimensions
    int dim_no(void) const
    {
      return _ndims;
    }
    
    //! get the dimension information
    const dim_info& dim(unsigned int n) const
    {
      if(n>=static_cast<unsigned int>(_ndims)) 
        REPORT_ERROR("Dimension is not defined");
      return _info[n];
    }
    
    //! get the pointer to the dimension description array
    const minc_info& info(void) const
    {
      return _info;
    }
    
    //! get the number of dimensions in one slice
    int slice_dimensions(void) const
    {
      return _slice_dimensions;
    }
    
    //! get the current slice index
    const std::vector<long> & current_slice(void) const
    {
      return _cur;
    }
    
    //! get the normalized dimensions sizes 
    //! ( 0 - vector_dimension, 1 - x, 2- y , 3 -z , 4 - time)
    int ndim(int i) const
    {
      int j=_map_to_std[i];
      if(j>=0) return _info[j].length;
      return 0;
    }
    //! get normalized dimension start coordinate (see ndim)
    double nstart(int i) const
    {
      int j=_map_to_std[i];
      if(j>=0) return _info[j].start;
      return 0.0;
    }
    
    //! get normalized dimension spacing  (see ndim)
    double nspacing(int i) const
    {
      int j=_map_to_std[i];
      if(j>=0) return _info[j].step;
      return 0.0;
    }
    
    //! get normalized dimension direction cosine component  (see ndim)
    double ndir_cos(int i,int j) const
    {
      int k=_map_to_std[i];
      if(k>=0) return _info[k].dir_cos[j];
      return 0.0;
    }
    
    //! check if a normalized dimension has direction cosine information
    bool have_dir_cos(int i) const
    {
      int k=_map_to_std[i];
      if(k>=0) return _info[k].have_dir_cos;
      return false;
    }
     
    //! map file dimensions into normalized dimensions
    int map_space(int i)
    {
      return _map_to_std[i];
    }
    
    //metadate info handling function:
    //! read the minc history (:history attribute)
    std::string history(void) const;
    
    //! retrive var id, if it exists, otherwise return MI_ERROR
    int var_id(const char *var_name) const;
    
    //! get variable length
    long var_length(const char *var_name) const;
    
    //! get variable length
    long var_length(int var_id) const;
    
    //! read the number of variables
    int var_number(void) const;
    
    //! get the variable name number no
    std::string var_name(int no) const;
    
    //! get the variable contents, given it's id
    std::vector<double> var_value_double(int varid) const;
    
    //! get the variable contents, given it's name
    std::vector<double> var_value_double(const char *var_name) const;
    
    //! get the number of attributes associated with variable
    int att_number(const char *var_name) const;
    
    //! get the number of attributes associated with variable
    int att_number(int var_no) const;
    
    //! get the attribute name, given the number
    std::string att_name(const char *var_name,int no) const;
    //! get the attribute name, given the number
    std::string att_name(int varid,int no) const;
    
    //! get the string attribute value , given the name
    std::string att_value_string(const char *var_name,const char *att_name) const;
    //! get the string attribute value , given variable id
    std::string att_value_string(int varid,const char *att_name) const;
    
    //! get the double attribute value , given the name
    std::vector<double> att_value_double(const char *var_name,const char *att_name) const;
    //! get the int attribute value , given the name
    std::vector<int> att_value_int(const char *var_name,const char *att_name) const;
    //! get the short attribute value , given the variable id
    std::vector<short> att_value_short(const char *var_name,const char *att_name) const;
    //! get the byte attribute value , given the variable id
    std::vector<unsigned char> att_value_byte(const char *var_name,const char *att_name) const;
    
    //! get the double attribute value , given the variable id
    std::vector<double> att_value_double(int varid,const char *att_name) const;
    //! get the int attribute value , given the variable id
    std::vector<int> att_value_int(int varid,const char *att_name) const;
    //! get the short attribute value , given the variable id
    std::vector<short> att_value_short(int varid,const char *att_name) const;
    //! get the byte attribute value , given the variable id
    std::vector<unsigned char> att_value_byte(int varid,const char *att_name) const;
    
    //! enquire about attribute data type
    nc_type att_type(const char *var_name,const char *att_name) const;
    //! enquire about attribute data type
    nc_type att_type(int varid,const char *att_name) const;

    //! enquire about attribute length
    int att_length(const char *var_name,const char *att_name) const;
    //! enquire about attribute length
    int att_length(int varid,const char *att_name) const;


    //! return var_id for the given name (create one, if it doesn't exists)
    int create_var_id(const char *varname);
    
    void insert(const char *varname,const char *attname,double val);
    void insert(const char *varname,const char *attname,const char* val);
    void insert(const char *varname,const char *attname,const std::vector<double> &val);
    void insert(const char *varname,const char *attname,const std::vector<int> &val);
    void insert(const char *varname,const char *attname,const std::vector<short> &val);
    void insert(const char *varname,const char *attname,const std::vector<unsigned char> &val);
    
    
    //! check if the file in MINC2 format
    bool is_minc2(void) const
    {
      return _minc2;
    }
    
  };
  
  //! minc file reader
  class minc_1_reader:public minc_1_base
  {
    protected:
      bool _metadate_only;
      std::string _tempfile;
      bool _have_temp_file;
      bool _read_prepared;
      void _setup_dimensions(void);

    public:
    //! copy constructor
    minc_1_reader(const minc_1_reader&);
    
    //! default constructor
    minc_1_reader();

    //! close the minc file
    virtual void close(void);
    
    //! destructor
    virtual ~minc_1_reader();
    
    //! open a minc file
    //! \param path - path to existing  minc file
    //! \param positive_directions  - make all step sizes positive
    //! \param metadate_only - file is opened only for the purpose of reading metadata (will save memory)
    //! \param rw - file headers may be modified
    void open(const char *path,bool positive_directions=false,bool metadate_only=false,bool rw=false);
    
    //! read single slice
    void read(void* slice);
    //! setup reading in float format
    void setup_read_float(void);
    //! setup reading in double format
    void setup_read_double(void);
    //! setup reading in signed short format
    void setup_read_short(bool normalized=false);
    //! setup reading in unsigned short format
    void setup_read_ushort(bool normalized=false);
    //! setup reading in byte format
    void setup_read_byte(bool normalized=false);
    //! setup reading in int format
    void setup_read_int(bool normalized=false);
    //! setup reading in unsigned int format
    void setup_read_uint(bool normalized=false);
  };
  
  //! minc file writer
  class minc_1_writer:public minc_1_base
  {
    protected:
      bool _set_image_range;
      bool _set_slice_range;
      bool _calc_min_max;
      bool _write_prepared;
    public:
      //! open minc file for writing - will overwrite existing 
      //! \param path - path to minc file
      //! \param inf  - information about dimensions
      //! \param slice_dimensions - number of dimensions per slice (used for storage)
      //! \param datatype - storage datatype
      //! \param is_signed - check if datatype will be signed or not
      void open(const char *path,const minc_info& inf,int slice_dimensions,nc_type datatype,int is_signed=0);
      
      //! open minc file for writing - will overwrite existing 
      //! \param path - path to minc file
      //! \param imitate  - all information is copied from this opened minc file
      void open(const char *path,const minc_1_base& imitate);
      
      //! open minc file for writing - will overwrite existing 
      //! \param path - path to minc file
      //! \param imitate_file  - all information is copied from this existing minc file
      void open(const char *path,const char *imitate_file);
    
      //! prepare for writing float array
      void setup_write_float(void);
      //! prepare for writing double array
      void setup_write_double(void);
      //! prepare for writing short array
      void setup_write_short(bool normalize=false);
      //! prepare for writing unsigned short array
      void setup_write_ushort(bool normalize=false);
      //! prepare for writing unsigned char array
      void setup_write_byte(bool normalize=false);
      //! prepare for writing int array
      void setup_write_int(bool normalize=false);
      //! prepare for writing unsigned int array
      void setup_write_uint(bool normalize=false);
    
      //! copy header from another minc file
      //! \param src - path to existing minc file
      void copy_headers(const minc_1_base& src);
    
      //! append a line into minc history
      //! \param append_history - history line to append
      void append_history(const char *append_history);
      
      //! default constructor
      minc_1_writer();
      
      //! make a copy of another writer
      minc_1_writer(const minc_1_writer&);
      
      //! destructor
      virtual ~minc_1_writer();
      
      //! close the minc file
      virtual void close(void);
      
      //!write a single slice, size of the buffer should be more or equall to slab_len
      void write(void* slice);
  };
}
#endif //__PRIMITIVE_MINC_IO__