/////////////////////////////////////////////////////////////////////////////////////// /// \file spinupdata.h /// \brief Management of climate data for spinup /// /// $Date: 2018-02-02 18:01:35 +0100 (ven, 02 fév 2018) $ /// /////////////////////////////////////////////////////////////////////////////////////// #ifndef LPJ_GUESS_SPINUP_DATA_H #define LPJ_GUESS_SPINUP_DATA_H #include "guessmath.h" class Spinup_data { // Class for management of climate data for spinup // (derived from first few years of historical climate data) private: int nyear; int thisyear; double* data; bool havedata; // guess2008 - this array holds the climatology for the spinup period double dataclim[12]; public: Spinup_data(int nyear_loc) { nyear=nyear_loc; havedata=false; data=new double[nyear*12]; thisyear=0; havedata=true; reset_clim(); // guess2008 } ~Spinup_data() { if (havedata) delete[] data; } double& operator[](int month) { return data[thisyear*12+month]; } void nextyear() { if (thisyear==nyear-1) thisyear=0; else thisyear++; } void firstyear() { thisyear=0; } void get_data_from(double source[][12]) { int y,m; thisyear=0; for (y=0;y maxval) data[y*12+m] = maxval; } } } void set_min_val(const double& oldval, const double& newval) { // Change values < oldval to newval int y,m; for (y=0;y > RawData; GenericSpinupData(); /// Loads the underlying forcing data (and sets the "current" year to 0) void get_data_from(RawData& source); /// Gets the value for a given timestep in the "current" year double operator[](int ts) const; /// Goes to the next year void nextyear(); /// Goes to the first year void firstyear(); /// Removes trend from the original data void detrend_data(); /// Returns the number of years used to construct the spinup dataset size_t nbr_years() const; private: /// The "current" year int thisyear; /// The forcing data which is used over and over during the spinup RawData data; }; #endif // LPJ_GUESS_SPINUP_DATA_H