Skip to content

Commit

Permalink
style: run clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
k-doering-NOAA authored Aug 16, 2023
1 parent bfc6289 commit 9edd6fa
Show file tree
Hide file tree
Showing 35 changed files with 3,598 additions and 2,674 deletions.
177 changes: 115 additions & 62 deletions inst/include/common/data_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
* Fisheries Integrated Modeling System project.
*
* This software is a "United States Government Work" under the terms of the
* United States Copyright Act. It was written as part of the author's official
* duties as a United States Government employee and thus cannot be copyrighted.
* This software is freely available to the public for use. The National Oceanic
* And Atmospheric Administration and the U.S. Government have not placed any
* restriction on its use or reproduction. Although all reasonable efforts have
* been taken to ensure the accuracy and reliability of the software and data,
* the National Oceanic And Atmospheric Administration and the U.S. Government
* do not and cannot warrant the performance or results that may be obtained by
* using this software or data. The National Oceanic And Atmospheric
* Administration and the U.S. Government disclaim all warranties, express or
* implied, including warranties of performance, merchantability or fitness
* for any particular purpose.
* United States Copyright Act. It was written as part of the author's
* official duties as a United States Government employee and thus cannot be
* copyrighted. This software is freely available to the public for use. The
* National Oceanic And Atmospheric Administration and the U.S. Government have
* not placed any restriction on its use or reproduction. Although all
* reasonable efforts have been taken to ensure the accuracy and reliability of
* the software and data, the National Oceanic And Atmospheric Administration
* and the U.S. Government do not and cannot warrant the performance or results
* that may be obtained by using this software or data. The National Oceanic
* And Atmospheric Administration and the U.S. Government disclaim all
* warranties, express or implied, including warranties of performance,
* merchantability or fitness for any particular purpose.
*
* Please cite the author(s) in any work or product based on this material.
*
Expand All @@ -37,13 +37,14 @@

#include "model_object.hpp"

namespace fims {
namespace fims
{

/**
* Container to hold user supplied data.
*/
template <typename Type>
struct DataObject : public fims::FIMSObject<Type> {
template <typename Type> struct DataObject : public fims::FIMSObject<Type>
{
static uint32_t id_g; /*!< id of the Data Object >*/
std::vector<Type> data; /*!< vector of the data >*/
size_t dimensions; /*!< dimension of the Data object >*/
Expand All @@ -55,35 +56,40 @@ struct DataObject : public fims::FIMSObject<Type> {
/**
* Constructs a one-dimensional data object.
*/
DataObject(size_t imax) : dimensions(1), imax(imax) {
data.resize(imax);
DataObject (size_t imax) : dimensions (1), imax (imax)
{
data.resize (imax);

this->id = DataObject<Type>::id_g++;
}

/**
* Constructs a two-dimensional data object.
*/
DataObject(size_t imax, size_t jmax) : dimensions(2), imax(imax), jmax(jmax) {
data.resize(imax * jmax);
DataObject (size_t imax, size_t jmax)
: dimensions (2), imax (imax), jmax (jmax)
{
data.resize (imax * jmax);
this->id = DataObject<Type>::id_g++;
}

/**
* Constructs a three-dimensional data object.
*/
DataObject(size_t imax, size_t jmax, size_t kmax)
: dimensions(3), imax(imax), jmax(jmax), kmax(kmax) {
data.resize(imax * jmax * kmax);
DataObject (size_t imax, size_t jmax, size_t kmax)
: dimensions (3), imax (imax), jmax (jmax), kmax (kmax)
{
data.resize (imax * jmax * kmax);
this->id = DataObject<Type>::id_g++;
}

/**
* Constructs a four-dimensional data object.
*/
DataObject(size_t imax, size_t jmax, size_t kmax, size_t lmax)
: dimensions(4), imax(imax), jmax(jmax), kmax(kmax), lmax(lmax) {
data.resize(imax * jmax * kmax * lmax);
DataObject (size_t imax, size_t jmax, size_t kmax, size_t lmax)
: dimensions (4), imax (imax), jmax (jmax), kmax (kmax), lmax (lmax)
{
data.resize (imax * jmax * kmax * lmax);
this->id = DataObject<Type>::id_g++;
}

Expand All @@ -92,18 +98,25 @@ struct DataObject : public fims::FIMSObject<Type> {
* @param i dimension of 1d data set
* @return the value of the vector at position i
*/
inline Type operator()(size_t i) { return data[i]; }
inline Type
operator() (size_t i)
{
return data[i];
}

/**
* Retrieve element from 1d data set.
* Throws an exception if index is out of bounds.
* @param i dimension of 1d data set
* @return the reference to the value of the vector at position i
*/
inline Type& at(size_t i) {
if (i >= this->data.size()) {
throw std::overflow_error("DataObject error:i index out of bounds");
}
inline Type &
at (size_t i)
{
if (i >= this->data.size ())
{
throw std::overflow_error ("DataObject error:i index out of bounds");
}
return data[i];
}

Expand All @@ -113,10 +126,13 @@ struct DataObject : public fims::FIMSObject<Type> {
* @param x
*
*/
inline void set(size_t i, Type x) {
if (i >= this->data.size()) {
throw std::overflow_error("DataObject error: index out of bounds");
}
inline void
set (size_t i, Type x)
{
if (i >= this->data.size ())
{
throw std::overflow_error ("DataObject error: index out of bounds");
}
data[i] = x;
}

Expand All @@ -126,7 +142,9 @@ struct DataObject : public fims::FIMSObject<Type> {
* @param j 2nd dimension of 2d data set
* @return the value of the matrix at position i, j
*/
inline const Type operator()(size_t i, size_t j) {
inline const Type
operator() (size_t i, size_t j)
{
return data[i * jmax + j];
}

Expand All @@ -137,10 +155,13 @@ struct DataObject : public fims::FIMSObject<Type> {
* @param j 2nd dimension of 2d data set
* @return the reference to the value of the matrix at position i, j
*/
inline Type& at(size_t i, size_t j) {
if ((i * jmax + j) >= this->data.size()) {
throw std::overflow_error("DataObject error: index out of bounds");
}
inline Type &
at (size_t i, size_t j)
{
if ((i * jmax + j) >= this->data.size ())
{
throw std::overflow_error ("DataObject error: index out of bounds");
}
return data[i * jmax + j];
}

Expand All @@ -151,10 +172,13 @@ struct DataObject : public fims::FIMSObject<Type> {
* @param x
*
*/
inline void set(size_t i, size_t j, Type x) {
if ((i * jmax + j) >= this->data.size()) {
throw std::overflow_error("DataObject error: index out of bounds");
}
inline void
set (size_t i, size_t j, Type x)
{
if ((i * jmax + j) >= this->data.size ())
{
throw std::overflow_error ("DataObject error: index out of bounds");
}
data[i * jmax + j] = x;
}

Expand All @@ -165,7 +189,9 @@ struct DataObject : public fims::FIMSObject<Type> {
* @param k 3rd dimension of 3d data set
* @return the value of the array at position i, j, k
*/
inline const Type operator()(size_t i, size_t j, size_t k) {
inline const Type
operator() (size_t i, size_t j, size_t k)
{
return data[i * jmax * kmax + j * kmax + k];
}

Expand All @@ -177,10 +203,13 @@ struct DataObject : public fims::FIMSObject<Type> {
* @param k 3rd dimension of 3d data set
* @return the reference to the value of the array at position i, j, k
*/
inline Type& at(size_t i, size_t j, size_t k) {
if ((i * jmax * kmax + j * kmax + k) >= this->data.size()) {
throw std::overflow_error("DataObject error: index out of bounds");
}
inline Type &
at (size_t i, size_t j, size_t k)
{
if ((i * jmax * kmax + j * kmax + k) >= this->data.size ())
{
throw std::overflow_error ("DataObject error: index out of bounds");
}
return data[i * jmax * kmax + j * kmax + k];
}

Expand All @@ -192,7 +221,9 @@ struct DataObject : public fims::FIMSObject<Type> {
* @param l 4th dimension of 4d data set
* @return the value of the array at position i, j, k, l
*/
inline const Type operator()(size_t i, size_t j, size_t k, size_t l) {
inline const Type
operator() (size_t i, size_t j, size_t k, size_t l)
{
return data[i * jmax * kmax * lmax + j * kmax * lmax + k * lmax + l];
}

Expand All @@ -205,11 +236,14 @@ struct DataObject : public fims::FIMSObject<Type> {
* @param l 4th dimension of 4d data set
* @return the reference to the value of the array at position i, j, k, l
*/
inline Type& at(size_t i, size_t j, size_t k, size_t l) {
if ((i * jmax * kmax * lmax + j * kmax * lmax + k * lmax + l) >=
this->data.size()) {
throw std::overflow_error("DataObject error: index out of bounds");
}
inline Type &
at (size_t i, size_t j, size_t k, size_t l)
{
if ((i * jmax * kmax * lmax + j * kmax * lmax + k * lmax + l)
>= this->data.size ())
{
throw std::overflow_error ("DataObject error: index out of bounds");
}
return data[i * jmax * kmax * lmax + j * kmax * lmax + k * lmax + l];
}

Expand All @@ -218,40 +252,59 @@ struct DataObject : public fims::FIMSObject<Type> {
*
* @return size_t
*/
size_t get_dimensions() const { return dimensions; }
size_t
get_dimensions () const
{
return dimensions;
}

/**
* @brief Get the imax object
*
* @return size_t
*/
size_t get_imax() const { return imax; }
size_t
get_imax () const
{
return imax;
}

/**
* @brief Get the jmax object
*
* @return size_t
*/
size_t get_jmax() const { return jmax; }
size_t
get_jmax () const
{
return jmax;
}

/**
* @brief Get the kmax object
*
* @return size_t
*/
size_t get_kmax() const { return kmax; }
size_t
get_kmax () const
{
return kmax;
}

/**
* @brief Get the lmax object
*
* @return size_t
*/
size_t get_lmax() const { return lmax; }
size_t
get_lmax () const
{
return lmax;
}
};

template <typename Type>
uint32_t DataObject<Type>::id_g = 0;
template <typename Type> uint32_t DataObject<Type>::id_g = 0;

} // namespace fims
} // namespace fims

#endif
35 changes: 20 additions & 15 deletions inst/include/common/def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <memory>
#include <vector>

std::ofstream FIMS_LOG("fims.log"); /**< Log file */
std::ofstream FIMS_LOG ("fims.log"); /**< Log file */

#ifdef TMB_MODEL
// simplify access to singletons
Expand All @@ -25,26 +25,31 @@ std::ofstream FIMS_LOG("fims.log"); /**< Log file */
#define TMB_FIMS_THIRD_ORDER AD<TMB_FIMS_SECOND_ORDER>
#endif

namespace fims {
namespace fims
{

/**
* A static class for FIMS logging.
*/

class fims_log {
public:
class fims_log
{
public:
static std::map<std::string, std::ofstream>
FIMS_LOGS; /**< Map Log of files */
/**
* Static getter for retrieving a specific log file.
*/
static std::ofstream& get(const std::string& l) {
static std::ofstream &
get (const std::string &l)
{
typename std::map<std::string, std::ofstream>::iterator it;
it = fims_log::FIMS_LOGS.find(l);
if (it == fims_log::FIMS_LOGS.end()) {
std::ofstream& of = fims_log::FIMS_LOGS[l];
of.open(l.c_str());
}
it = fims_log::FIMS_LOGS.find (l);
if (it == fims_log::FIMS_LOGS.end ())
{
std::ofstream &of = fims_log::FIMS_LOGS[l];
of.open (l.c_str ());
}

return fims_log::FIMS_LOGS[l];
}
Expand All @@ -58,20 +63,20 @@ std::map<std::string, std::ofstream> fims_log::FIMS_LOGS;
* @brief Default trait. These are "T" specific
* traits that depend on modeling platform.
*/
template <typename T>
struct ModelTraits {
template <typename T> struct ModelTraits
{
typedef double real_t; /**< The real type */
typedef double variable_t; /**< The variable type */
typedef typename std::vector<double> DataVector; /**< The data vector type */
typedef typename std::vector<double> ParameterVector; /**< The variable vector
type */
typedef typename std::vector<double> ParameterVector; /**< The variable
vector type */
typedef typename std::vector<std::vector<double> > DataMatrix; /**< The
data matrix type */
typedef typename std::vector<std::vector<double> > VariableMatrix; /**< The
variable matrix type */
};

#endif
} // namespace fims
} // namespace fims

#endif /* TRAITS_HPP */
Loading

0 comments on commit 9edd6fa

Please sign in to comment.