externalinput.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. /// \file externalinput.h
  3. /// \brief Input code for land cover, management and other data from text files.
  4. /// \author Mats Lindeskog
  5. /// $Date: 2018-12-21 08:30:58 +0100 (ven, 21 déc 2018) $
  6. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  7. #ifndef LPJ_GUESS_EXTERNALINPUT_H
  8. #define LPJ_GUESS_EXTERNALINPUT_H
  9. #include "indata.h"
  10. using namespace InData;
  11. /// Reads gridlist in lon-lat-description format from text input file
  12. void read_gridlist(ListArray_id<Coord>& gridlist, const char* file_gridlist);
  13. /// Help function for get_lc_transfer() to adjust inconsistencies between net land cover inout and gross land cover transitions.
  14. void adjust_gross_transfers(Gridcell& gridcell, double landcoverfrac_change[], double lc_frac_transfer[][NLANDCOVERTYPES], forest_lc_frac_transfer& forest_lc_frac_transfer_s, double& tot_frac_ch);
  15. /// Class that deals with all land cover input from text files
  16. class LandcoverInput {
  17. public:
  18. /// Constructor
  19. LandcoverInput();
  20. /// Opens land cover input files
  21. void init();
  22. /// Loads land cover and stand type area fractions from input files
  23. bool loadlandcover(double lon, double lat);
  24. /// Gets land cover and stand type fractions for a year.
  25. /** Updates landcover and stand type variables frac, frac_old and frac_change
  26. * Area fractions are re-scaled if sum is not 1.0
  27. */
  28. void getlandcover(Gridcell& gridcell);
  29. /// Gets crop stand type fractions for a year, called from getlandcover()
  30. double get_crop_fractions(Gridcell& gridcell, int year, TimeDataD& CFTdata, double sum_tot);
  31. /// Gets land cover or stand type transitions for a year
  32. bool get_land_transitions(Gridcell& gridcell);
  33. /// Gets land cover transitions for a year
  34. /** Updates landcover frac_transfer array
  35. * Transition values are checked against net lcc fractions and
  36. * rescaled if necessary.
  37. */
  38. bool get_lc_transfer(Gridcell& gridcell);
  39. /// Gets first historic year of net land cover fraction input data
  40. int getfirsthistyear();
  41. private:
  42. // Objects handling land cover fraction data input
  43. InData::TimeDataD LUdata;
  44. InData::TimeDataD Peatdata;
  45. InData::TimeDataD grossLUC;
  46. InData::TimeDataD st_data[NLANDCOVERTYPES];
  47. /// Files names for land cover fraction input files
  48. xtring file_lu, file_grossLUC, file_peat;
  49. xtring file_lu_st[NLANDCOVERTYPES];
  50. /// Whether pfts not in crop fraction input file are removed from pftlist (0,1)
  51. bool minimizecftlist;
  52. /// Number of years to increase cropland fraction linearly from 0 to first year's value
  53. int nyears_cropland_ramp;
  54. /// whether to use stand types with suitable rainfed crops (based on crop pft tb and gridcell latitude) when using fixed crop fractions
  55. bool frac_fixed_default_crops;
  56. };
  57. /// Class that deals with all crop management input from text files
  58. class ManagementInput {
  59. public:
  60. /// Constructor
  61. ManagementInput();
  62. /// Opens management data files
  63. void init();
  64. /// Loads fertilisation, sowing and harvest dates from input files
  65. bool loadmanagement(double lon, double lat);
  66. /// Gets management data for a year
  67. void getmanagement(Gridcell& gridcell, LandcoverInput& landcover_input);
  68. private:
  69. /// Input objects for each management text input file
  70. InData::TimeDataD sdates;
  71. InData::TimeDataD hdates;
  72. InData::TimeDataD Nfert;
  73. InData::TimeDataD Nfert_st;
  74. InData::TimeDataD woodharv_frac;
  75. InData::TimeDataD woodharv_vol;
  76. /// Files names for management input file
  77. xtring file_sdates, file_hdates, file_Nfert, file_Nfert_st, file_woodharv_frac, file_woodharv_vol;
  78. /// Gets sowing date data for a year
  79. void getsowingdates(Gridcell& gridcell);
  80. /// Gets harvest date data for a year
  81. void getharvestdates(Gridcell& gridcell);
  82. /// Gets nitrogen fertilisation data for a year
  83. void getNfert(Gridcell& gridcell);
  84. /// Gets wood harvest data for a year
  85. void getwoodharvest(Gridcell& gridcell, LandcoverInput& landcover_input);
  86. };
  87. #endif // LPJ_GUESS_EXTERNALINPUT_H