# HG changeset patch
# Parent 3702c3466a23e58b7eea748b70b2fd8fed4c104e

diff --git a/src/sampling/Make/files b/src/sampling/Make/files
--- a/src/sampling/Make/files
+++ b/src/sampling/Make/files
@@ -1,5 +1,7 @@
 probes/probes.C
+probes/csvProbes.C
 probes/probesFunctionObject.C
+probes/csvProbesFunctionObject.C
 
 sampledSet/coordSet/coordSet.C
 sampledSet/sampledSet/sampledSet.C
diff --git a/src/sampling/probes/probes.C b/src/sampling/probes/csvProbes.C
copy from src/sampling/probes/probes.C
copy to src/sampling/probes/csvProbes.C
--- a/src/sampling/probes/probes.C
+++ b/src/sampling/probes/csvProbes.C
@@ -23,7 +23,7 @@
 
 \*---------------------------------------------------------------------------*/
 
-#include "probes.H"
+#include "csvProbes.H"
 #include "volFields.H"
 #include "dictionary.H"
 #include "Time.H"
@@ -33,247 +33,15 @@
 
 namespace Foam
 {
-    defineTypeNameAndDebug(probes, 0);
+    defineTypeNameAndDebug(csvProbes, 0);
 }
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-void Foam::probes::findCells(const fvMesh& mesh)
-{
-    if (cellList_.empty())
-    {
-        cellList_.setSize(probeLocations_.size());
-
-        forAll(probeLocations_, probeI)
-        {
-            cellList_[probeI] = mesh.findCell(probeLocations_[probeI]);
-
-            if (debug && cellList_[probeI] != -1)
-            {
-                Pout<< "probes : found point " << probeLocations_[probeI]
-                    << " in cell " << cellList_[probeI] << endl;
-            }
-        }
-
-
-        // Check if all probes have been found.
-        forAll(cellList_, probeI)
-        {
-            label cellI = cellList_[probeI];
-
-            // Check at least one processor with cell.
-            reduce(cellI, maxOp<label>());
-
-            if (cellI == -1)
-            {
-                if (Pstream::master())
-                {
-                    WarningIn("probes::read()")
-                        << "Did not find location " << probeLocations_[probeI]
-                        << " in any cell. Skipping location." << endl;
-                }
-            }
-            else
-            {
-                // Make sure location not on two domains.
-                if (cellList_[probeI] != -1 && cellList_[probeI] != cellI)
-                {
-                    WarningIn("probes::read()")
-                        << "Location " << probeLocations_[probeI]
-                        << " seems to be on multiple domains:"
-                        << " cell " << cellList_[probeI]
-                        << " on my domain " << Pstream::myProcNo()
-                        << " and cell " << cellI << " on some other domain."
-                        << endl
-                        << "This might happen if the probe location is on"
-                        << " a processor patch. Change the location slightly"
-                        << " to prevent this." << endl;
-                }
-            }
-        }
-    }
-}
-
-
-bool Foam::probes::checkFieldTypes()
-{
-    wordList fieldTypes(fieldNames_.size());
-
-    // check files for a particular time
-    if (loadFromFiles_)
-    {
-        forAll(fieldNames_, fieldI)
-        {
-            IOobject io
-            (
-                fieldNames_[fieldI],
-                obr_.time().timeName(),
-                refCast<const polyMesh>(obr_),
-                IOobject::MUST_READ,
-                IOobject::NO_WRITE,
-                false
-            );
-
-            if (io.headerOk())
-            {
-                fieldTypes[fieldI] = io.headerClassName();
-            }
-            else
-            {
-                fieldTypes[fieldI] = "(notFound)";
-            }
-        }
-    }
-    else
-    {
-        // check objectRegistry
-        forAll(fieldNames_, fieldI)
-        {
-            objectRegistry::const_iterator iter =
-                obr_.find(fieldNames_[fieldI]);
-
-            if (iter != obr_.end())
-            {
-                fieldTypes[fieldI] = iter()->type();
-            }
-            else
-            {
-                fieldTypes[fieldI] = "(notFound)";
-            }
-        }
-    }
-
-
-    label nFields = 0;
-
-    // classify fieldTypes
-    nFields += countFields(scalarFields_, fieldTypes);
-    nFields += countFields(vectorFields_, fieldTypes);
-    nFields += countFields(sphericalTensorFields_, fieldTypes);
-    nFields += countFields(symmTensorFields_, fieldTypes);
-    nFields += countFields(tensorFields_, fieldTypes);
-
-    // concatenate all the lists into foundFields
-    wordList foundFields(nFields);
-
-    label fieldI = 0;
-    forAll(scalarFields_, i)
-    {
-        foundFields[fieldI++] = scalarFields_[i];
-    }
-    forAll(vectorFields_, i)
-    {
-        foundFields[fieldI++] = vectorFields_[i];
-    }
-    forAll(sphericalTensorFields_, i)
-    {
-        foundFields[fieldI++] = sphericalTensorFields_[i];
-    }
-    forAll(symmTensorFields_, i)
-    {
-        foundFields[fieldI++] = symmTensorFields_[i];
-    }
-    forAll(tensorFields_, i)
-    {
-        foundFields[fieldI++] = tensorFields_[i];
-    }
-
-    if (Pstream::master())
-    {
-        fileName probeDir;
-
-        fileName probeSubDir = name_;
-
-        if (obr_.name() != polyMesh::defaultRegion)
-        {
-            probeSubDir = probeSubDir/obr_.name();
-        }
-        probeSubDir = probeSubDir/obr_.time().timeName();
-
-        if (Pstream::parRun())
-        {
-            // Put in undecomposed case
-            // (Note: gives problems for distributed data running)
-            probeDir = obr_.time().path()/".."/probeSubDir;
-        }
-        else
-        {
-            probeDir = obr_.time().path()/probeSubDir;
-        }
-
-        // Close the file if any fields have been removed.
-        forAllIter(HashPtrTable<OFstream>, probeFilePtrs_, iter)
-        {
-            if (findIndex(foundFields, iter.key()) == -1)
-            {
-                if (debug)
-                {
-                    Pout<< "close stream: " << iter()->name() << endl;
-                }
-
-                delete probeFilePtrs_.remove(iter);
-            }
-        }
-
-        // Open new files for new fields. Keep existing files.
-
-        probeFilePtrs_.resize(2*foundFields.size());
-
-        forAll(foundFields, fieldI)
-        {
-            const word& fldName = foundFields[fieldI];
-
-            // Check if added field. If so open a stream for it.
-
-            if (!probeFilePtrs_.found(fldName))
-            {
-                // Create directory if does not exist.
-                mkDir(probeDir);
-
-                OFstream* sPtr = new OFstream(probeDir/fldName);
-
-                if (debug)
-                {
-                    Pout<< "open  stream: " << sPtr->name() << endl;
-                }
-
-                probeFilePtrs_.insert(fldName, sPtr);
-
-                unsigned int w = IOstream::defaultPrecision() + 7;
-
-                for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
-                {
-                    *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
-                        << vector::componentNames[cmpt];
-
-                    forAll(probeLocations_, probeI)
-                    {
-                        *sPtr<< ' ' << setw(w) << probeLocations_[probeI][cmpt];
-                    }
-                    *sPtr << endl;
-                }
-
-                *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
-                    << "Time" << endl;
-            }
-        }
-
-        if (debug)
-        {
-            Pout<< "Probing fields:" << foundFields << nl
-                << "Probing locations:" << probeLocations_ << nl
-                << endl;
-        }
-    }
-
-
-    return nFields > 0;
-}
-
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-Foam::probes::probes
+Foam::csvProbes::csvProbes
 (
     const word& name,
     const objectRegistry& obr,
@@ -281,18 +49,13 @@
     const bool loadFromFiles
 )
 :
-    name_(name),
-    obr_(obr),
-    loadFromFiles_(loadFromFiles),
-    fieldNames_(0),
-    probeLocations_(0),
-    scalarFields_(),
-    vectorFields_(),
-    sphericalTensorFields_(),
-    symmTensorFields_(),
-    tensorFields_(),
-    cellList_(0),
-    probeFilePtrs_(0)
+    probes(
+        name,
+        obr,
+        dict,
+        ".csv",
+        loadFromFiles
+    )
 {
     read(dict);
 }
@@ -300,25 +63,13 @@
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
-Foam::probes::~probes()
+Foam::csvProbes::~csvProbes()
 {}
 
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-void Foam::probes::execute()
-{
-    // Do nothing - only valid on write
-}
-
-
-void Foam::probes::end()
-{
-    // Do nothing - only valid on write
-}
-
-
-void Foam::probes::write()
+void Foam::csvProbes::write()
 {
     if (probeLocations_.size() && checkFieldTypes())
     {
@@ -331,16 +82,4 @@
 }
 
 
-void Foam::probes::read(const dictionary& dict)
-{
-    dict.lookup("fields") >> fieldNames_;
-    dict.lookup("probeLocations") >> probeLocations_;
-
-    // Force all cell locations to be redetermined
-    cellList_.clear();
-    findCells(refCast<const fvMesh>(obr_));
-    checkFieldTypes();
-}
-
-
 // ************************************************************************* //
diff --git a/src/sampling/probes/probes.H b/src/sampling/probes/csvProbes.H
copy from src/sampling/probes/probes.H
copy to src/sampling/probes/csvProbes.H
--- a/src/sampling/probes/probes.H
+++ b/src/sampling/probes/csvProbes.H
@@ -22,7 +22,7 @@
     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
 
 Class
-    Foam::probes
+    Foam::csvProbes
 
 Description
     Set of locations to sample.
@@ -30,113 +30,28 @@
     Call write() to sample and write files.
 
 SourceFiles
-    probes.C
+    csvProbes.C
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef probes_H
-#define probes_H
+#ifndef csvProbes_H
+#define csvProbes_H
 
-#include "HashPtrTable.H"
-#include "OFstream.H"
-#include "polyMesh.H"
-#include "pointField.H"
-#include "volFieldsFwd.H"
+#include "probes.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
 {
 
-// Forward declaration of classes
-class objectRegistry;
-class dictionary;
-class fvMesh;
-class mapPolyMesh;
-
 /*---------------------------------------------------------------------------*\
-                          Class probes Declaration
+                          Class csvProbes Declaration
 \*---------------------------------------------------------------------------*/
 
-class probes
+class csvProbes
+:
+    public probes
 {
-    // Private classes
-
-        //- Class used for grouping field types
-        template<class Type>
-        class fieldGroup
-        :
-            public wordList
-        {
-        public:
-            //- Construct null
-            fieldGroup()
-            :
-                wordList()
-            {}
-
-            //- Construct for a list of field names
-            fieldGroup(const wordList& fieldNames)
-            :
-                wordList(fieldNames)
-            {}
-        };
-
-
-    // Private data
-
-        //- Name of this set of probes,
-        //  Also used as the name of the probes directory.
-        word name_;
-
-        //- Const reference to objectRegistry
-        const objectRegistry& obr_;
-
-        //- Load fields from files (not from objectRegistry)
-        bool loadFromFiles_;
-
-
-        // Read from dictonary
-
-            //- Names of fields to probe
-            wordList fieldNames_;
-
-            //- Locations to probe
-            vectorField probeLocations_;
-
-
-        // Calculated
-
-            //- Categorized scalar/vector/tensor fields
-            fieldGroup<scalar> scalarFields_;
-            fieldGroup<vector> vectorFields_;
-            fieldGroup<sphericalTensor> sphericalTensorFields_;
-            fieldGroup<symmTensor> symmTensorFields_;
-            fieldGroup<tensor> tensorFields_;
-
-            // Cells to be probed (obtained from the locations)
-            labelList cellList_;
-
-            //- Current open files
-            HashPtrTable<OFstream> probeFilePtrs_;
-
-
-    // Private Member Functions
-
-        //- Find cells containing probes
-        void findCells(const fvMesh&);
-
-        //- classify field types, return true if nFields > 0
-        bool checkFieldTypes();
-
-        //- Find the fields in the list of the given type, return count
-        template<class Type>
-        label countFields
-        (
-            fieldGroup<Type>& fieldList,
-            const wordList& fieldTypes
-        ) const;
-
         //- Sample and write a particular volume field
         template<class Type>
         void sampleAndWrite
@@ -149,23 +64,26 @@
         void sampleAndWrite(const fieldGroup<Type>&);
 
         //- Disallow default bitwise copy construct
-        probes(const probes&);
+        csvProbes(const csvProbes&);
 
         //- Disallow default bitwise assignment
-        void operator=(const probes&);
+        void operator=(const csvProbes&);
 
+        //- write the probe-Header
+         template<class T>
+         void writeCSVProbeHeader(Ostream &out);
 
 public:
 
     //- Runtime type information
-    TypeName("probes");
+    TypeName("csvProbes");
 
 
     // Constructors
 
         //- Construct for given objectRegistry and dictionary.
         //  Allow the possibility to load fields from files
-        probes
+        csvProbes
         (
             const word& name,
             const objectRegistry&,
@@ -175,69 +93,15 @@
 
 
     //- Destructor
-    virtual ~probes();
+    virtual ~csvProbes();
 
 
     // Member Functions
 
-        //- Return name of the set of probes
-        virtual const word& name() const
-        {
-            return name_;
-        }
-
-        //- Return names of fields to probe
-        virtual const wordList& fieldNames() const
-        {
-            return fieldNames_;
-        }
-
-        //- Return locations to probe
-        virtual const vectorField& probeLocations() const
-        {
-            return probeLocations_;
-        }
-
-        //- Cells to be probed (obtained from the locations)
-        const labelList& cells() const
-        {
-            return cellList_;
-        }
-
-        //- Execute, currently does nothing
-        virtual void execute();
-
-        //- Execute at the final time-loop, currently does nothing
-        virtual void end();
 
         //- Sample and write
         virtual void write();
 
-        //- Read the probes
-        virtual void read(const dictionary&);
-
-        //- Update for changes of mesh
-        virtual void updateMesh(const mapPolyMesh&)
-        {}
-
-        //- Update for changes of mesh
-        virtual void movePoints(const pointField&)
-        {}
-
-        //- Update for changes of mesh due to readUpdate
-        virtual void readUpdate(const polyMesh::readUpdateState state)
-        {}
-
-        //- Sample a volume field at all locations
-        template<class Type>
-        tmp<Field<Type> > sample
-        (
-            const GeometricField<Type, fvPatchField, volMesh>&
-        ) const;
-
-        //- Sample a single field on all sample locations
-        template <class Type>
-        tmp<Field<Type> > sample(const word& fieldName) const;
 };
 
 
@@ -248,7 +112,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 #ifdef NoRepository
-#   include "probesTemplates.C"
+#   include "csvProbesTemplates.C"
 #endif
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/sampling/probes/probesFunctionObject.C b/src/sampling/probes/csvProbesFunctionObject.C
copy from src/sampling/probes/probesFunctionObject.C
copy to src/sampling/probes/csvProbesFunctionObject.C
--- a/src/sampling/probes/probesFunctionObject.C
+++ b/src/sampling/probes/csvProbesFunctionObject.C
@@ -23,18 +23,18 @@
 
 \*---------------------------------------------------------------------------*/
 
-#include "probesFunctionObject.H"
+#include "csvProbesFunctionObject.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 namespace Foam
 {
-    defineNamedTemplateTypeNameAndDebug(probesFunctionObject, 0);
+    defineNamedTemplateTypeNameAndDebug(csvProbesFunctionObject, 0);
 
     addToRunTimeSelectionTable
     (
         functionObject,
-        probesFunctionObject,
+        csvProbesFunctionObject,
         dictionary
     );
 }
diff --git a/src/sampling/probes/probesFunctionObject.H b/src/sampling/probes/csvProbesFunctionObject.H
copy from src/sampling/probes/probesFunctionObject.H
copy to src/sampling/probes/csvProbesFunctionObject.H
--- a/src/sampling/probes/probesFunctionObject.H
+++ b/src/sampling/probes/csvProbesFunctionObject.H
@@ -22,28 +22,28 @@
     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
 
 Typedef
-    Foam::probesFunctionObject
+    Foam::csvProbesFunctionObject
 
 Description
-    FunctionObject wrapper around probes to allow them to be created via the
+    FunctionObject wrapper around csvProbes to allow them to be created via the
     functions list within controlDict.
 
 SourceFiles
-    probesFunctionObject.C
+    csvProbesFunctionObject.C
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef probesFunctionObject_H
-#define probesFunctionObject_H
+#ifndef csvProbesFunctionObject_H
+#define csvProbesFunctionObject_H
 
-#include "probes.H"
+#include "csvProbes.H"
 #include "OutputFilterFunctionObject.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
 {
-    typedef OutputFilterFunctionObject<probes> probesFunctionObject;
+    typedef OutputFilterFunctionObject<csvProbes> csvProbesFunctionObject;
 }
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/sampling/probes/probesTemplates.C b/src/sampling/probes/csvProbesTemplates.C
copy from src/sampling/probes/probesTemplates.C
copy to src/sampling/probes/csvProbesTemplates.C
--- a/src/sampling/probes/probesTemplates.C
+++ b/src/sampling/probes/csvProbesTemplates.C
@@ -23,7 +23,7 @@
 
 \*---------------------------------------------------------------------------*/
 
-#include "probes.H"
+#include "csvProbes.H"
 #include "volFields.H"
 #include "IOmanip.H"
 
@@ -32,67 +32,72 @@
 namespace Foam
 {
 
-//- comparison operator for probes class
-template<class T>
-class isNotEqOp
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+template<>
+inline void Foam::csvProbes::writeCSVProbeHeader<scalar>(Ostream &out)
 {
-public:
+    out << "Time";
+        
+    forAll(probeLocations_, probeI)
+    {
+        out << ",@" << probeLocations_[probeI];
+    }
 
-    void operator()(T& x, const T& y) const
-    {
-        const T unsetVal(-VGREAT*pTraits<T>::one);
-
-        if (x != unsetVal)
-        {
-            // Keep x.
-
-            // Note:chould check for y != unsetVal but multiple sample cells
-            // already handled in read().
-        }
-        else
-        {
-            // x is not set. y might be.
-            x = y;
-        }
-    }
-};
-
+    out << endl;
 }
 
-
-// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
-
 template<class Type>
-Foam::label Foam::probes::countFields
-(
-    fieldGroup<Type>& fieldList,
-    const wordList& fieldTypes
-) const
+void Foam::csvProbes::writeCSVProbeHeader(Ostream &out)
 {
-    fieldList.setSize(fieldNames_.size());
-    label nFields = 0;
-
-    forAll(fieldNames_, fieldI)
+    out << "Time";
+        
+    forAll(probeLocations_, probeI)
     {
-        if
-        (
-            fieldTypes[fieldI]
-         == GeometricField<Type, fvPatchField, volMesh>::typeName
-        )
-        {
-            fieldList[nFields] = fieldNames_[fieldI];
-            nFields++;
+        for(label j=0;j<Type::nComponents;j++) {
+            out << "," << Type::componentNames[j]
+                << "@" << probeLocations_[probeI] ;
         }
     }
 
-    fieldList.setSize(nFields);
-
-    return nFields;
+    out << endl;
 }
 
+template<>
+inline void Foam::csvProbes::sampleAndWrite
+(
+    const GeometricField<scalar, fvPatchField, volMesh>& vField
+)
+{
+    Field<scalar> values = sample(vField);
+
+    if (Pstream::master())
+    {
+        // formatting pretty throws some Spreadsheets off the track
+        //        unsigned int w = IOstream::defaultPrecision() + 7;
+
+        OFstream& probeStream = *probeFilePtrs_[vField.name()];
+        if( !probeFileHasHeader_.found(vField.name()) ) 
+        {
+            probeFileHasHeader_.insert(vField.name());
+            writeCSVProbeHeader<scalar>(probeStream);
+        }
+
+        //        probeStream << setw(w) << vField.time().value();
+        probeStream << vField.time().value();
+
+        forAll(values, probeI)
+        {
+            //            probeStream << ',' << setw(w) << values[probeI];
+            probeStream << ',' << values[probeI];
+        }
+        probeStream << endl;
+    }
+}
+
 
 template<class Type>
-void Foam::probes::sampleAndWrite
+void Foam::csvProbes::sampleAndWrite
 (
     const GeometricField<Type, fvPatchField, volMesh>& vField
 )
@@ -101,14 +106,24 @@
 
     if (Pstream::master())
     {
-        unsigned int w = IOstream::defaultPrecision() + 7;
+        //        unsigned int w = IOstream::defaultPrecision() + 7;
+
         OFstream& probeStream = *probeFilePtrs_[vField.name()];
+        if( !probeFileHasHeader_.found(vField.name()) ) 
+        {
+            probeFileHasHeader_.insert(vField.name());
+            writeCSVProbeHeader<Type>(probeStream);
+        }
 
-        probeStream << setw(w) << vField.time().value();
+        //        probeStream  << setw(w) << vField.time().value();
+        probeStream << vField.time().value();
 
         forAll(values, probeI)
         {
-            probeStream << ' ' << setw(w) << values[probeI];
+            for(label j=0;j<Type::nComponents;j++) {
+                //                probeStream << ',' << setw(w) << values[probeI][j];
+                probeStream << ',' << values[probeI][j];
+            }
         }
         probeStream << endl;
     }
@@ -116,7 +131,7 @@
 
 
 template <class Type>
-void Foam::probes::sampleAndWrite
+void Foam::csvProbes::sampleAndWrite
 (
     const fieldGroup<Type>& fields
 )
@@ -169,49 +184,6 @@
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-template<class Type>
-Foam::tmp<Foam::Field<Type> >
-Foam::probes::sample
-(
-    const GeometricField<Type, fvPatchField, volMesh>& vField
-) const
-{
-    const Type unsetVal(-VGREAT*pTraits<Type>::one);
-
-    tmp<Field<Type> > tValues
-    (
-        new Field<Type>(probeLocations_.size(), unsetVal)
-    );
-
-    Field<Type>& values = tValues();
-
-    forAll(probeLocations_, probeI)
-    {
-        if (cellList_[probeI] >= 0)
-        {
-            values[probeI] = vField[cellList_[probeI]];
-        }
-    }
-
-    Pstream::listCombineGather(values, isNotEqOp<Type>());
-    Pstream::listCombineScatter(values);
-
-    return tValues;
 }
 
-
-template<class Type>
-Foam::tmp<Foam::Field<Type> >
-Foam::probes::sample(const word& fieldName) const
-{
-    return sample
-    (
-        obr_.lookupObject<GeometricField<Type, fvPatchField, volMesh> >
-        (
-            fieldName
-        )
-    );
-}
-
-
 // ************************************************************************* //
diff --git a/src/sampling/probes/probes.C b/src/sampling/probes/probes.C
--- a/src/sampling/probes/probes.C
+++ b/src/sampling/probes/probes.C
@@ -178,6 +178,13 @@
         foundFields[fieldI++] = tensorFields_[i];
     }
 
+    createFiles(foundFields);
+
+    return nFields > 0;
+}
+
+void Foam::probes::createFiles(const wordList &foundFields)
+{
     if (Pstream::master())
     {
         fileName probeDir;
@@ -206,6 +213,10 @@
         {
             if (findIndex(foundFields, iter.key()) == -1)
             {
+                if(probeFileHasHeader_.found(iter.key())) {
+                    probeFileHasHeader_.erase(iter.key());
+                }
+
                 if (debug)
                 {
                     Pout<< "close stream: " << iter()->name() << endl;
@@ -230,7 +241,7 @@
                 // Create directory if does not exist.
                 mkDir(probeDir);
 
-                OFstream* sPtr = new OFstream(probeDir/fldName);
+                OFstream* sPtr = new OFstream(probeDir/fldName+fileExtension_);
 
                 if (debug)
                 {
@@ -238,23 +249,6 @@
                 }
 
                 probeFilePtrs_.insert(fldName, sPtr);
-
-                unsigned int w = IOstream::defaultPrecision() + 7;
-
-                for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
-                {
-                    *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
-                        << vector::componentNames[cmpt];
-
-                    forAll(probeLocations_, probeI)
-                    {
-                        *sPtr<< ' ' << setw(w) << probeLocations_[probeI][cmpt];
-                    }
-                    *sPtr << endl;
-                }
-
-                *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
-                    << "Time" << endl;
             }
         }
 
@@ -265,11 +259,27 @@
                 << endl;
         }
     }
-
-
-    return nFields > 0;
 }
 
+void Foam::probes::writeProbeHeader(Ostream &out)
+{
+    unsigned int w = IOstream::defaultPrecision() + 7;
+    
+    for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
+    {
+        out << '#' << setw(IOstream::defaultPrecision() + 6)
+            << vector::componentNames[cmpt];
+        
+        forAll(probeLocations_, probeI)
+        {
+            out << ' ' << setw(w) << probeLocations_[probeI][cmpt];
+        }
+        out << endl;
+    }
+    
+    out << '#' << setw(IOstream::defaultPrecision() + 6)
+        << "Time" << endl;
+}
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
@@ -297,6 +307,31 @@
     read(dict);
 }
 
+Foam::probes::probes
+(
+    const word& name,
+    const objectRegistry& obr,
+    const dictionary& dict,
+    const word &extension,
+    const bool loadFromFiles
+)
+:
+    fileExtension_(extension),
+    name_(name),
+    obr_(obr),
+    loadFromFiles_(loadFromFiles),
+    fieldNames_(0),
+    probeLocations_(0),
+    scalarFields_(),
+    vectorFields_(),
+    sphericalTensorFields_(),
+    symmTensorFields_(),
+    tensorFields_(),
+    cellList_(0),
+    probeFilePtrs_(0)
+{
+}
+
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
@@ -339,7 +374,8 @@
     // Force all cell locations to be redetermined
     cellList_.clear();
     findCells(refCast<const fvMesh>(obr_));
-    checkFieldTypes();
+
+    checkFieldTypes(); 
 }
 
 
diff --git a/src/sampling/probes/probes.H b/src/sampling/probes/probes.H
--- a/src/sampling/probes/probes.H
+++ b/src/sampling/probes/probes.H
@@ -82,9 +82,15 @@
             {}
         };
 
+    //- write the probe-Header
+    void writeProbeHeader(Ostream &out);
 
     // Private data
 
+    //- extension for written files
+    word fileExtension_;
+protected:
+
         //- Name of this set of probes,
         //  Also used as the name of the probes directory.
         word name_;
@@ -120,15 +126,14 @@
             //- Current open files
             HashPtrTable<OFstream> probeFilePtrs_;
 
+            //- Has this file a header?
+            HashSet<word> probeFileHasHeader_;
 
     // Private Member Functions
 
         //- Find cells containing probes
         void findCells(const fvMesh&);
 
-        //- classify field types, return true if nFields > 0
-        bool checkFieldTypes();
-
         //- Find the fields in the list of the given type, return count
         template<class Type>
         label countFields
@@ -148,12 +153,33 @@
         template <class Type>
         void sampleAndWrite(const fieldGroup<Type>&);
 
+        //- Construct for given objectRegistry and dictionary.
+        //  Allow the possibility to load fields from files.
+        // to be used by subclasses
+        probes
+        (
+            const word& name,
+            const objectRegistry&,
+            const dictionary&,
+            const word &extension,
+            const bool loadFromFiles = false
+        );
+
+private:
+
         //- Disallow default bitwise copy construct
         probes(const probes&);
 
         //- Disallow default bitwise assignment
         void operator=(const probes&);
 
+protected:
+
+        //- classify field types, return true if nFields > 0
+        bool checkFieldTypes();
+
+        //- create the files
+        void createFiles(const wordList &foundFields);
 
 public:
 
diff --git a/src/sampling/probes/probesTemplates.C b/src/sampling/probes/probesTemplates.C
--- a/src/sampling/probes/probesTemplates.C
+++ b/src/sampling/probes/probesTemplates.C
@@ -104,6 +104,11 @@
         unsigned int w = IOstream::defaultPrecision() + 7;
         OFstream& probeStream = *probeFilePtrs_[vField.name()];
 
+        if( !probeFileHasHeader_.found(vField.name()) ) 
+        {
+            probeFileHasHeader_.insert(vField.name());
+            writeProbeHeader(probeStream);
+        }
         probeStream << setw(w) << vField.time().value();
 
         forAll(values, probeI)
