Subroutine random_samples

  1 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2 : !random run of VOM
  3 : !
  4 : !
  5 : !
  6 : !
  7 : !
  8 : !
  9 : !
 10 : !
 11 : !
 12 : !
 13 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 14 : !
 15 : ! Copyright (C) 2008 Stan Schymanski
 16 : !
 17 : !   This program is free software: you can redistribute it and/or modify
 18 : !   it under the terms of the GNU General Public License as published by
 19 : !   the Free Software Foundation, either version 3 of the License, or
 20 : !   (at your option) any later version.
 21 : !
 22 : !   This program is distributed in the hope that it will be useful,
 23 : !   but WITHOUT ANY WARRANTY; without even the implied warranty of
 24 : !   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 25 : !   GNU General Public License for more details.
 26 : !
 27 : !   You should have received a copy of the GNU General Public License
 28 : !   along with this program. If not, see .
 29 : !
 30 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 31 : 
 32 : 
 33 : subroutine random_samples ()
 34 : 
 35 : use vom_sce_mod
 36 : use vom_vegwat_mod
 37 : 
 38 :       implicit none
 39 : 
 40 : 
 41 :       real*8,dimension(6)              :: r        !random values
 42 :       integer                          :: n        !number of iterations
 43 :       real*8,dimension(6)              :: paramset !random parameterset
 44 :       integer                          :: i_loop   !current loop
 45 :       real*8                           :: obj      !objective ncp
 46 :       INTEGER                          :: iostat   !input-output status
 47 : 
 48 :       namelist /outputfiles/ vd_d_out, &
 49 :                              esoil_out, &
 50 :                              jmax25t_out, &
 51 :                              jmax25g_out, &
 52 :                              vegcov_out, &
 53 :                              resp_out, &
 54 :                              lambdat_out, &
 55 :                              lambdag_out, &
 56 :                              rrt_out, &
 57 :                              rrg_out, &
 58 :                              asst_out, &
 59 :                              assg_out, &
 60 :                              su_av_out, &
 61 :                              zw_out, &
 62 :                              wsnew_out, &
 63 :                              spgfcf_out, &
 64 :                              infx_out, &
 65 :                              etmt_out, &
 66 :                              etmg_out, &
 67 :                              su1_out, &
 68 :                              topt_out
 69 : 
 70 :       open(kfile_outputlist, FILE=sfile_outputlist, STATUS='old',          &
 71 :      &                     FORM='formatted', IOSTAT=iostat)
 72 :       if (iostat .eq. 0) then
 73 :         read(kfile_outputlist, outputfiles)
 74 :       endif
 75 :       close(kfile_outputlist)
 76 : 
 77 :       !read settings for optimization
 78 :       call read_shufflepar()
 79 : 
 80 :       !read max and min ranges of parameters
 81 :       call read_shufflevar ()
 82 : 
 83 : 
 84 :       !initialize random seed 
 85 :       call random_seed()
 86 :       call transpmodel_init_once(vom_command)
 87 : 
 88 :       !open file for output
 89 :       open(kfile_random_output, FILE=trim(adjustl(i_outputpath)) // trim(adjustl(sfile_random_output)))
 90 :       open(kfile_random_params, FILE=trim(adjustl(i_outputpath)) // trim(adjustl(sfile_random_params)))
 91 : 
 92 : 
 93 :      call open_output_randomruns()
 94 : 
 95 : 
 96 :       !loop for n random samples, needs parallelization
 97 :       do i_loop=1, i_iter
 98 : 
 99 :          write(*,*) "i_loop", i_loop
100 : 
101 :          !generate random number between 0  and 1
102 :          call random_number(r)
103 : 
104 :          !make a random parameterset
105 :          paramset=r*(parmax-parmin)+parmin
106 : 
107 :          !run the model with the random set
108 : 
109 :          call transpmodel(paramset, vom_npar, obj, vom_command)
110 : 
111 : 
112 : 
113 : 
114 :          write(kfile_random_output, *) obj
115 :          write(kfile_random_params, *) paramset
116 : 
117 :       end do
118 : 
119 :       close( kfile_random_output )
120 :       close( kfile_random_params )
121 : 
122 :      call close_output_randomruns()
123 : 
124 : 
125 : end subroutine