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

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