Skip to content
Snippets Groups Projects
prepsite.f 78.9 KiB
Newer Older
Petra Lasch-Born's avatar
Petra Lasch-Born committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
!*****************************************************************!
!*                                                               *!
!*                     4C (FORESEE)                              *!
!*                                                               *!
!*                                                               *!
!*                    Subroutines:                               *!
!*             PREPARE_SITE and PREPARE_CLIMATE                  *!
!*                                                               *!
!* Contains subroutines:                                         *!
!*                                                               *!
!* PREPARE_SITE:                                                 *!
!*            preparation of site specific simulation parameters *!
!*                                                               *!
!*            contains internal subroutines:                     *!
!*            SITEMENU: choice of inputs                         *!
!*            EDITFILE: edit filenames                           *!
!*            READSOIL: input of soil parameter                  *!
!*            READCN: input of C-N-parameter                     *!
!*            READVALUE: input of start values for               *!
!*                       soil water and C-N-modeling             *!
!*            ALLOC_SOIL: allocate soil variables                *!
!*            STAND_BAL_INI: allocate and init stand variables   *!
!*            CONTROL_FILE: saving all parameters                *!
!*                          and start conditions for each site   *!
!*                                                               *!
!* READDEPO:  reading deposition data                            *!
!* READREDN:  reading values of redN                             *!
!* READLIT:   reading initialisation data of litter fractions    *!
!*                                                               *!
!* PREPARE_CLIMATE: reading of site specific climate input data  *!
!*                  from file                                    *!
!*                  contains internal subroutines:               *!
!*                  READ_DWD                                     *!
!*                  READ_CLI                                     *!
!*                  CLIMFILL                                     *!
!*                                                               *!
!* STORE_PARA:      multi run - restore of changed parameter     *!
!*                                                               *!
!*                  Copyright (C) 1996-2018                      *!
!*     Potsdam Institute for Climate Impact Reserach (PIK)       *!
!*          Authors and contributors see AUTHOR file             *!
!*  This file is part of 4C and is licensed under BSD-2-Clause   *!
!*                   See LICENSE file or under:                  *!
!*     http://www.https://opensource.org/licenses/BSD-2-Clause   *!
!*                           Contact:                            *!
!*       https://gitlab.pik-potsdam.de/foresee/4C                *!
!*                                                               *!
!*****************************************************************!

subroutine prepare_site

! input of site specific data

  use data_climate
  use data_inter
  use data_manag
  use data_mess
  use data_out
  use data_par
  use data_simul
  use data_site
  use data_soil
  use data_soil_cn
  use data_species
  use data_stand
  use data_tsort
  use data_frost


implicit none
integer i,ios,help, help_ip
character a
character :: text
character(10)  :: helpsim, text2
logical:: ex=.TRUE.
real parerr
real, external :: avg_sun_incl
character(100)  :: helpx

if (flag_trace) write (unit_trace, '(I4,I10,A)') iday, time_cur, ' prepare_site'

WRITE(helpsim,'(I4)') anz_sim
read(helpsim,*) anh


IF(site_nr==1) THEN
    help_ip=site_nr
ELSE
    help_ip=ip
END IF

! Initialization of climate data
IF (flag_clim==1 .or. ip==1 .or. flag_multi .eq.5) THEN
    call prepare_climate
END IF

if (flag_end .gt. 0) return
ios=0; help=0
do
  if (ip==1 .and. flag_mult9) then
   if (flag_trace) write (unit_trace, '(I4,I10,A,I3,A5,L5)') iday, time_cur, ' prepare_site ip=',ip,'  ex=',ex  
    call readspec
    call readsoil  ! reading soil parameter
    IF (flag_end .gt.0) return
    if (flag_soilin .eq. 0) call readvalue  ! Initialization of simulation start values for soil layers
    
    ! biochar
    if (flag_bc .gt. 0) call bc_appl
    
    ! Deposition data
    call readdepo

    ! Input redN
    if (flag_multi .ne. 4 .or. flag_multi .ne. 8 ) call readredN

    flag_mult9 = .FALSE.
  else
   if (flag_trace) write (unit_trace, '(I4,I10,A,I3,A5,L5)') iday, time_cur, ' prepare_site ip=',ip,'  ex=',ex   

    ! Deposition data
    call readdepo

    select case (flag_multi)
    case (1,6)
       call readspec
       if (flag_soilin .eq. 0) call readvalue  ! Initialization of simulation start values for soil layers
       call readredN           ! Input redN
       call readsoil  ! reading soil parameter   
       
       do
          jpar = jpar + 1
             if (vpar(jpar) .gt. -90.0) then
                helpx = simpar(jpar)
                call store_para(vpar(jpar), helpx, parerr)
                IF (parerr .ne. 1.) then
                   CALL  error_mess(time,'parameter variation: '//trim(simpar(jpar))//' not found',vpar(jpar))
                   write (*,*) '***  parameter variation: ', trim(simpar(jpar)), ' not found,   see error log'
                endif
             else
                exit
             endif
       enddo
    
    ! biochar
      if (flag_bc .gt. 0 .or. flag_decomp .gt. 100) call bc_appl

    case (2,4)


       call readsoil  ! reading soil parameter
       if (flag_soilin .eq. 0) call readvalue  ! Initialization of simulation start values for soil layers

    case (5)
       call readspec   
       call readsoil  
       if (flag_soilin .eq. 0) call readvalue  ! Initialization of simulation start values for soil layers
       call readredN                           ! Input redN

    case (7)
       call assign_co2par      
       call readsoil                           ! reading soil parameter
       if (flag_soilin .eq. 0) call readvalue  ! Initialization of simulation start values for soil layers
       call readredN                           ! Input redN

    case (8, 9, 10)

       call readsoil         ! reading soil parameter
       IF (flag_end .gt.0) return
       call readredN         ! Input redN or test resp.
    end select
  endif
exit
enddo

! Setting flag_inth and prec_stad_red from flag_int
if (flag_int .lt. 1000) then
    flag_inth = flag_int
else
  ! Conversion character ==> number and vice versa  
    write (helpsim,'(I4)') flag_int
    text2 = helpsim(2:2)
    read (text2,*) flag_inth
    text2 = helpsim(3:4)
    read (text2,*) prec_stand_red
endif

if (.not.flag_mult8910) then
    unit_soil = getunit()
    open (unit_soil,file=trim(dirout)//trim(site_name(help_ip))//'_soil.ini'//anh,status='replace')
    WRITE (unit_soil,'(2A)') '! Soil initialisation, site name: ',site_name(help_ip)
endif

call stand_bal_ini !allocation of stand summation variables

! Initialization of CO2
call assign_co2par
! Initialisation litter compartments
call readlit
! Initialization of soil model with profile data
call soil_ini    ! Aufruf ohne s_cn_ini
! Initialization disturbances
IF (flag_dis .eq. 1 .or. flag_dis .eq. 2) CALL dist_ini
! Initialization of stand
call prepare_stand
IF (flag_end .gt.0) return
! calculation of latitude in radians
xlat = lat/90.*pi*0.5
! calculation of average sun inclination
avg_incl = AVG_SUN_INCL(lat)   ! degrees
beta=avg_incl*PI/180           ! radians
! read externally prescribed bud burst days
CALL readbudb
! Initialization management
IF(flag_mg.ne.0.and. flag_mg.ne.5) call manag_ini
IF(flag_mg.eq. 5) then
    thin_dead = 1
    allocate(thin_flag1(nspec_tree))
	thin_flag1  = 0
end if	  
! Initialization of output file per site
call prep_out
call stand_balance
call CROWN_PROJ
call standup
call root_ini   ! initialisation of root distribution
call s_cn_ini

! Initialization of soil temperature model with stand data
call s_t_ini

! control file for saving simulation environment
! output of first Litter-Input at start
if(flag_mult8910 .and. (anz_sim .gt. 1)) then
    continue
else 
    IF ((ip .eq. 1 .or. flag_multi .eq. 1 .or. flag_multi .eq. 6) .and. (time_out .ne. -2) ) call control_file
endif

! hand over of the litter-initialising
call litter
if ((flag_decomp .eq. 20) .or. (flag_decomp .eq. 21)) then
    call testfile(valfile(ip),ex)
    if (ex .eqv. .true.) then
       ios = 0
       unit_litter = getunit()
       open(unit_litter,file=valfile(ip),status='old',action='read')
       if (flag_multi .ne. 9) print *,' *** Open file of litter input data ',valfile(ip),'...'
           do
              read(unit_litter,*) text
              IF(text .ne. '!')then
                 backspace(unit_litter);exit
              endif
           enddo
    endif
endif
call cn_inp

! read flux data
if (flag_eva .gt.10) call evapo_ini
      ! yearly output
      IF (time_out .gt. 0) THEN
         IF (mod(time,time_out) .eq. 0) CALL outyear (1)
         IF (mod(time,time_out) .eq. 0) CALL outyear (2)
      ENDIF

    contains

!-------------------------------------------------------------------------------

subroutine readsoil ! Input of soil parameter

use data_par
use data_soil_t
use data_site

implicit none

integer :: inunit, helpnl, helpnr, ihelp
real helpgrw, hlong, hlat
character :: text
character(30) :: hor, boart, helpid

if (flag_trace) write (unit_trace, '(I4,I10,A)') iday, time_cur, ' readsoil'

! Setting of flag_surf from flag_cond
select case (flag_cond)

    case (0,1,2,3)
       flag_surf = 0

    case (10,11,12,13)
       flag_surf = 1

    case (30,31,32,33)
       flag_surf = 3
       
end select

! Setting of flag_bc from flag_decomp
if (flag_decomp .ge. 100) then
    flag_decomp = flag_decomp - 100
    flag_bc = 1
else
    flag_bc = 0
endif

call testfile(sitefile(ip),ex)
IF (ex .eqv. .true.) then
  inunit = getunit()
  ios=0
  open(inunit,file=sitefile(ip),iostat=ios,status='old',action='read')
  if (.not.flag_mult8910) then
      print *,'***** Reading soil parameter from file ',sitefile(ip),'...'
      write (unit_err, *) 'Soil parameter from file   ',trim(sitefile(ip))
  endif

  do
     read(inunit,*) text
     IF(text .ne. '!')then
        backspace(inunit)
        exit
     endif
  enddo
     
  if (flag_multi .eq. 8.or. flag_multi.eq.5.or. flag_mult910) then  
      read(inunit,*) text
     IF((text .eq. 'N') .or. (text .eq. 'n'))then
         flag_soilin = 3
     else
         flag_soilin = 2
         backspace(inunit)
     endif
  else
     read(inunit,*) text
     IF((text .eq. 'N') .or. (text .eq. 'n'))then
         flag_soilin = 1
     else
         flag_soilin = 0
         backspace(inunit)
     endif
     soilid(ip) = valfile(ip)
  endif
  if ((text .eq. 'S') .or. (text .eq. 's'))then
      flag_soilin = 4
      read(inunit,*) text
  endif
  if (.not.flag_mult8910) then
      write (unit_err, *) 'Soil identity number       ', trim(soilid(ip))
      write (unit_err, *) 'Climate ID                 ', trim(clim_id(ip))
  endif
  
  if (flag_soilin .eq. 1 .or. flag_soilin .ge. 3) then
    flag_hum = 1
  endif  
  
  if (flag_cond .ge. 40) then
    flag_hum = 0
  endif
  
  select case (flag_soilin)

  case (0,1)   ! single files f. j. site

     read (inunit,*,iostat=ios) long
     read (inunit,*,iostat=ios) lat
     read (inunit,*,iostat=ios) nlay
     read (inunit,*,iostat=ios) nroot_max
     read (inunit,*,iostat=ios) helpgrw
     
     if (helpgrw .gt. 1) then
        grwlev = helpgrw
     else
        fakt   = helpgrw
        grwlev = 1000.
     endif
     
     read (inunit,*,iostat=ios) w_ev_d
     read(inunit,*,iostat=ios) k_hum     ! mineralization constants of humus
     read(inunit,*,iostat=ios) k_hum_r
     read(inunit,*,iostat=ios) k_nit     ! nitrification constant

     IF(help==0) call alloc_soil
         read (inunit,*,iostat=ios) text
         select case (flag_soilin)
         case (0)      ! old input structure
             do i = 1, nlay
               read (inunit,*,iostat=ios) text
               read (inunit,*,iostat=ios) thick(i),pv_v(i),dens(i),f_cap_v(i), &
                     wilt_p_v(i),spheat(i),phv(i),wlam(i)
             end do
             skelv = 0.
     
         case(1)      ! new input structure
             do i = 1, nlay
               read (inunit,*,iostat=ios) helpnr, thick(i),pv_v(i),f_cap_v(i),wilt_p_v(i), &
                     dens(i),spheat(i),phv(i),wlam(i),skelv(i), sandv(i),clayv(i),humusv(i),&
                     C_hum(i), N_hum(i),NH4(i),NO3(i)
                     if (flag_wurz .eq. 4 .or. flag_wurz .eq. 6) then
                       if (phv(i) .le. 0.01) phv(i)=6.0         ! if flag_wurz 4 or 6 is used for calculation a pH-value is assumed
                     endif
             end do
         end select  ! flag_soilin (0,1)
     
    if (.not.flag_mult8910) print *, ' '
     IF (ios .ne.0) then
          print *,' >>>FORESEE message: Error during reading soil data!'
          WRITE(*,'(A)',advance='no') '  Stop program (y/n)? '
          read *, a
          IF ( a .eq. 'y' .or. a .eq. 'Y') then
              print *, '  STOP program!'
              stop
          endif
          IF (help==1)  call dealloc_soil
          print *,'  Check your input choice!!!'
      endif   ! ios

  case (2)   ! all sites are read from one file; old structure
     
     ios = 0
     do while (ios .eq. 0)
         read (inunit,*,iostat=ios) helpid, helpnl, helpnr
         if (trim(soilid(ip)) .ne. trim(helpid)) then
            do i = 1, helpnl
               read (inunit,*,iostat=ios) helpid
            enddo
         else
            nlay      = helpnl
            nroot_max = helpnr
            if (help==0) call alloc_soil
            do i = 1, nlay
               read (inunit,*,iostat=ios) helpnl, hor, boart, depth(i), thick(i),pv_v(i),dens(i), &
                    f_cap_v(i), wilt_p_v(i), spheat(i),phv(i),wlam(i), &
                    C_hum(i), N_hum(i), NH4(i), NO3(i), temps(i)
            enddo
            lat = latitude(ip)
			grwlev = gwtable(ip)
            exit
         endif
     enddo

     IF (ios .lt. 0) then
       if (.not.flag_mult8910) print *,' >>>FORESEE message: soil_id ', soilid(ip), ' not found'
       if (.not.flag_mult8910) print *,'  Check your input choice!!!'
       if (help==1)  call dealloc_soil
       CALL error_mess(time,"soil identificator not found "//adjustl(soilid(ip))//" ip No. ",real(help_ip))
       flag_end = 5
       return
     ENDIF   ! ios

     skelv = 0.

  case (3)   ! all sites are read from one file; new structure
     
     ios = 0
     do while (ios .eq. 0)
         read (inunit,*,iostat=ios) helpid, helpnl, helpnr
         if (trim(soilid(ip)) .ne. trim(helpid)) then
            do i = 1, helpnl
               read (inunit,*,iostat=ios) helpid
            enddo
         else
            nlay      = helpnl
            nroot_max = helpnr
            if (help==0) call alloc_soil
             do i = 1, nlay
               read (inunit,*,iostat=ios) helpnr, hor, boart, depth(i), thick(i),pv_v(i),f_cap_v(i), &
                     wilt_p_v(i),dens(i),spheat(i),phv(i),wlam(i),skelv(i), sandv(i), &
                     clayv(i),humusv(i),C_hum(i), N_hum(i),NH4(i),NO3(i)
                     if (flag_wurz .eq. 4 .or. flag_wurz .eq. 6) then
                       if (phv(i) .le. 0.01) phv(i)=6.0         ! if flag_wurz 4 or 6 is used for calculation a pH-value is assumed
                     endif
             end do
            lat = latitude(ip)
			grwlev = gwtable(ip)
            exit
         endif
     enddo
     IF (ios .lt. 0) then
       if (.not.flag_mult8910) print *,' >>>FORESEE message: soil_id ', soilid(ip), ' not found'
       if (.not.flag_mult8910) print *,'  Check your input choice!!!'
       if (help==1)  call dealloc_soil
       CALL error_mess(time,"soil identificator not found "//adjustl(soilid(ip))//"ip No.",real(help_ip))
       flag_end = 5
       return
     ENDIF   ! ios

  case (4)   ! one file several sites

     if (.not.flag_mult8910) print *,'   Reading soil model parameter from soil type file... ', soilid(ip)

     ios = 0
     do while (ios .eq. 0)
         read (inunit,*,iostat=ios) helpid
         if (trim(soilid(ip)) .ne. trim(helpid)) then
            read (inunit,*,iostat=ios) text
            read (inunit,*,iostat=ios) text
            read (inunit,*,iostat=ios) helpnl
            do i = 1, helpnl+6
               read (inunit,*,iostat=ios) boart
            enddo
            read (inunit,*,iostat=ios) boart
         else
             read (inunit,*,iostat=ios) hlong
             read (inunit,*,iostat=ios) hlat
             read (inunit,*,iostat=ios) nlay
             read (inunit,*,iostat=ios) nroot_max
             read (inunit,*,iostat=ios) helpgrw
             if (flag_multi .eq. 8.or. flag_multi.eq.5.or. flag_mult910) then
                if (abs(latitude(ip)) .gt. 90.) lat = latitude(ip)
			    grwlev = gwtable(ip)
             else
                 if (helpgrw .gt. 1) then
                    grwlev = helpgrw
                 else
                    fakt   = helpgrw
                    grwlev = 1000.
                 endif
                long = hlong
                lat = hlat
             endif  
             read (inunit,*,iostat=ios) w_ev_d
             read(inunit,*,iostat=ios) k_hum     ! mineralization constants of humus
             read(inunit,*,iostat=ios) k_hum_r
             read(inunit,*,iostat=ios) k_nit     ! nitrification constant

             IF(help==0) call alloc_soil
 
             read (inunit,*,iostat=ios) text
              do i = 1, nlay
               read (inunit,*,iostat=ios) helpnr, thick(i),pv_v(i),f_cap_v(i),wilt_p_v(i), &
                     dens(i),spheat(i),phv(i),wlam(i),skelv(i), sandv(i),clayv(i),humusv(i),&
                     C_hum(i), N_hum(i),NH4(i),NO3(i)
                     if (flag_wurz .eq. 4 .or. flag_wurz .eq. 6) then
                       if (phv(i) .le. 0.01) phv(i)=6.0         ! if flag_wurz 4 or 6 is used for calculation a pH-value is assumed
                     endif
             end do
             IF (ios .ne.0) then
                  print *,' >>>FORESEE message: Error during reading soil data!'    
                  print *, ' Program stopped!'
                  IF (help==1)  call dealloc_soil
                  flag_end = 7
                  return
              endif   ! ios
           exit
         endif
     enddo

     if (.not.flag_mult8910) print *, ' '
     IF (ios .lt. 0) then
       if (.not.flag_mult8910) then
           print *,' >>>FORESEE message: soil_id ', soilid(ip), ' not found'
           print *,'  Check your input choice!!!'
       endif
       if (help==1)  call dealloc_soil
       CALL error_mess(time,"soil identificator not found "//adjustl(soilid(ip))//"ip No.",real(help_ip))
       flag_end = 5
       return
     ENDIF   ! ios

  end select  ! flag_soilin
  close(inunit)
endif    ! ex

if (nroot_max .lt. 0) then
    do i=1, nlay
        if (C_hum(i) .gt. zero) nroot_max = i
    enddo
endif
if (.not.flag_mult8910) then
    write (unit_err, *) 'Latitude                ',lat
    write (unit_err,*)
endif

end subroutine readsoil

!-------------------------------------------------------------------------

subroutine readvalue ! Input of cn-parameters and start values for soil model

integer :: inunit   
character :: text

if (flag_trace) write (unit_trace, '(I4,I10,A)') iday, time_cur, ' readvalue'

call testfile(valfile(ip),ex)
IF (ex .eqv. .true.) then
   ios = 0
   inunit = getunit()
   open(inunit,file=valfile(ip),status='old',action='read')
   if (.not.flag_mult8910) print *,' *** Reading initial soil values from file ',valfile(ip),'...'
   do
      read(inunit,*) text
      IF(text .ne. '!')then
         backspace(inunit);exit
      endif
   enddo
 ! Soil temperature
   read(inunit,*,iostat=ios) text
   read(inunit,*,iostat=ios) (temps(i),i=1,nlay)
 ! C-content of humus
    read(inunit,*,iostat=ios) text
    read(inunit,*,iostat=ios) (C_hum(i),i=1,nlay)
 ! N-content of humus
    read(inunit,*,iostat=ios) text
    read(inunit,*,iostat=ios) (N_hum(i),i=1,nlay)
 ! NH4-content
    read(inunit,*,iostat=ios) text
    read(inunit,*,iostat=ios) (NH4(i),i=1,nlay)
 ! NO3-content
    read(inunit,*,iostat=ios) text
    read(inunit,*,iostat=ios) (NO3(i),i=1,nlay)
endif

IF (ios .ne. 0) then
print *,' >>>FORESEE message: Error during reading start values!'
WRITE(*,'(A)',advance='no') '  Stop program (y/n)? '
read *, a
  IF ( a .eq. 'y' .or. a .eq. 'Y') then
  print *, '  STOP program!'
  stop
  ELSE
  call dealloc_soil
  print *,'  Check your input choice!!!'
  end if
endif
close(inunit)

end subroutine readvalue

!--------------------------------------------------------------------------

subroutine alloc_soil
use data_soil_t
use data_soil

if (flag_trace) write (unit_trace, '(I4,I10,A)') iday, time_cur, ' alloc_soil'

help=0
allocate(thick(nlay))
allocate(mid(nlay))
allocate(depth(nlay))
allocate(pv(nlay))
allocate(pv_v(nlay))
allocate(dens(nlay))
allocate(f_cap_v(nlay))
allocate(field_cap(nlay))
allocate(wilt_p(nlay))
allocate(wilt_p_v(nlay))
allocate(vol(nlay))
allocate(quarzv(nlay))
allocate(sandv(nlay))
allocate(BDopt(nlay))
allocate(clayv(nlay))
allocate(siltv(nlay))
allocate(humusv(nlay))
allocate(fcaph(nlay))
allocate(wiltph(nlay))
allocate(pvh(nlay))
allocate(dmass(nlay))
allocate(skelv(nlay))
allocate(skelfact(nlay))
allocate(spheat(nlay))
allocate(phv(nlay))
allocate(wlam(nlay))
allocate(wats(nlay))
allocate(watvol(nlay))
allocate(wat_res(nlay))
wat_res = 0.

allocate(perc(nlay))
allocate(wupt_r(nlay))
allocate(wupt_ev(nlay))
allocate(s_drought(nlay))
allocate(root_fr(nlay))
!allocate(dp_rfr(nlay))
allocate(temps(nlay))
allocate (C_opm(nlay))
allocate (C_hum(nlay))
allocate (C_opmfrt(nlay))
allocate (C_opmcrt(nlay))
allocate (N_opm(nlay))
allocate (N_hum(nlay))
allocate (N_opmfrt(nlay))
allocate (N_opmcrt(nlay))
allocate (NH4(nlay))
allocate (NO3(nlay))
allocate (Nupt(nlay))
allocate (Nmin(nlay))
allocate (rmin_phv(nlay))
allocate (rnit_phv(nlay))
allocate (cnv_opm(nlay))
allocate (cnv_hum(nlay))
allocate(slit(nspecies))
allocate(slit_1(nspecies))

if (flag_bc .gt. 0) then
    allocate (C_bc(nlay))
    allocate (N_bc(nlay))
    C_bc = 0.
    N_bc = 0.
endif

do i=1,nspecies
slit(i)%C_opm_frt = 0.
slit(i)%N_opm_frt = 0.
slit(i)%C_opm_crt = 0.
slit(i)%N_opm_crt = 0.
slit(i)%C_opm_tb = 0.
slit(i)%N_opm_tb = 0.
slit(i)%C_opm_stem = 0.
slit(i)%N_opm_stem = 0.
enddo

nlay2 = nlay+2
mfirst = 1

allocate (sh(mfirst:nlay2))
allocate (sv(mfirst:nlay2))
allocate (sb(mfirst:nlay2))
allocate (sbt(mfirst:nlay2))
allocate (t_cb(mfirst:nlay2))
allocate (t_cond(mfirst:nlay2))
allocate (h_cap(mfirst:nlay2))
allocate (sxx(mfirst:nlay2))
allocate (svv(mfirst:nlay2))
allocate (svva(mfirst:nlay2))
allocate (soh(mfirst:nlay2))
allocate (son(mfirst:nlay2+1))
help=1
C_opm = 0
allocate(fr_loss(nlay))
allocate(redis(nlay))

end subroutine alloc_soil

!------------------------------------------------------------------
subroutine stand_bal_ini

use data_stand

implicit none

integer i   

allocate(diam_class(num_class, nspecies)); diam_class=0
allocate(diam_class_t(num_class, nspecies)); diam_class_t=0
allocate(diam_class_h(num_class,nspecies)); diam_class_h=0
allocate(diam_class_age(num_class,nspecies)); diam_class_age=0
allocate(diam_class_mvol(num_class,nspecies)); diam_class_mvol=0
allocate(diam_classm(num_class,nspecies)); diam_classm=0
allocate(diam_classm_h(num_class,nspecies)); diam_classm_h=0
allocate(height_class(num_class)); height_class =0

! array of potential litter (dead stems and twigs/branches for the next years 
allocate(dead_wood(nspec_tree))
do i = 1,nspec_tree
    allocate(dead_wood(i)%C_tb(lit_year))
    allocate(dead_wood(i)%N_tb(lit_year))
    allocate(dead_wood(i)%C_stem(lit_year))
    allocate(dead_wood(i)%N_stem(lit_year))
    dead_wood(i)%C_tb = 0.
    dead_wood(i)%N_tb = 0.
    dead_wood(i)%C_stem = 0.
    dead_wood(i)%N_stem = 0.
enddo

end subroutine stand_bal_ini

!--------------------------------------------------------------

subroutine control_file ! saving simulation parameter and start conditions for each site
real buckdepth  
character(8) actdate
character(10) acttime
character(150) site_help
integer help_ip,  j
TYPE(Coh_Obj), Pointer :: help_coh  ! pointer to cohort list

IF(site_nr==1) THEN
    help_ip=site_nr
ELSE
    help_ip=ip
END IF

! Write soil initialisation file
if (flag_mult8910) then
    site_help = site_name1
else
    site_help = site_name(help_ip)
endif

if (.not.flag_mult8910 .or. (flag_mult8910 .and. anh .eq. "1") .or. (flag_mult8910 .and. time_out .gt. 0.)) then
    if (.not.flag_mult8910) then
        WRITE (unit_soil,'(26A)') 'Layer',' Depth(cm)',' F-cap(mm)',' F-cap(Vol%)','   Wiltp(mm)', &
          ' Wiltp(Vol%)',' Pore vol.',' Skel.(Vol%)',' Density','  Spheat','      pH','    Wlam',    &
          ' Water(mm)',' Water(Vol%)',' Soil-temp.',' C_opm g/m2', &
          ' C_hum g/m2',' N_opm g/m2',' N_hum g/m2',' NH4 g/m2',' NO3 g/m2','  humus part',' d_mass g/m2', '  Clay','  Silt','  Sand'
        do i = 1,nlay
        WRITE (unit_soil,'(I5,2F10.2,3F12.2,F10.2,F12.2,4F8.2,F10.2,F12.2, 5F11.2,2F9.4,2E12.4, 3F6.1)') i,depth(i),field_cap(i),f_cap_v(i),wilt_p(i), &
              wilt_p_v(i),pv_v(i), skelv(i)*100., dens(i),spheat(i),phv(i),wlam(i),   &
              wats(i),watvol(i),temps(i),c_opm(i),c_hum(i),n_opm(i), n_hum(i),nh4(i),no3(i),humusv(i),dmass(i), clayv(i)*100., siltv(i)*100., sandv(i)*100.

        end do
    endif

    ! Write control file
    call date_and_time(actdate, acttime)
    unit_ctr = getunit()
    open(unit_ctr,file=trim(dirout)//trim(site_help)//'.ctr'//anh,status='replace')
    WRITE(unit_ctr,'(2A)')     '*** Site name: ',site_name(help_ip)
    WRITE(unit_ctr,'(2A)')     '    Appendix ' ,anh
    WRITE(unit_ctr,'(A,F7.2)') '  Longitude: ', long
    WRITE(unit_ctr,'(A,F7.2)') '  Latitude:  ', lat
    WRITE(unit_ctr,*) ' '
    WRITE(unit_ctr,'(10A)') '               ----   Version: v2.2   ---- '  
    WRITE(unit_ctr,'(10A)') '  Date: ',actdate(7:8),'.',actdate(5:6),'.',actdate(1:4), &
                            '  Time: ',acttime(1:2),':',acttime(3:4)
    WRITE(unit_ctr,'(A,A)') '   Simulation control file:      ',trim(simfile)
    WRITE(unit_ctr,*) ' '
    WRITE(unit_ctr,'(A)') '*** Data files:'
    IF(flag_clim==1)then
    WRITE(unit_ctr,'(A,A)') ' Climfile:                   ',trim(climfile(ip))
    ELSE
    WRITE(unit_ctr,'(A,A)') ' Climfile:                   ',trim(climfile(1))
    endif
    WRITE(unit_ctr,'(A,A)') ' Sitefile:                   ',trim(sitefile(help_ip))
    WRITE(unit_ctr,'(A,A)') ' Start value file:           ',trim(valfile(help_ip))

    ! Initialization of stand
    IF( flag_multi==3 .OR. (site_nr>1 .AND. flag_stand>0) ) THEN
    WRITE(unit_ctr,'(A,A)') ' Stand initialization:       ',trim(treefile(ip))
    ELSE IF( ip==1 .AND. flag_stand>0) THEN
    WRITE(unit_ctr,'(A,A)') ' Stand initialization:       ',trim(treefile(ip))
    ELSE IF (flag_stand==0) THEN
    WRITE(unit_ctr,'(A,A)') ' Stand initialization:       none'
    endif
    IF (lmulti) WRITE(unit_ctr,'(A,A)') ' Stand identificator: ', adjustl(standid(ip))
    WRITE(unit_ctr,*) ' '
    IF(flag_mg.ne.0 .and. flag_mg.ne.5) then
    WRITE(unit_ctr,'(A,A)') ' Management control file:   ',trim(manfile(ip))
    ELSE
    WRITE(unit_ctr,'(A)') ' Management:                 none'
    endif
    WRITE(unit_ctr,'(A,A)') ' Deposition file:            ',trim(depofile(ip))
    WRITE(unit_ctr,'(A,A)') ' N reduction file:           ',trim(redfile(ip))
    WRITE(unit_ctr,'(A,A)') ' Litter initialisation file: ',trim(litfile(ip))
    if (flag_stat .gt. 0) WRITE(unit_ctr,'(A,A)') ' File with measurements:     ',trim(mesfile(1))
    WRITE(unit_ctr,*) ' '
    WRITE(unit_ctr,'(A)') '*** Soil description '
    WRITE(unit_ctr,'(A,I3)') ' Number of soil layers:    ',nlay
    WRITE(unit_ctr,'(A,I3)') ' Number of rooting layers: ',nroot_max
    WRITE(unit_ctr,'(A,I3)') ' Ground water from layer:  ',nlgrw
    WRITE(unit_ctr,'(A,F5.1)') ' Evaporation depth (cm):   ',w_ev_d
    call bucket(bucks_100, bucks_root, buckdepth)
    buckdepth = buckdepth/100
    WRITE(unit_ctr,'(A,F5.2,A,F7.2)') ' Bucket size (mm), ', buckdepth,' m depth: ',bucks_100
    WRITE(unit_ctr,'(A,F7.2)') ' Bucket size (mm) of rooting zone: ',bucks_root
    WRITE(unit_ctr,*) ' '
    WRITE(unit_ctr,'(A)') '*** Soil water conditions'
    WRITE(unit_ctr,'(12A)') 'Layer ','Depth(cm) ','F-cap(mm) ','F-cap(Vol%) ','Wiltp(mm) ', &
      'Wiltp(Vol%) ','Pore vol. ','Density   ','Spheat  ','pH-value  ','   Wlam','   skel. '
    do i = 1,nlay
    WRITE(unit_ctr,'(I5,12F10.2)') i,depth(i),field_cap(i),f_cap_v(i),wilt_p(i), &
       wilt_p_v(i),pv_v(i),dens(i),spheat(i),phv(i),wlam(i),skelv(i)
    end do
    WRITE(unit_ctr,*) ' '
    WRITE(unit_ctr,'(A)') '*** Soil initial values'
    WRITE(unit_ctr,'(9A)') 'Layer ','Water-cont. ','Soil-temp. ','C_opm     ', &
      'C_hum     ','N_opm     ','N_hum     ','NH4-cont. ','NO3-cont '
    do i=1,nlay
    WRITE(unit_ctr,'(I5, 2F10.2, 6F10.4)') i,wats(i),temps(i),c_opm(i),c_hum(i),n_opm(i), &
      n_hum(i),nh4(i),no3(i)
    end do
    WRITE(unit_ctr,*) ' '
    WRITE(unit_ctr,'(A)') '       N_tot       C_tot     N_antot    N_humtot    C_humtot   C_opm_fol   C_opm_tb   C_opm_frt   C_opm_crt   C_opm_stem '
    WRITE(unit_ctr,'(10F12.4)') N_tot, C_tot, N_an_tot, N_hum_tot, C_hum_tot, C_opm_fol, C_opm_tb, C_opm_frt, C_opm_crt, C_opm_stem
    WRITE(unit_ctr,*) ' '
    WRITE(unit_ctr,'(A)',advance='no') 'Mineralization constant of humus - humus layer (k_hum): '
    WRITE(unit_ctr,'(F10.5)') k_hum
    WRITE(unit_ctr,'(A)',advance='no') 'Mineralization constant of humus - mineral soil (k_hum_r): '
    WRITE(unit_ctr,'(F10.5)') k_hum_r
    WRITE(unit_ctr,'(A)',advance='no') 'Nitrification constant (k_nit): '
    WRITE(unit_ctr,'(F10.5)') k_nit
    WRITE(unit_ctr,*) ' '
    if (flag_bc .gt.0) then
    WRITE(unit_ctr,'(A)') '*** Biochar application '
    WRITE(unit_ctr,'(A)') '    year  C-content(%)  C/N-ratio  depth  mass(kg/ha dry mass)'
      do j = 1, n_appl_bc
      WRITE(unit_ctr,'(I7,F14.1, F11.1, I7, F18.1)') &
            y_bc(j), cpart_bc(j), cnv_bc(j), bc_appl_lay(j), C_bc_appl(j)      
      enddo
    WRITE(unit_ctr,'(F10.5)')  
    endif
    WRITE(unit_ctr,*) ' '
    WRITE(unit_ctr,'(A)') '*** Stand initialisation'
    WRITE(unit_ctr,'(A)')'  Coh      x_fol       x_frt       x_sap       x_hrt       x_Ahb     height   x_hbole  x_age      n     sp       DC          DBH'
    help_coh => pt%first
    DO WHILE (ASSOCIATED(help_coh))
    WRITE(unit_ctr,'(I5,5f12.5,2f10.0,i7,f7.0,i7, 2f12.5)') help_coh%coh%ident, help_coh%coh%x_fol, help_coh%coh%x_frt, help_coh%coh%x_sap, help_coh%coh%x_hrt, &
              help_coh%coh%x_Ahb, help_coh%coh%height, help_coh%coh%x_hbole, help_coh%coh%x_age, &
              help_coh%coh%nTreeA,help_coh%coh%species, help_coh%coh%dcrb, help_coh%coh%diam
    help_coh => help_coh%next
    END DO
    WRITE(unit_ctr,*) ' '
    WRITE(unit_ctr,'(A)') '*** Simulation control'
    WRITE(unit_ctr,'(A66,I4)') 'Run option:                                                       ',flag_multi
    WRITE(unit_ctr,'(A66,I4)') 'Start year:                                                       ',time_b
    WRITE(unit_ctr,'(A66,I4)') 'Number of simulation years - year:                                ', year
    WRITE(unit_ctr,'(A60,F12.1)') 'Patch size [m²] - kpatchsize:                                     ',kpatchsize
    WRITE(unit_ctr,'(A60,F12.1)') 'Thickness of leaf layers - dz:                                    ',dz
    WRITE(unit_ctr,'(A66,I4)') 'Time step for photosynthesis calculations (days) -    ns_pro:     ',ns_pro
    WRITE(unit_ctr,'(A66,I4)') 'Mortality (0-OFF,1-ON stress, 2- ON stress+intr) -  flag_mort:    ',flag_mort
    WRITE(unit_ctr,'(A66,I4)') 'Regeneration (0-OFF,1-ON, 2-weekly growth of seedl.) - flag_reg:  ',flag_reg
    WRITE(unit_ctr,'(A66,I4)') 'use FORSKA for regeneration (0-OFF,1-ON) - flag_forska:           ',flag_lambda
    WRITE(unit_ctr,'(A66,I4)') 'Stand initialization (0-no,1-from *.ini,2-generate) - flag_stand: ',flag_stand
    WRITE(unit_ctr,'(A66,I4)') 'Ground vegetation initialization (0-no,1-generate) - flag_sveg:     ',flag_sveg
    WRITE(unit_ctr,'(A66,I4)') 'Stand management (0-no,1-yes, 2 - seed once) - flag_mg:           ',flag_mg
    WRITE(unit_ctr,'(A66,I4)') 'Disturbance (0-OFF, 1-ON ) - flag_dis:                            ',flag_dis
    WRITE(unit_ctr,'(A66,I4)') 'Light absoption algorithm (1,2,3,4) - :                           ',flag_light
    WRITE(unit_ctr,'(A66,I4)') 'Foliage-height relationship (0,1) - flag_folhei:                  ',flag_folhei
    WRITE(unit_ctr,'(A66,I4)') 'Volume function trunc (0,1) - flag_volfunc:                       ',flag_volfunc
    WRITE(unit_ctr,'(A66,I4)') 'Respiration model (0-0.5*NPP,1-organ specific) - flag_resp:       ',flag_resp
    WRITE(unit_ctr,'(A66,I4)') 'Limitation (0-NO,1-water, 2-N, 3-water+N) - flag_limi:            ',flag_limi
    WRITE(unit_ctr,'(A66,I4)') 'Flag for decomposition model - flag_decomp:                       ',flag_decomp
    WRITE(unit_ctr,'(A66,I4)') 'Root spec. activity (0-const,1-varying) - flag_sign:              ',flag_sign
    WRITE(unit_ctr,'(A66,I4)') 'Water uptake function soil (1,2,3,4) - flag_wred:                 ',flag_wred
    WRITE(unit_ctr,'(A66,I4)') 'Root distribution - flag_wurz:                                    ',flag_wurz
    WRITE(unit_ctr,'(A66,I4)') 'Heat conductance - flag_cond:                                     ',flag_cond
    WRITE(unit_ctr,'(A66,I4)') 'Interception - flag_int:                                          ',flag_int
    WRITE(unit_ctr,'(A66,I4)') 'Evapotranspiration - flag_eva:                                    ',flag_eva
    WRITE(unit_ctr,'(A66,I4)') 'CO2 (0-constant,1-historic increase,2-step change)- flag_co2:     ',flag_co2
    WRITE(unit_ctr,'(A66,I4)') 'Sort flag - flag_sort:                                            ',flag_sort
    WRITE(unit_ctr,'(A66,I4)') 'wpm flag - flag_wpm:                                              ',flag_wpm
    WRITE(unit_ctr,'(A66,I4)') 'Analysis of measurements - flag_stat:                             ',flag_stat
    WRITE(unit_ctr,*) ' '
    WRITE(unit_ctr,'(A66,A)')  'Species parameter file:                                           ',trim(specfile(help_ip))
    WRITE(unit_ctr,*) ' '
    WRITE(unit_ctr,'(A)') '*** Species parameter description'
    WRITE(unit_ctr,'(A51,I4)')   ' Species number: ', nspecies
    WRITE(unit_ctr,'(A51,I4)')   ' Number of tree species: ', nspec_tree
    WRITE(unit_ctr,*) '              ********** '
    WRITE(unit_ctr,'(A25,A9,2X,A30)') 'Short Name', '  Spec-Nr', 'Latin Name                   '
    WRITE(unit_ctr,*) ' '
    do i=1,nspecies
    WRITE(unit_ctr,'(A25,I9,2X,A30)') trim(spar(i)%species_short_name), i, spar(i)%species_name
    enddo
    WRITE(unit_ctr,*) '              ********** '
    WRITE(unit_ctr,'(A51,15A16)')   ' Species name: ', (trim(spar(i)%species_short_name),i=1,nspecies)
    WRITE(unit_ctr,1010) ' Maximal age - max_age: ', (spar(i)%max_age,i=1,nspecies)
    WRITE(unit_ctr,1010) ' Stress rec. time - yrec: ', (spar(i)%yrec,i=1,nspecies)
    WRITE(unit_ctr,1010) ' Shade tolerance - stol: ', (spar(i)%stol,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Extinction coeff - pfext: ', (spar(i)%pfext,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Root activity rate - sigman: ', (spar(i)%sigman,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Respiration coeff - respcoeff: ', (spar(i)%respcoeff,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Growth resp. par. - prg: ', (spar(i)%prg,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Maint.resp.par./sapwood - prms: ', (spar(i)%prms,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Maint.resp.par./fineroot - prmr: ', (spar(i)%prmr,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Senesc.par. foliage - psf: ', (spar(i)%psf,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Senesc.par. sapwood - pss: ', (spar(i)%pss,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Senesc.par. fineroot - psr: ', (spar(i)%psr,i=1,nspecies)
    WRITE(unit_ctr,1000) ' N/C ratio of biomass - pcnr: ', (spar(i)%pcnr,i=1,nspecies)
    WRITE(unit_ctr,1000) ' N concentration of foliage - ncon_fol: ', (spar(i)%ncon_fol,i=1,nspecies)
    WRITE(unit_ctr,1000) ' N concentration of fine roots - ncon_frt: ', (spar(i)%ncon_frt,i=1,nspecies)
    WRITE(unit_ctr,1000) ' N concentration of coarse roots - ncon_crt: ', (spar(i)%ncon_crt,i=1,nspecies)
    WRITE(unit_ctr,1000) ' N concentration of twigs and branches - ncon_tbc: ', (spar(i)%ncon_tbc,i=1,nspecies)
    WRITE(unit_ctr,1000) ' N concentration of stemwood - ncon_stem: ', (spar(i)%ncon_stem,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Reallocation parameter of foliage - reallo_fol: ', (spar(i)%reallo_fol,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Reallocation parameter of fine root - reallo_frt: ', (spar(i)%reallo_frt,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Ratio of coarse wood - alphac: ', (spar(i)%alphac,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Coarse root fraction of coarse wood - cr_frac: ', (spar(i)%cr_frac,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Sapwood density - prhos: ', (spar(i)%prhos,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Proport.const.(pipe mod.) - pnus: ', (spar(i)%pnus,i=1,nspecies)
    IF(flag_folhei==0) THEN
    WRITE(unit_ctr,1000) ' Height growth parameter - pha: ', (spar(i)%pha,i=1,nspecies)
    ELSEIF(flag_folhei==1) THEN
    WRITE(unit_ctr,1000) ' Height growth par. 1 - pha_v1: ', (spar(i)%pha_v1,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Height growth par. 2 - pha_v2: ', (spar(i)%pha_v2,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Height growth par. 3 - pha_v3: ', (spar(i)%pha_v3,i=1,nspecies)
    ELSE
    WRITE(unit_ctr,'(A51,I3)')     ' non valid flag value - flag_folhei : ',flag_folhei
    ENDIF
    WRITE(unit_ctr,1000) ' Height growth parameter coeff 1 - pha_coeff1: ', (spar(i)%pha_coeff1,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Height growth parameter coeff 2 - pha_coeff2: ', (spar(i)%pha_coeff2,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Crown radius - DBH ratio parameter a - crown_a: ', (spar(i)%crown_a,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Crown radius - DBH ratio parameter b - crown_b: ', (spar(i)%crown_b,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Crown radius - DBH ratio parameter c - crown_c: ', (spar(i)%crown_c,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Minimum specific leaf area - psla_min: ', (spar(i)%psla_min,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Light dep. specific leaf area - psla_a: ', (spar(i)%psla_a,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Efficiency parameter - phic: ', (spar(i)%phic,i=1,nspecies)
    WRITE(unit_ctr,1000) ' N content - pnc: ', (spar(i)%pnc,i=1,nspecies)
    WRITE(unit_ctr,1000) ' kco2_25: ', (spar(i)%kCO2_25,i=1,nspecies)
    WRITE(unit_ctr,1000) ' ko2_25: ', (spar(i)%kO2_25,i=1,nspecies)
    WRITE(unit_ctr,1000) ' CO2/O2 specif. value - pc_25: ', (spar(i)%pc_25,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Q10_kco2: ', (spar(i)%q10_kCO2,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Q10_ko2: ', (spar(i)%q10_kO2,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Q10_pc: ', (spar(i)%q10_pc,i=1,nspecies)
    WRITE(unit_ctr,1000) ' Rd to Vm ratio - pb: ', (spar(i)%pb,i=1,nspecies)

    WRITE(unit_ctr,1000) ' PIM: Inhibitor min temp. - PItmin: ', (spar(i)%PItmin,i=1,nspecies)
    WRITE(unit_ctr,1000) ' PIM: Inhibitor opt temp. - PItopt: ', (spar(i)%PItopt,i=1,nspecies)