# HG changeset patch
# Parent 076420bf661e43e36275ac3e2bd23a2cd396f05b

diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files
--- a/src/OpenFOAM/Make/files
+++ b/src/OpenFOAM/Make/files
@@ -512,6 +512,10 @@
 interpolation = $(interpolations)/interpolation
 $(interpolations)/patchToPatchInterpolation/PatchToPatchInterpolationName.C
 
+$(interpolations)/interpolationTable/tableReaders/tableReaders.C
+$(interpolations)/interpolationTable/tableReaders/openFoam/openFoamTableReaders.C
+$(interpolations)/interpolationTable/tableReaders/csv/csvTableReaders.C
+
 algorithms/MeshWave/MeshWaveName.C
 algorithms/MeshWave/FaceCellWaveName.C
 
diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C
--- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C
+++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C
@@ -26,6 +26,8 @@
 #include "interpolationTable.H"
 #include "IFstream.H"
 
+#include "openFoamTableReader.H"
+
 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
 
 template<class Type>
@@ -37,8 +39,15 @@
 
     fName.expand();
 
+    if(!exists(fName,false)) {
+        FatalErrorIn("Foam::interpolationTable<Type>::readTable()")
+            << " The file " << fileName_ << " (expanded: " << fName
+                << ") does not exist" 
+                << endl
+                << abort(FatalError);
+    }
     // Read data from file
-    IFstream(fName)() >> *this;
+    reader_()(fName,*this);
 
     // Check that the data are okay
     check();
@@ -53,7 +62,6 @@
     }
 }
 
-
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 template<class Type>
@@ -61,7 +69,8 @@
 :
     List<Tuple2<scalar, Type> >(),
     boundsHandling_(interpolationTable::WARN),
-    fileName_("fileNameIsUndefined")
+    fileName_("fileNameIsUndefined"),
+    reader_(new openFoamTableReader<Type>())
 {}
 
 
@@ -75,7 +84,8 @@
 :
     List<Tuple2<scalar, Type> >(values),
     boundsHandling_(bounds),
-    fileName_(fName)
+    fileName_(fName),
+    reader_(new openFoamTableReader<Type>())
 {}
 
 
@@ -84,7 +94,8 @@
 :
     List<Tuple2<scalar, Type> >(),
     boundsHandling_(interpolationTable::WARN),
-    fileName_(fName)
+    fileName_(fName),
+    reader_(new openFoamTableReader<Type>())
 {
     readTable();
 }
@@ -95,7 +106,8 @@
 :
     List<Tuple2<scalar, Type> >(),
     boundsHandling_(wordToBoundsHandling(dict.lookup("outOfBounds"))),
-    fileName_(dict.lookup("fileName"))
+    fileName_(dict.lookup("fileName")),
+    reader_(tableReader<Type>::New(dict))
 {
     readTable();
 }
@@ -109,7 +121,8 @@
 :
     List<Tuple2<scalar, Type> >(interpTable),
     boundsHandling_(interpTable.boundsHandling_),
-    fileName_(interpTable.fileName_)
+    fileName_(interpTable.fileName_),
+    reader_(interpTable.reader_->clone())
 {}
 
 
@@ -233,6 +246,7 @@
         << fileName_ << token::END_STATEMENT << nl;
     os.writeKeyword("outOfBounds")
         << boundsHandlingToWord(boundsHandling_) << token::END_STATEMENT << nl;
+    reader_->write(os);
 }
 
 
diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H
--- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H
+++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H
@@ -49,6 +49,9 @@
 #include "List.H"
 #include "Tuple2.H"
 
+#include "tableReader.H"
+#include "autoPtr.H"
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
@@ -87,12 +90,17 @@
         //- File name
         fileName fileName_;
 
+        //- the actual reader
+        autoPtr<tableReader<Type> > reader_;
 
     // Private Member Functions
 
         //- Read the table of data from file
         void readTable();
 
+        //- Read the table of data from file. Format is to be determined
+    //        void readTable(const dictionary &spec);
+
 
 public:
 
diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.C
new file mode 100644
--- /dev/null
+++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.C
@@ -0,0 +1,189 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "csvTableReader.H"
+#include "IFstream.H"
+#include "DynamicList.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+template<class Type>
+Foam::csvTableReader<Type>::csvTableReader()
+    : 
+    headerLine_(true),
+    timeColumn_(-1),
+    componentColumns_(0,-1)
+{
+    notImplemented("Foam::csvTableReader<Type>::csvTableReader()")
+}
+
+template<class Type>
+Foam::csvTableReader<Type>::csvTableReader(const dictionary &spec)
+    :
+    headerLine_(readBool(spec.lookup("hasHeaderLine"))),
+    timeColumn_(readLabel(spec.lookup("timeColumn"))),
+    componentColumns_(spec.lookup("valueColumns")),
+    separator_(spec.lookupOrDefault<string>("separator",string(","))[0])
+{
+    if(componentColumns_.size()!=pTraits<Type>::nComponents) {
+        FatalErrorIn("")
+            << componentColumns_ << " does not have the expected length "
+                << pTraits<Type>::nComponents << endl
+                << abort(FatalError);
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+template<class Type>
+Foam::csvTableReader<Type>::~csvTableReader()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+namespace Foam {
+    // doesn't recognize specialization otherwise
+    template<>
+    scalar csvTableReader<scalar>::readValue(const List<string> &splitted)
+    {
+        if(componentColumns_[0]>=splitted.size()) {
+            FatalErrorIn("scalar csvTableReader<scalar>::readValue(const List<string> &splitted)")
+                << "No column " << componentColumns_[0] << " in " 
+                    << splitted << endl
+                    << abort(FatalError);
+        }
+
+        return readScalar(IStringStream(splitted[componentColumns_[0]])());
+    }
+    
+    template<class Type>
+    Type csvTableReader<Type>::readValue(const List<string> &splitted)
+    {
+        Type result;
+
+        for(label i=0;i<pTraits<Type>::nComponents;i++) {
+            if(componentColumns_[i]>=splitted.size()) {
+                FatalErrorIn("Type csvTableReader<Type>::readValue(const List<string> &splitted)")
+                    << "No column " << componentColumns_[i] << " in " 
+                        << splitted << endl
+                        << abort(FatalError);
+            }
+
+            result[i]=readScalar(IStringStream(splitted[componentColumns_[i]])());
+        }
+
+        return result;
+    }
+}
+
+template<class Type>
+Foam::string Foam::csvTableReader<Type>::readLine(IFstream &in)
+{
+    string result="";
+
+    char c='.';
+
+    while(
+        !in.eof()
+        &&
+        c!='\n'
+    ) {
+        in.get(c);
+        if(c!='\n' && !in.eof()) {
+            result+=c;
+        }
+    }
+
+    return result;
+}
+
+template<class Type>
+void Foam::csvTableReader<Type>::operator()(const fileName &fName,List<Tuple2<scalar, Type> > &data)
+{
+    IFstream in(fName);
+
+    DynamicList<Tuple2<scalar, Type> > values;
+
+    label lineNr=0;
+
+    while(!in.eof()) {
+        string line=readLine(in);
+
+        lineNr++;
+        if( headerLine_ && lineNr==1) {
+            continue;
+        }
+        DynamicList<string> splitted;
+        std::size_t pos=0;
+        while(pos!=std::string::npos) {
+            std::size_t nPos=line.find(separator_,pos);
+            if(nPos==std::string::npos) {
+                splitted.append(line.substr(pos));
+                pos=nPos;
+            } else {
+                splitted.append(line.substr(pos,nPos-pos));
+                pos=nPos+1;
+            }
+        }
+
+        if(splitted.size()<=1) {
+            break;
+        }
+
+        scalar time=readScalar(IStringStream(splitted[timeColumn_])());
+        Type value=readValue(splitted);
+
+        values.append(Tuple2<scalar,Type>(time,value));
+    }
+
+    data.transfer(values);
+}
+
+template<class Type>
+void Foam::csvTableReader<Type>::write(Ostream& os) const
+{
+    tableReader<Type>::write(os);
+
+    os.writeKeyword("hasHeaderLine")
+        << headerLine_ << token::END_STATEMENT << nl;
+    os.writeKeyword("timeColumn")
+        << timeColumn_ << token::END_STATEMENT << nl;
+    os.writeKeyword("valueColumns")
+        << componentColumns_ << token::END_STATEMENT << nl;
+    os.writeKeyword("separator")
+        << string(separator_) << token::END_STATEMENT << nl;
+
+}
+
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.H b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.H
new file mode 100644
--- /dev/null
+++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.H
@@ -0,0 +1,128 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::tableReader
+
+Description
+    Reads an interpolation table from a file - CSV-format
+
+SourceFiles
+    tableReader.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef csvTableReader_H
+#define csvTableReader_H
+
+#include "tableReader.H"
+#include "labelList.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+    class IFstream;
+
+/*---------------------------------------------------------------------------*\
+                           Class csvTableReader Declaration
+\*---------------------------------------------------------------------------*/
+
+template<class Type>
+class csvTableReader
+:
+    public tableReader<Type>
+{
+    //- does the file have a header line?
+    bool headerLine_;
+
+    //- column of the time
+    label timeColumn_;
+
+    //- labels of the components
+    labelList componentColumns_;
+
+    //- read the nect value from the splitted string
+    Type readValue(const List<string> &splitted);
+
+    //- read a line from a stream
+    string readLine(IFstream &in);
+
+    //- separator character 
+    char separator_;
+public:
+
+    //- Runtime type information
+    TypeName("csv");
+
+    // Constructors
+
+        //- Construct null
+        csvTableReader();
+
+        //- Construct from dictionary
+        csvTableReader(const dictionary &dict);
+
+
+    //- Destructor
+    virtual ~csvTableReader();
+
+    //- Read the table
+    virtual void operator()(const fileName &fName,List<Tuple2<scalar, Type> > &);
+
+    //- write the remaining parameters
+    virtual void write(Ostream& os) const;
+
+    //- Construct and return a copy
+    virtual autoPtr<tableReader<Type> > clone() const
+    {
+        return autoPtr<tableReader<Type> >
+        (
+            new csvTableReader<Type>
+            (
+                *this
+            )
+        );
+    }
+
+
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#ifdef NoRepository
+#   include "csvTableReader.C"
+#endif
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReaders.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReaders.C
new file mode 100644
--- /dev/null
+++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReaders.C
@@ -0,0 +1,37 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "csvTableReader.H"
+#include "tableReaders.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    makeTableReaders(csvTableReader);
+}
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.C
new file mode 100644
--- /dev/null
+++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.C
@@ -0,0 +1,62 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "openFoamTableReader.H"
+#include "IFstream.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+template<class Type>
+Foam::openFoamTableReader<Type>::openFoamTableReader()
+{}
+
+template<class Type>
+Foam::openFoamTableReader<Type>::openFoamTableReader(const dictionary &spec)
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+template<class Type>
+Foam::openFoamTableReader<Type>::~openFoamTableReader()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+template<class Type>
+void Foam::openFoamTableReader<Type>::operator()(const fileName &fName,List<Tuple2<scalar, Type> > &data)
+{
+    // Read data from file
+    IFstream(fName)() >> data;
+}
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.H b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.H
new file mode 100644
--- /dev/null
+++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.H
@@ -0,0 +1,105 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::tableReader
+
+Description
+    Reads an interpolation table from a file - OpenFOAM-format
+
+SourceFiles
+    tableReader.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef openFoamTableReader_H
+#define openFoamTableReader_H
+
+#include "tableReader.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                           Class openFoamTableReader Declaration
+\*---------------------------------------------------------------------------*/
+
+template<class Type>
+class openFoamTableReader
+:
+    public tableReader<Type>
+{
+
+public:
+
+    //- Runtime type information
+    TypeName("openFoam");
+
+    // Constructors
+
+        //- Construct null
+        openFoamTableReader();
+
+        //- Construct from dictionary
+        openFoamTableReader(const dictionary &dict);
+
+
+    //- Destructor
+    virtual ~openFoamTableReader();
+
+    //- Read the table
+    virtual void operator()(const fileName &fName,List<Tuple2<scalar, Type> > &);
+
+    //- Construct and return a copy
+    virtual autoPtr<tableReader<Type> > clone() const
+    {
+        return autoPtr<tableReader<Type> >
+        (
+            new openFoamTableReader<Type>
+            (
+                *this
+            )
+        );
+    }
+
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#ifdef NoRepository
+#   include "openFoamTableReader.C"
+#endif
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReaders.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReaders.C
new file mode 100644
--- /dev/null
+++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReaders.C
@@ -0,0 +1,37 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "openFoamTableReader.H"
+#include "tableReaders.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    makeTableReaders(openFoamTableReader);
+}
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.C
new file mode 100644
--- /dev/null
+++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.C
@@ -0,0 +1,88 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "tableReader.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+template<class Type>
+Foam::autoPtr<Foam::tableReader<Type> > Foam::tableReader<Type>::New
+(
+    const dictionary& spec
+)
+{
+    const word readerType=spec.lookupOrDefault<word>("readerType","openFoam");
+
+    typename dictionaryConstructorTable::iterator cstrIter =
+        dictionaryConstructorTablePtr_
+            ->find(readerType);
+
+    if (cstrIter == dictionaryConstructorTablePtr_->end())
+    {
+        FatalErrorIn
+        (
+            "tableReader::New(const dictionary&)"
+        )   << "Unknown reader type " << readerType
+            << nl << nl
+            << "Valid reader types : " << nl
+            << dictionaryConstructorTablePtr_->sortedToc()
+            << exit(FatalError);
+    }
+
+    return autoPtr<tableReader<Type> >(cstrIter()(spec));
+}
+
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+template<class Type>
+Foam::tableReader<Type>::tableReader()
+{}
+
+template<class Type>
+Foam::tableReader<Type>::tableReader(const dictionary &spec)
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+template<class Type>
+Foam::tableReader<Type>::~tableReader()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+template<class Type>
+void Foam::tableReader<Type>::write(Ostream& os) const
+{
+    os.writeKeyword("readerType")
+        << this->type() << token::END_STATEMENT << nl;
+}
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.H b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.H
new file mode 100644
--- /dev/null
+++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.H
@@ -0,0 +1,122 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::tableReader
+
+Description
+    Base class to read table data for the interpolationTable
+
+SourceFiles
+    tableReader.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef tableReader_H
+#define tableReader_H
+
+#include "fileName.H"
+#include "wordList.H"
+#include "vector.H"
+#include "tensor.H"
+#include "typeInfo.H"
+#include "runTimeSelectionTables.H"
+#include "autoPtr.H"
+#include "dictionary.H"
+#include "Tuple2.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                           Class tableReader Declaration
+\*---------------------------------------------------------------------------*/
+
+template<class Type>
+class tableReader
+{
+
+public:
+
+    //- Runtime type information
+    TypeName("tableReader");
+
+    // Declare run-time constructor selection table
+
+        declareRunTimeSelectionTable
+        (
+            autoPtr,
+            tableReader,
+            dictionary,
+            (const dictionary &dict),
+            (dict)
+        );
+
+
+    // Selectors
+
+        //- Return a reference to the selected tableReader
+        static autoPtr<tableReader> New(const dictionary& spec);
+
+
+    // Constructors
+
+        //- Construct null
+        tableReader();
+
+        //- Construct from dictionary
+        tableReader(const dictionary &dict);
+
+
+    //- Destructor
+    virtual ~tableReader();
+
+    //- Read the table
+    virtual void operator()(const fileName &fName,List<Tuple2<scalar, Type> > &) = 0;
+
+    //- write additional information
+    virtual void write(Ostream& os) const;
+
+    //- Construct and return a clone
+    virtual autoPtr<tableReader<Type> > clone() const = 0;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#ifdef NoRepository
+#   include "tableReader.C"
+#endif
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.C
new file mode 100644
--- /dev/null
+++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.C
@@ -0,0 +1,49 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "tableReaders.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+#define defineTableReaderType(dataType)                                         \
+    defineNamedTemplateTypeNameAndDebug(tableReader<dataType >, 0);                \
+    defineTemplatedRunTimeSelectionTable(tableReader, dictionary, dataType);
+
+defineTableReaderType(scalar);
+defineTableReaderType(vector);
+defineTableReaderType(sphericalTensor);
+defineTableReaderType(symmTensor);
+defineTableReaderType(tensor);
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.H b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.H
new file mode 100644
--- /dev/null
+++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.H
@@ -0,0 +1,79 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+InClass
+    Foam::tableReader
+
+SourceFiles
+    tableReaders.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef tableReaders_H
+#define tableReaders_H
+
+#include "tableReader.H"
+#include "fieldTypes.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// Only used internally
+#define makeTypeTableReadersTypeName(typeTableReader, dataType)                      \
+                                                                              \
+    defineNamedTemplateTypeNameAndDebug(typeTableReader< dataType >, 0)
+
+// Sometimes used externally
+#define makeTableReadersTypeName(typeTableReader)                                    \
+                                                                              \
+    makeTypeTableReadersTypeName(typeTableReader, scalar);                           \
+    makeTypeTableReadersTypeName(typeTableReader, vector);                           \
+    makeTypeTableReadersTypeName(typeTableReader, sphericalTensor);                  \
+    makeTypeTableReadersTypeName(typeTableReader, symmTensor);                       \
+    makeTypeTableReadersTypeName(typeTableReader, tensor)
+
+// Define type info for single dataType template instantiation (eg, vector)
+#define makeTableReaderType(typeTableReader, dataType)                               \
+                                                                              \
+    defineNamedTemplateTypeNameAndDebug(typeTableReader< dataType >, 0);           \
+    addTemplatedToRunTimeSelectionTable                                       \
+    (                                                                         \
+        tableReader, typeTableReader, dataType, dictionary                                    \
+    )
+
+
+// Define type info for scalar, vector etc. instantiations
+#define makeTableReaders(typeTableReader)                                            \
+                                                                              \
+    makeTableReaderType(typeTableReader, scalar);                                    \
+    makeTableReaderType(typeTableReader, vector);                                    \
+    makeTableReaderType(typeTableReader, sphericalTensor);                           \
+    makeTableReaderType(typeTableReader, symmTensor);                                \
+    makeTableReaderType(typeTableReader, tensor)
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
