Documentation_of_code - PIK-LPJmL/LPJmL GitHub Wiki

Documentation of code

Here, we try to disentangle the LPJmL code. We begin with the main function in lpjml.c and go from there into details.

lpjml.c includes
Definition of number of PFT types NTYPES = 3 (grass, tree, crop and bioenergy) and number of stand types NSTANDTYPES = 9.
Definition of main configuration file with managed land “lpjml.conf” or without manage land “lpj.conf”.
Main function comprises:

  • Declaration of output file array Outputfile *output;
  • Declaration of grid cell structure Cell *grid;
  • Reading of configuration files by readconfig reads LPJ configuration file (fscanconfig() reads lpjml.conf and fscanparam() reads param.par).
  • Initialization of input data by initinput (initclimate, initlanduse, initwateruse, initpopdens).
  • Allocation of grid cell structure by grid= newgrid (grid cells are allocated and soil code is read as well as country code and coordinates. Also reads standlist->stand->pftlist from file. If restart filename is set, state of grid cells is recovered from a restart file).
  • Creation of output files by fopenoutput.
  • Main yearly time loop by iterate (grid) which calls iterateyear or iterateyear_river.
  • Closing of output by fcloseoutput, releasing structures by freegrid(grid), freeinput and freeconfig.