demoinput.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ///////////////////////////////////////////////////////////////////////////////////////
  2. /// \file demoinput.h
  3. /// \brief Input module for demo data set
  4. ///
  5. /// \author Joe Siltberg
  6. /// $Date: 2018-02-02 18:01:35 +0100 (Fri, 02 Feb 2018) $
  7. ///
  8. ///////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef LPJ_GUESS_DEMOINPUT_H
  10. #define LPJ_GUESS_DEMOINPUT_H
  11. #include "guess.h"
  12. #include "inputmodule.h"
  13. #include <vector>
  14. #include "gutil.h"
  15. #include "externalinput.h"
  16. /// An input module for a toy data set (for demonstration purposes)
  17. /** This input module is provided as an example of an input module.
  18. * Included together with the LPJ-GUESS source code is a small
  19. * toy data set (text based) which can be used to test the model,
  20. * or to learn about how to write input modules.
  21. *
  22. * \see InputModule for more documentation about writing input modules.
  23. */
  24. class DemoInput : public InputModule {
  25. public:
  26. /// Constructor
  27. /** Declares the instruction file parameters used by the input module.
  28. */
  29. DemoInput();
  30. /// Destructor, cleans up used resources
  31. ~DemoInput();
  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. private:
  44. /// Type for storing grid cell longitude, latitude and description text
  45. struct Coord {
  46. int id;
  47. double lon;
  48. double lat;
  49. xtring descrip;
  50. };
  51. /// Land cover input module
  52. LandcoverInput landcover_input;
  53. /// Management input module
  54. ManagementInput management_input;
  55. /// Help function to readenv, reads in 12 monthly values from a text file
  56. bool read_from_file(Coord coord, xtring fname, const char* format,
  57. double monthly[12], bool soil = false);
  58. /// Reads in environmental data for a location
  59. bool readenv(Coord coord, long& seed);
  60. /// number of simulation years to run after spinup
  61. int nyear;
  62. /// A list of Coord objects containing coordinates of the grid cells to simulate
  63. ListArray_id<Coord> gridlist;
  64. /// Flag for getgridcell(). True indicates that the first gridcell has not been read yet by getgridcell()
  65. bool first_call;
  66. // Timers for keeping track of progress through the simulation
  67. Timer tprogress,tmute;
  68. static const int MUTESEC=20; // minimum number of sec to wait between progress messages
  69. // Daily temperature, precipitation and sunshine for one year
  70. double dtemp[Date::MAX_YEAR_LENGTH];
  71. double dprec[Date::MAX_YEAR_LENGTH];
  72. double dsun[Date::MAX_YEAR_LENGTH];
  73. // bvoc
  74. // Daily diurnal temperature range for one year
  75. double ddtr[Date::MAX_YEAR_LENGTH];
  76. /// atmospheric CO2 concentration (ppmv) (read from ins file)
  77. double co2;
  78. /// atmospheric nitrogen deposition (kgN/yr/ha) (read from ins file)
  79. double ndep;
  80. };
  81. #endif // LPJ_GUESS_DEMOINPUT_H