1
/*=========================================================================
3
Program: Visualization Toolkit
4
Module: $RCSfile: TestFixedWidthTextReader.cxx,v $
6
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
10
This software is distributed WITHOUT ANY WARRANTY; without even
11
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
PURPOSE. See the above copyright notice for more information.
14
=========================================================================*/
15
/*----------------------------------------------------------------------------
16
Copyright (c) Sandia Corporation
17
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
18
----------------------------------------------------------------------------*/
20
#include <vtkFixedWidthTextReader.h>
21
#include <vtkStringArray.h>
23
#include <vtkVariant.h>
24
#include <vtkVariantArray.h>
25
#include <vtkTestUtilities.h>
26
#include <vtkIOStream.h>
29
TestFixedWidthTextReader(int argc, char *argv[])
31
cout << "### Pass 1: No headers, field width 10, do not strip whitespace" << endl;
34
char *filename = vtkTestUtilities::ExpandDataFileName(argc, argv,
35
"Data/fixedwidth.txt");
37
cout << "Filename: " << filename << endl;
39
vtkFixedWidthTextReader *reader = vtkFixedWidthTextReader::New();
40
reader->SetHaveHeaders(false);
41
reader->SetFieldWidth(10);
42
reader->StripWhiteSpaceOff();
43
reader->SetFileName(filename);
46
cout << "Printing reader info..." << endl;
49
vtkTable *table = reader->GetOutput();
51
cout << "FixedWidth text file has " << table->GetNumberOfRows()
53
cout << "FixedWidth text file has " << table->GetNumberOfColumns()
54
<< " columns" << endl;
55
cout << "Column names: " << endl;
57
for (i = 0; i < table->GetNumberOfColumns(); ++i)
59
cout << "\tColumn " << i << ": " << table->GetColumn(i)->GetName() << endl;
62
cout << "Table contents:" << endl;
64
for (i = 0; i < table->GetNumberOfRows(); ++i)
66
vtkVariantArray *row = table->GetRow(i);
68
for (j = 0; j < row->GetNumberOfTuples(); ++j)
70
cout << "Row " << i << " column " << j << ": ";
72
vtkVariant value = row->GetValue(j);
73
if (! value.IsValid())
75
cout << "invalid value" << endl;
79
cout << "type " << value.GetTypeAsString() << " value "
80
<< value.ToString() << endl;
89
reader = vtkFixedWidthTextReader::New();
90
filename = vtkTestUtilities::ExpandDataFileName(argc, argv,
91
"Data/fixedwidth.txt");
93
reader->HaveHeadersOn();
94
reader->SetFieldWidth(10);
95
reader->StripWhiteSpaceOn();
96
reader->SetFileName(filename);
98
table = reader->GetOutput();
101
cout << endl << "### Test 2: headers, field width 10, strip whitespace" << endl;
103
cout << "Printing reader info..." << endl;
106
cout << "FixedWidth text file has " << table->GetNumberOfRows()
108
cout << "FixedWidth text file has " << table->GetNumberOfColumns()
109
<< " columns" << endl;
110
cout << "Column names: " << endl;
111
for (i = 0; i < table->GetNumberOfColumns(); ++i)
113
cout << "\tColumn " << i << ": " << table->GetColumn(i)->GetName() << endl;
116
cout << "Table contents:" << endl;
118
for (i = 0; i < table->GetNumberOfRows(); ++i)
120
vtkVariantArray *row = table->GetRow(i);
122
for (j = 0; j < row->GetNumberOfTuples(); ++j)
124
cout << "Row " << i << " column " << j << ": ";
126
vtkVariant value = row->GetValue(j);
127
if (! value.IsValid())
129
cout << "invalid value" << endl;
133
cout << "type " << value.GetTypeAsString() << " value "
134
<< value.ToString() << endl;