OpendTect  6.3
arraynddumper.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: Bert
8  Date: May 2013
9 ________________________________________________________________________
10 
11 
12 -*/
13 
14 #include "algomod.h"
15 #include "arraynd.h"
16 #include "od_iostream.h"
17 
27 template <class T>
29 {
30 public:
31 
32  ArrayNDDumper( const ArrayND<T>& arr )
33  : inp_(arr), haveudfs_(true)
34  , withpos_(false)
35  { setOneLinePerFastestDim(); }
36 
37  inline void setSingleLineWithPos()
38  { withpos_ = true; nlafter_ = 1; }
39  inline void setOneLinePerFastestDim();
40  inline void setOneLinePerSlowestDim();
41 
42  inline void dump(od_ostream&) const;
43 
44  const ArrayND<T>& inp_;
45  bool withpos_;
46  bool haveudfs_;
48 
49 };
50 
51 
52 template <class T>
54 {
55  const int nrdims = inp_.info().getNDim();
56  nlafter_ = nrdims < 2 ? 0 : inp_.info().getSize( nrdims - 1 );
57 }
58 
59 
60 template <class T>
62 {
63  const int nrdims = inp_.info().getNDim();
64  if ( nrdims < 2 )
65  { nlafter_ = 0; return; }
66 
67  nlafter_ = 1;
68  for ( int idim=1; idim<nrdims; idim++ )
69  nlafter_ *= inp_.info().getSize( idim );
70 }
71 
72 
73 template <class T>
75 {
76  if ( inp_.isEmpty() ) return;
77 
78  ArrayNDIter it( inp_.info() );
79  const int nrdims = inp_.info().getNDim();
80 
81  od_int64 nrthisline = 0;
82  while ( true )
83  {
84  const int* pos = it.getPos();
85  if ( withpos_ && nrthisline == 0 )
86  {
87  for ( int idim=0; idim<nrdims; idim++ )
88  strm.add( pos[idim] ).add( od_tab );
89 
90  }
91 
92  const T val = inp_.getND( pos );
93  if ( haveudfs_ && mIsUdf(val) )
94  strm.add( "udf" );
95  else
96  strm.add( val );
97 
98  char wschar = od_tab;
99  if ( nlafter_ > 0 )
100  {
101  nrthisline++;
102  if ( nrthisline == nlafter_ )
103  { wschar = od_newline; nrthisline = 0; }
104  }
105  if ( it.next() )
106  strm.add( wschar );
107  else
108  { strm.add(od_newline).flush(); break; }
109  }
110 }
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:285
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:25
bool withpos_
Definition: arraynddumper.h:45
#define od_int64
Definition: plftypes.h:34
od_ostream & add(char)
ArrayNDDumper(const ArrayND< T > &arr)
Definition: arraynddumper.h:32
od_int64 nlafter_
Definition: arraynddumper.h:47
Dumps contents of ArrayND objects.
Definition: arraynddumper.h:28
void flush()
void setOneLinePerFastestDim()
Definition: arraynddumper.h:53
#define od_tab
Definition: od_iosfwd.h:22
An ArrayND is an array with a given number of dimensions and a size.
Definition: arraynd.h:29
Iterates through all samples in an ArrayND.
Definition: arraynd.h:175
const ArrayND< T > & inp_
Definition: arraynddumper.h:44
void setSingleLineWithPos()
Definition: arraynddumper.h:37
bool haveudfs_
Definition: arraynddumper.h:46
#define mClass(module)
Definition: commondefs.h:161
void setOneLinePerSlowestDim()
Definition: arraynddumper.h:61
void dump(od_ostream &) const
Definition: arraynddumper.h:74
#define od_newline
Definition: od_iosfwd.h:23

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2017