InputPts.cpp 3.56 KB
Newer Older
Spencer Sherwin's avatar
Spencer Sherwin committed
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
////////////////////////////////////////////////////////////////////////////////
//
//  File: InputPts.cpp
//
//  For more information, please see: http://www.nektar.info/
//
//  The MIT License
//
//  Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
//  Department of Aeronautics, Imperial College London (UK), and Scientific
//  Computing and Imaging Institute, University of Utah (USA).
//
//  License for the specific language governing rights and limitations under
//  Permission is hereby granted, free of charge, to any person obtaining a
//  copy of this software and associated documentation files (the "Software"),
//  to deal in the Software without restriction, including without limitation
//  the rights to use, copy, modify, merge, publish, distribute, sublicense,
//  and/or sell copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included
//  in all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
//  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//  DEALINGS IN THE SOFTWARE.
//
//  Description: Read xml file of a series of points and hold
//
////////////////////////////////////////////////////////////////////////////////

#include <iostream>
37
#include <string>
Spencer Sherwin's avatar
Spencer Sherwin committed
38
39
using namespace std;

40
#include <LibUtilities/BasicUtils/PtsField.h>
41
#include <LibUtilities/BasicUtils/PtsIO.h>
42
#include <LibUtilities/BasicUtils/CsvIO.h>
43

44
#include <tinyxml.h>
Spencer Sherwin's avatar
Spencer Sherwin committed
45
46
47
48
49

#include "InputPts.h"

namespace Nektar
{
Douglas Serson's avatar
Douglas Serson committed
50
namespace FieldUtils
51
52
53
54
55
56
57
{

ModuleKey InputPts::m_className[5] = {
    GetModuleFactory().RegisterCreatorFunction(
        ModuleKey(eInputModule, "pts"), InputPts::create, "Reads Pts file."),
    GetModuleFactory().RegisterCreatorFunction(
        ModuleKey(eInputModule, "pts.gz"), InputPts::create, "Reads Pts file."),
58
59
60
61
    GetModuleFactory().RegisterCreatorFunction(
        ModuleKey(eInputModule, "csv"), InputPts::create, "Reads csv file."),
    GetModuleFactory().RegisterCreatorFunction(
        ModuleKey(eInputModule, "csv.gz"), InputPts::create, "Reads csv file."),
62
63
64
65
66
67
68
69
70
};

/**
 * @brief Set up InputPts object.
 *
 */
InputPts::InputPts(FieldSharedPtr f) : InputModule(f)
{
    m_allowedFiles.insert("pts");
71
    m_allowedFiles.insert("csv");
72
73
}

Chris Cantwell's avatar
Chris Cantwell committed
74
75
76
/**
 *
 */
77
78
79
80
81
82
83
84
85
InputPts::~InputPts()
{
}

/**
 *
 */
void InputPts::Process(po::variables_map &vm)
{
86
    string inFile = m_config["infile"].as<string>();
87

88
    // Determine appropriate field input
Douglas Serson's avatar
Douglas Serson committed
89
    if (m_f->m_inputfiles.count("csv") != 0)
90
    {
91
92
93
        LibUtilities::CsvIOSharedPtr csvIO =
            MemoryManager<LibUtilities::CsvIO>::AllocateSharedPtr(m_f->m_comm);
        csvIO->Import(inFile, m_f->m_fieldPts);
94
    }
Douglas Serson's avatar
Douglas Serson committed
95
    else if (m_f->m_inputfiles.count("pts") != 0)
96
    {
97
98
99
        LibUtilities::PtsIOSharedPtr ptsIO =
            MemoryManager<LibUtilities::PtsIO>::AllocateSharedPtr(m_f->m_comm);
        ptsIO->Import(inFile, m_f->m_fieldPts);
100
101
102
    }
    else
    {
103
        ASSERTL0(false, "unknown input file type");
104
105
    }

Douglas Serson's avatar
Douglas Serson committed
106
107
108
109
110
    // save field names
    for (int j = 0; j < m_f->m_fieldPts->GetNFields(); ++j)
    {
        m_f->m_variables.push_back(m_f->m_fieldPts->GetFieldName(j));
    }
Spencer Sherwin's avatar
Spencer Sherwin committed
111
}
112
113
}
}