cruinput.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. ///////////////////////////////////////////////////////////////////////////////////////
  2. /// \file cruinput.h
  3. /// \brief Input module for the CRU-NCEP data set
  4. ///
  5. /// \author Joe Siltberg
  6. /// $Date: 2018-02-02 18:01:35 +0100 (ven, 02 fév 2018) $
  7. ///
  8. ///////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef LPJ_GUESS_CRUINPUT_H
  10. #define LPJ_GUESS_CRUINPUT_H
  11. #include "guess.h"
  12. #include "inputmodule.h"
  13. #include <vector>
  14. #include "gutil.h"
  15. #include "globalco2file.h"
  16. #include "spinupdata.h"
  17. #include "cru_ts30.h"
  18. #include "lamarquendep.h"
  19. #include "externalinput.h"
  20. /// An input module for CRU climate data
  21. /** This input module gets climate data from binary archives built from
  22. * CRU-NCEP (1901-2015).
  23. */
  24. class CRUInput : public InputModule {
  25. public:
  26. /// Constructor
  27. /** Declares the instruction file parameters used by the input module.
  28. */
  29. CRUInput();
  30. /// Destructor, cleans up used resources
  31. ~CRUInput();
  32. /// Reads in gridlist and initialises the input module
  33. /** Gets called after the instruction file has been read */
  34. void init();
  35. /// See base class for documentation about this function's responsibilities
  36. bool getgridcell(Gridcell& gridcell);
  37. /// See base class for documentation about this function's responsibilities
  38. bool getclimate(Gridcell& gridcell);
  39. /// See base class for documentation about this function's responsibilities
  40. void getlandcover(Gridcell& gridcell);
  41. /// Obtains land management data for one day
  42. void getmanagement(Gridcell& gridcell) {management_input.getmanagement(gridcell, landcover_input);}
  43. // Constants associated with historical climate data set
  44. /// number of years of historical climate
  45. static const int NYEAR_HIST = CRU_TS30::NYEAR_HIST;
  46. /// calendar year corresponding to first year in data set
  47. static const int FIRSTHISTYEAR = CRU_TS30::FIRSTHISTYEAR;
  48. /// number of years to use for temperature-detrended spinup data set
  49. /** (not to be confused with the number of years to spinup model for, which
  50. * is read from the ins file)
  51. */
  52. static const int NYEAR_SPINUP_DATA=30;
  53. protected:
  54. /// Gets monthly ndep values for a given calendar year
  55. /** To be used by sub-classes that wish to do their own
  56. * distribution of monthly values to daily values.
  57. *
  58. * The ndep values returned are for the current gridcell,
  59. * i.e. the gridcell chosen in the most recent call to
  60. * getgridcell().
  61. *
  62. * \param calendar_year The calendar (not simulation!) year for which to get ndep
  63. * \param mndrydep Pointer to array holding 12 doubles
  64. * \param mnwetdep Pointer to array holding 12 doubles
  65. */
  66. void get_monthly_ndep(int calendar_year,
  67. double* mndrydep,
  68. double* mnwetdep);
  69. /// Gives sub-classes a chance to modify the forcing data
  70. /** This function will be called just after the forcing data for the historical
  71. * period has been read in for a gridcell. Sub-classes can override this function
  72. * and modify the data if needed, for instance adjusting according to site data.
  73. *
  74. * Note that modifying this data will also affect the spinup period since
  75. * the spinup forcing is based on the historical period.
  76. *
  77. * \param hist_mtemp Monthly temperature values for each year
  78. * \param hist_mprec Monthly precipitation values for each year
  79. * \param hist_msun Monthly sunshine values for each year
  80. */
  81. virtual void adjust_raw_forcing_data(double lon,
  82. double lat,
  83. double hist_mtemp[NYEAR_HIST][12],
  84. double hist_mprec[NYEAR_HIST][12],
  85. double hist_msun[NYEAR_HIST][12]);
  86. private:
  87. /// Type for storing grid cell longitude, latitude and description text
  88. struct Coord {
  89. int id;
  90. double lon;
  91. double lat;
  92. xtring descrip;
  93. };
  94. /// Land cover input module
  95. LandcoverInput landcover_input;
  96. /// Management input module
  97. ManagementInput management_input;
  98. /// search radius to use when finding CRU data
  99. double searchradius;
  100. /// A list of Coord objects containing coordinates of the grid cells to simulate
  101. ListArray_id<Coord> gridlist;
  102. /// Flag for getgridcell(). True indicates that the first gridcell has not been read yet by getgridcell()
  103. bool first_call;
  104. // Timers for keeping track of progress through the simulation
  105. Timer tprogress,tmute;
  106. static const int MUTESEC=20; // minimum number of sec to wait between progress messages
  107. /// Yearly CO2 data read from file
  108. /**
  109. * This object is indexed with calendar years, so to get co2 value for
  110. * year 1990, use co2[1990]. See documentation for GlobalCO2File for
  111. * more information.
  112. */
  113. GlobalCO2File co2;
  114. /// Monthly temperature for current grid cell and historical period
  115. double hist_mtemp[NYEAR_HIST][12];
  116. /// Monthly precipitation for current grid cell and historical period
  117. double hist_mprec[NYEAR_HIST][12];
  118. /// Monthly sunshine for current grid cell and historical period
  119. double hist_msun[NYEAR_HIST][12];
  120. /// Monthly frost days for current grid cell and historical period
  121. double hist_mfrs[NYEAR_HIST][12];
  122. /// Monthly precipitation days for current grid cell and historical period
  123. double hist_mwet[NYEAR_HIST][12];
  124. /// Monthly DTR (diurnal temperature range) for current grid cell and historical period
  125. double hist_mdtr[NYEAR_HIST][12];
  126. /// Nitrogen deposition forcing for current gridcell
  127. Lamarque::NDepData ndep;
  128. /// Spinup data for current grid cell - temperature
  129. Spinup_data spinup_mtemp;
  130. /// Spinup data for current grid cell - precipitation
  131. Spinup_data spinup_mprec;
  132. /// Spinup data for current grid cell - sunshine
  133. Spinup_data spinup_msun;
  134. /// Spinup data for current grid cell - frost days
  135. Spinup_data spinup_mfrs;
  136. /// Spinup data for current grid cell - precipitation days
  137. Spinup_data spinup_mwet;
  138. /// Spinup data for current grid cell - DTR (diurnal temperature range)
  139. Spinup_data spinup_mdtr;
  140. /// Daily temperature for current year
  141. double dtemp[Date::MAX_YEAR_LENGTH];
  142. /// Daily precipitation for current year
  143. double dprec[Date::MAX_YEAR_LENGTH];
  144. /// Daily sunshine for current year
  145. double dsun[Date::MAX_YEAR_LENGTH];
  146. // Daily diurnal temperature range for current year
  147. double ddtr[Date::MAX_YEAR_LENGTH];
  148. /// Daily N deposition for current year
  149. double dndep[Date::MAX_YEAR_LENGTH];
  150. };
  151. #endif // LPJ_GUESS_CRUINPUT_H