OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

writeFunctions.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "writeFunctions.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 // C++ version of fwrite_str80 from FieldView/uns/write_binary_uns.c
00034 // Write padded string of 80 char.
00035 bool writeStr80(std::ostream& os, const string& str)
00036 {
00037     char cBuf[80];
00038 
00039     memset(cBuf, '\0', 80);
00040 
00041     int len = str.size();
00042 
00043     strncpy(cBuf, str.c_str(), (len < 80 ? len : 80));
00044 
00045     os.write(cBuf, 80*sizeof(char));
00046 
00047     return os.good();
00048 }
00049 
00050 
00051 // Write single integer
00052 bool writeInt(std::ostream& os, int val1)
00053 {
00054     os.write(reinterpret_cast<char*>(&val1), sizeof(int));
00055 
00056     return os.good();
00057 }
00058 
00059 
00060 // Write single float
00061 bool writeFloat(std::ostream& os, scalar val1)
00062 {
00063     float floatVal = val1;
00064 
00065     os.write(reinterpret_cast<char*>(&floatVal), sizeof(float));
00066 
00067     return os.good();
00068 }
00069 
00070 
00071 // Debug: write raw bytes
00072 void writeBytes(char* start, int nBytes)
00073 {
00074     cout.setf(std::ios::hex, std::ios::basefield);
00075 
00076     cout<< start << " : ";
00077 
00078     for(int i = 0; i < nBytes; i++)
00079     {
00080         cout<< " " << start[i];
00081     }
00082     cout << std::endl;
00083 
00084     cout.setf(std::ios::dec);
00085 }
00086 
00087 
00088 // Debug: write wall flags data
00089 void writeWallFlags(Ostream& os, label cellI, const labelList& wallFlags)
00090 {
00091     os << "cell " << cellI << " wallsFlags:";
00092     forAll(wallFlags, wallFaceI)
00093     {
00094         os << wallFlags[wallFaceI] << " ";
00095     }
00096     os << endl;
00097 }
00098 
00099 
00100 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd