2013-03-03 00:42:56 +01:00
|
|
|
/*+
|
2014-05-22 09:38:59 +02:00
|
|
|
This is CosmoTool (./src/fortran.hpp) -- Copyright (C) Guilhem Lavaux (2007-2014)
|
2013-03-03 00:42:56 +01:00
|
|
|
|
|
|
|
guilhem.lavaux@gmail.com
|
|
|
|
|
|
|
|
This software is a computer program whose purpose is to provide a toolbox for cosmological
|
|
|
|
data analysis (e.g. filters, generalized Fourier transforms, power spectra, ...)
|
|
|
|
|
|
|
|
This software is governed by the CeCILL license under French law and
|
|
|
|
abiding by the rules of distribution of free software. You can use,
|
|
|
|
modify and/ or redistribute the software under the terms of the CeCILL
|
|
|
|
license as circulated by CEA, CNRS and INRIA at the following URL
|
|
|
|
"http://www.cecill.info".
|
|
|
|
|
|
|
|
As a counterpart to the access to the source code and rights to copy,
|
|
|
|
modify and redistribute granted by the license, users are provided only
|
|
|
|
with a limited warranty and the software's author, the holder of the
|
|
|
|
economic rights, and the successive licensors have only limited
|
|
|
|
liability.
|
|
|
|
|
|
|
|
In this respect, the user's attention is drawn to the risks associated
|
|
|
|
with loading, using, modifying and/or developing or reproducing the
|
|
|
|
software by the user in light of its specific status of free software,
|
|
|
|
that may mean that it is complicated to manipulate, and that also
|
|
|
|
therefore means that it is reserved for developers and experienced
|
|
|
|
professionals having in-depth computer knowledge. Users are therefore
|
|
|
|
encouraged to load and test the software's suitability as regards their
|
|
|
|
requirements in conditions enabling the security of their systems and/or
|
|
|
|
data to be ensured and, more generally, to use and operate it in the
|
|
|
|
same conditions as regards security.
|
|
|
|
|
|
|
|
The fact that you are presently reading this means that you have had
|
|
|
|
knowledge of the CeCILL license and that you accept its terms.
|
|
|
|
+*/
|
2013-03-06 04:39:33 +01:00
|
|
|
|
2009-01-08 16:17:32 +01:00
|
|
|
#ifndef __COSMO_FORTRAN_HPP
|
|
|
|
#define __COSMO_FORTRAN_HPP
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include "config.hpp"
|
|
|
|
|
|
|
|
namespace CosmoTool
|
|
|
|
{
|
|
|
|
class InvalidUnformattedAccess : public Exception
|
|
|
|
{
|
2017-05-05 09:09:51 +02:00
|
|
|
public:
|
|
|
|
InvalidUnformattedAccess()
|
|
|
|
: Exception("Invalid unformatted fortran file format") {}
|
2009-01-08 16:17:32 +01:00
|
|
|
};
|
|
|
|
|
2009-08-26 18:54:26 +02:00
|
|
|
class FortranTypes
|
2009-01-08 16:17:32 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Ordering {
|
|
|
|
LittleEndian, BigEndian
|
|
|
|
};
|
|
|
|
|
|
|
|
enum CheckpointSize {
|
|
|
|
Check_32bits, Check_64bits
|
|
|
|
};
|
2009-08-26 18:54:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class UnformattedRead: public FortranTypes
|
|
|
|
{
|
|
|
|
public:
|
2009-01-08 16:17:32 +01:00
|
|
|
|
|
|
|
UnformattedRead(const std::string& fname)
|
2009-01-10 02:11:05 +01:00
|
|
|
throw (NoSuchFileException);
|
2009-01-08 16:17:32 +01:00
|
|
|
UnformattedRead(const char *fname)
|
2009-01-10 02:11:05 +01:00
|
|
|
throw (NoSuchFileException);
|
2009-01-08 16:17:32 +01:00
|
|
|
~UnformattedRead();
|
|
|
|
|
|
|
|
// Todo implement primitive description
|
|
|
|
void setOrdering(Ordering o);
|
|
|
|
void setCheckpointSize(CheckpointSize cs);
|
2015-06-03 10:31:09 +02:00
|
|
|
|
|
|
|
uint64_t getBlockSize() const { return checkPointRef; }
|
2009-01-08 16:17:32 +01:00
|
|
|
|
2017-05-13 15:25:18 +02:00
|
|
|
void beginCheckpoint(bool bufferRecord = false)
|
2009-01-08 16:17:32 +01:00
|
|
|
throw (InvalidUnformattedAccess,EndOfFileException);
|
2010-04-23 09:31:25 +02:00
|
|
|
void endCheckpoint(bool autodrop = false)
|
2009-01-08 16:17:32 +01:00
|
|
|
throw (InvalidUnformattedAccess);
|
|
|
|
|
|
|
|
double readReal64()
|
|
|
|
throw (InvalidUnformattedAccess);
|
|
|
|
float readReal32()
|
|
|
|
throw (InvalidUnformattedAccess);
|
2015-06-03 10:31:09 +02:00
|
|
|
uint32_t readUint32()
|
|
|
|
throw (InvalidUnformattedAccess);
|
2009-01-08 16:17:32 +01:00
|
|
|
int32_t readInt32()
|
|
|
|
throw (InvalidUnformattedAccess);
|
|
|
|
int64_t readInt64()
|
|
|
|
throw (InvalidUnformattedAccess);
|
|
|
|
|
2010-04-23 09:31:25 +02:00
|
|
|
void skip(int64_t off)
|
|
|
|
throw (InvalidUnformattedAccess);
|
|
|
|
|
2016-01-26 22:59:35 +01:00
|
|
|
int64_t position() const;
|
|
|
|
void seek(int64_t pos);
|
|
|
|
|
|
|
|
void readOrderedBuffer(void *buffer, int size)
|
|
|
|
throw (InvalidUnformattedAccess);
|
2009-01-08 16:17:32 +01:00
|
|
|
protected:
|
|
|
|
bool swapOrdering;
|
|
|
|
CheckpointSize cSize;
|
|
|
|
uint64_t checkPointRef;
|
|
|
|
uint64_t checkPointAccum;
|
|
|
|
std::ifstream *f;
|
2017-05-13 15:25:18 +02:00
|
|
|
uint8_t *recordBuffer;
|
2009-01-08 16:17:32 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-08-26 18:54:26 +02:00
|
|
|
class UnformattedWrite: public FortranTypes
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
UnformattedWrite(const std::string& fname)
|
|
|
|
throw (NoSuchFileException);
|
|
|
|
UnformattedWrite(const char *fname)
|
|
|
|
throw (NoSuchFileException);
|
|
|
|
~UnformattedWrite();
|
|
|
|
|
|
|
|
// Todo implement primitive description
|
|
|
|
void setOrdering(Ordering o);
|
|
|
|
void setCheckpointSize(CheckpointSize cs);
|
|
|
|
|
|
|
|
void beginCheckpoint()
|
|
|
|
throw (FilesystemFullException,InvalidUnformattedAccess);
|
|
|
|
void endCheckpoint()
|
|
|
|
throw (FilesystemFullException,InvalidUnformattedAccess);
|
|
|
|
|
|
|
|
void writeReal64(double d)
|
|
|
|
throw (FilesystemFullException);
|
|
|
|
void writeReal32(float f)
|
|
|
|
throw (FilesystemFullException);
|
|
|
|
void writeInt32(int32_t i)
|
|
|
|
throw (FilesystemFullException);
|
|
|
|
void writeInt64(int64_t i)
|
|
|
|
throw (FilesystemFullException);
|
2012-04-02 00:49:19 +02:00
|
|
|
void writeInt8(int8_t c)
|
|
|
|
throw (FilesystemFullException);
|
2009-08-26 18:54:26 +02:00
|
|
|
|
2012-04-02 00:49:19 +02:00
|
|
|
void writeOrderedBuffer(void *buffer, int size)
|
|
|
|
throw(FilesystemFullException);
|
2009-08-26 18:54:26 +02:00
|
|
|
protected:
|
|
|
|
bool swapOrdering;
|
|
|
|
CheckpointSize cSize;
|
|
|
|
std::streamoff checkPointRef;
|
|
|
|
uint64_t checkPointAccum;
|
|
|
|
std::ofstream *f;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-01-08 16:17:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|