~ubuntu-branches/ubuntu/karmic/paraview/karmic

« back to all changes in this revision

Viewing changes to VTK/Infovis/Testing/Cxx/TestFixedWidthTextReader.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2008-06-15 22:04:41 UTC
  • Revision ID: james.westby@ubuntu.com-20080615220441-8us51vf6ra2umcov
Tags: upstream-3.2.2
ImportĀ upstreamĀ versionĀ 3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   Visualization Toolkit
 
4
  Module:    $RCSfile: TestFixedWidthTextReader.cxx,v $
 
5
 
 
6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
 
7
  All rights reserved.
 
8
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
 
9
 
 
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.
 
13
 
 
14
=========================================================================*/
 
15
/*----------------------------------------------------------------------------
 
16
 Copyright (c) Sandia Corporation
 
17
 See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
 
18
----------------------------------------------------------------------------*/
 
19
 
 
20
#include <vtkFixedWidthTextReader.h>
 
21
#include <vtkStringArray.h>
 
22
#include <vtkTable.h>
 
23
#include <vtkVariant.h>
 
24
#include <vtkVariantArray.h>
 
25
#include <vtkTestUtilities.h>
 
26
#include <vtkIOStream.h>
 
27
 
 
28
int
 
29
TestFixedWidthTextReader(int argc, char *argv[])
 
30
{
 
31
  cout << "### Pass 1: No headers, field width 10, do not strip whitespace" << endl;
 
32
 
 
33
  vtkIdType i, j;
 
34
  char *filename = vtkTestUtilities::ExpandDataFileName(argc, argv,
 
35
                                                        "Data/fixedwidth.txt");
 
36
 
 
37
  cout << "Filename: " << filename << endl;
 
38
 
 
39
  vtkFixedWidthTextReader *reader = vtkFixedWidthTextReader::New();
 
40
  reader->SetHaveHeaders(false);
 
41
  reader->SetFieldWidth(10);
 
42
  reader->StripWhiteSpaceOff();
 
43
  reader->SetFileName(filename);
 
44
  reader->Update();
 
45
 
 
46
  cout << "Printing reader info..." << endl;
 
47
  reader->Print(cout);
 
48
 
 
49
  vtkTable *table = reader->GetOutput();
 
50
 
 
51
  cout << "FixedWidth text file has " << table->GetNumberOfRows() 
 
52
       << " rows" << endl;
 
53
  cout << "FixedWidth text file has " << table->GetNumberOfColumns() 
 
54
       << " columns" << endl;
 
55
  cout << "Column names: " << endl;
 
56
 
 
57
  for (i = 0; i < table->GetNumberOfColumns(); ++i)
 
58
    {
 
59
    cout << "\tColumn " << i << ": " << table->GetColumn(i)->GetName() << endl;
 
60
    }
 
61
 
 
62
  cout << "Table contents:" << endl;
 
63
  
 
64
  for (i = 0; i < table->GetNumberOfRows(); ++i)
 
65
    {
 
66
    vtkVariantArray *row = table->GetRow(i);
 
67
 
 
68
    for (j = 0; j < row->GetNumberOfTuples(); ++j)
 
69
      {
 
70
      cout << "Row " << i << " column " << j << ": ";
 
71
 
 
72
      vtkVariant value = row->GetValue(j);
 
73
      if (! value.IsValid())
 
74
        {
 
75
        cout << "invalid value" << endl;
 
76
        }
 
77
      else
 
78
        {
 
79
        cout << "type " << value.GetTypeAsString() << " value " 
 
80
             << value.ToString() << endl;
 
81
        }
 
82
      }
 
83
    row->Delete();
 
84
    }
 
85
  
 
86
  reader->Delete();
 
87
  delete [] filename;
 
88
 
 
89
  reader = vtkFixedWidthTextReader::New();
 
90
  filename = vtkTestUtilities::ExpandDataFileName(argc, argv,
 
91
                                                  "Data/fixedwidth.txt");
 
92
 
 
93
  reader->HaveHeadersOn();
 
94
  reader->SetFieldWidth(10);
 
95
  reader->StripWhiteSpaceOn();
 
96
  reader->SetFileName(filename);
 
97
  reader->Update();
 
98
  table = reader->GetOutput();
 
99
 
 
100
 
 
101
  cout << endl << "### Test 2: headers, field width 10, strip whitespace" << endl;
 
102
 
 
103
  cout << "Printing reader info..." << endl;
 
104
  reader->Print(cout);
 
105
 
 
106
  cout << "FixedWidth text file has " << table->GetNumberOfRows() 
 
107
       << " rows" << endl;
 
108
  cout << "FixedWidth text file has " << table->GetNumberOfColumns() 
 
109
       << " columns" << endl;
 
110
  cout << "Column names: " << endl;
 
111
  for (i = 0; i < table->GetNumberOfColumns(); ++i)
 
112
    {
 
113
    cout << "\tColumn " << i << ": " << table->GetColumn(i)->GetName() << endl;
 
114
    }
 
115
 
 
116
  cout << "Table contents:" << endl;
 
117
  
 
118
  for (i = 0; i < table->GetNumberOfRows(); ++i)
 
119
    {
 
120
    vtkVariantArray *row = table->GetRow(i);
 
121
 
 
122
    for (j = 0; j < row->GetNumberOfTuples(); ++j)
 
123
      {
 
124
      cout << "Row " << i << " column " << j << ": ";
 
125
 
 
126
      vtkVariant value = row->GetValue(j);
 
127
      if (! value.IsValid())
 
128
        {
 
129
        cout << "invalid value" << endl;
 
130
        }
 
131
      else
 
132
        {
 
133
        cout << "type " << value.GetTypeAsString() << " value " 
 
134
             << value.ToString() << endl;
 
135
        }
 
136
      }
 
137
    row->Delete();
 
138
    }
 
139
  
 
140
  reader->Delete();
 
141
  delete [] filename;
 
142
 
 
143
  return 0;
 
144
}
 
145
 
 
146
  
 
147