TreeMig Code
Loading...
Searching...
No Matches
ReadControlPars.f90
Go to the documentation of this file.
1!==============================================================================
2!
3! File : ReadControlPars
4!
5! Remarks: contains the module WriteLineMod
6! and the subroutine ReadControlPars
7!
8!
9!==============================================================================
10!==============================================================================
11!
12! Module : WriteLineMod
13!
14! CONTAINS subroutines:
15! RWLine
16! RWInteger
17! RWReal
18! RWLogical
19! RWChar
20! CheckWriteError
21! CheckReadError
22! ReadSeveralValuesSameTypeFromLine
23! ReadWriteSeveralValuesSameTypeFromLine
24! AssignReportIntervals
25!==============================================================================
27 use loggermodule
29 contains
30
31!==============================================================================
43!==============================================================================
44 SUBROUTINE rwinteger(outInt)
45 IMPLICIT NONE
46
47 INTEGER, INTENT(out) :: outInt
48 character(len=:), allocatable :: word
49 character(len=:), allocatable:: comment
50 INTEGER :: err
51
52 call extractword(controlpars_file,1,word, comment, err) ! reads in 1st characterstring and rest (comment) from actual line in controlpars
53 call checkreaderror(err)
54
55 read(word, "("//format_integer//")", iostat=err) outint ! converts it into integer
56 if(err /= 0) then
57 call logerror("Could not cast to TYPE INTEGER in controlParsFile: ->"//word//"<-"//comment)
58 error stop
59 end if
60
61 write(controlparsout_file%unit,"("//format_integer//",A)", iostat=err) outint, comment
62 call checkwriteerror(err)
63
64 end SUBROUTINE rwinteger
65
66!==============================================================================
78!==============================================================================
79 SUBROUTINE rwreal(outReal)
80 IMPLICIT NONE
81
82 REAL, INTENT(out) :: outReal
83 character(len=:), allocatable :: word
84 character(len=:), allocatable:: comment
85 INTEGER :: err
86
87 call extractword(controlpars_file,1,word, comment, err) ! reads in 1st characterstring and rest (comment) from actual line in controlpars
88 call checkreaderror(err)
89
90 read(word, "("//format_real//")", iostat=err) outreal
91 if(err /= 0) then
92 call logerror("Could not cast to TYPE REAL in controlParsFile: ->"//word//"<-"//comment)
93 error stop
94 end if
95
96 write(controlparsout_file%unit,"("//format_real//",A)", iostat=err) outreal, comment
97 call checkwriteerror(err)
98
99 end SUBROUTINE rwreal
100
101!==============================================================================
113!==============================================================================
114 SUBROUTINE rwchar(outChar)
115 IMPLICIT NONE
116
117 character(len=:), allocatable, INTENT(out) :: outChar
118 character(len=:), allocatable :: word
119 character(len=:), allocatable:: comment
120 INTEGER :: err
121
122 call extractword(controlpars_file,1,word, comment, err) ! reads in 1st characterstring and rest (comment) from actual line in controlpars
123 call checkreaderror(err)
124 outchar = word
125 if(err /= 0) then
126 call logerror("Could not cast to TYPE CHARCATER in controlParsFile: ->"//word//"<-"//comment)
127 error stop
128 end if
129
130 write(controlparsout_file%unit,"("//format_character//",A)", iostat=err) outchar, comment
131 call checkwriteerror(err)
132
133 end SUBROUTINE rwchar
134
135!==============================================================================
136! @brief RWLogical
137! *****************************************
147!==============================================================================
148 SUBROUTINE rwlogical(outLogical)
149 IMPLICIT NONE
150
151 LOGICAL, INTENT(out) :: outLogical
152 character(len=:), allocatable :: word
153 character(len=:), allocatable:: comment
154 INTEGER :: err
155
156 call extractword(controlpars_file,1,word, comment, err) ! reads in 1st characterstring and rest (comment) from actual line in controlpars
157 call checkreaderror(err)
158
159 read(word, "("//format_logical//")", iostat=err) outlogical
160 if(err /= 0) then
161 call logerror("Could not cast to TYPE LOGICAL in controlParsFile: ->"//word//"<-"//comment)
162 error stop
163 end if
164
165 write(controlparsout_file%unit,"("//format_logical//",A)", iostat=err) outlogical, comment
166 call checkwriteerror(err)
167
168 end SUBROUTINE rwlogical
169
170!==============================================================================
180!==============================================================================
181 SUBROUTINE checkwriteerror(err)
182 IMPLICIT NONE
183 INTEGER, INTENT(in) :: err
184 if(err /= 0) then
185 call logerror("Could not write line in output controlParsFile: "//controlparsout_file%path)
186 error stop
187 end if
188 end SUBROUTINE checkwriteerror
189
190!==============================================================================
200!==============================================================================
201 SUBROUTINE checkreaderror(err)
202 IMPLICIT NONE
203 INTEGER, INTENT(in) :: err
204 if(err /= 0) then
205 call logerror("Could not read line in controlParsFile: "//controlpars_file%path)
206 error stop
207 end if
208 end SUBROUTINE checkreaderror
209
210!==============================================================================
224!==============================================================================
225 SUBROUTINE readseveralvaluessametypefromline(nvals, rest, err, vec_INTEGER, vec_REAL, vec_CHAR, vec_LOGICAL)
227 use loggermodule
228 IMPLICIT NONE
229 character(len=:), allocatable, INTENT(out) :: rest
230 INTEGER, INTENT(out) :: err
231 INTEGER, INTENT(out) :: nvals
232
233 INTEGER, dimension(10), INTENT(out), optional :: vec_INTEGER
234 REAL, dimension(10), INTENT(out), optional :: vec_REAL
235 character(len=30), INTENT(out), optional :: vec_CHAR (10)
236 LOGICAL, dimension(10), INTENT(out), optional :: vec_LOGICAL
237
238 character(len=30), dimension(50) :: wordsvec
239 INTEGER:: iword
240 !---- get a vector of strings for values and the rest (e.g. comment) from the buffer
241 call extractandcountwords(controlpars_file, nvals, wordsvec, rest, err)
242
243 if(err /= 0) then
244 call logerror("Could not read line in controlParsFile: "//controlpars_file%path)
245 error stop
246 end if
247 !---- convert each of these strings to a value and store it in the corresponding vector
248 do iword = 1, nvals
249 if(present(vec_integer))then
250 read(wordsvec(iword), "("//format_integer//")", iostat=err) vec_integer(iword)
251 else if (present(vec_real)) then
252 read(wordsvec(iword), "("//format_real//")", iostat=err) vec_real(iword)
253 else if (present(vec_char)) then
254 vec_char(iword) = wordsvec(iword )
255 else if (present(vec_logical)) then
256 read(wordsvec(iword), "("//format_logical//")", iostat=err) vec_logical(iword)
257 end if
258 end do ! iword
259
261
262!=============================================================================
280!==============================================================================
281 SUBROUTINE readwriteseveralvaluessametypefromline( nvals, err, vec_INTEGER, vec_REAL, vec_CHAR, vec_LOGICAL)
282
284 use loggermodule
285 IMPLICIT NONE
286 character(len=:), allocatable :: rest
287 INTEGER, INTENT(out) :: err
288 INTEGER, INTENT(out) :: nvals
289
290 INTEGER, dimension(10), INTENT(out), optional :: vec_INTEGER
291 REAL, dimension(10), INTENT(out), optional :: vec_REAL
292 character(len=30), INTENT(out), optional :: vec_char (10)
293 LOGICAL, dimension(10), INTENT(out), optional :: vec_LOGICAL
294 INTEGER:: i
295 character (len=3) :: nvalschar
296 character(len=3), parameter :: FORMAT_INTEGER_narrow = "I5"
297 !--- get the vector to be read in and its number of elements (nvals)
298 call readseveralvaluessametypefromline( nvals, rest, err, vec_integer, vec_real, vec_char, vec_logical)
299 !--- write out to the copy of the control pars file
300 call inttochar(3,nvals,nvalschar)
301 if(present(vec_integer))then
302 if(nvals == 0) then
303 write(controlparsout_file%unit,"(A)", iostat=err) &
304 rest
305 else
306 write(controlparsout_file%unit,"("// nvalschar// "("//format_integer_narrow//") ,A)", iostat=err) &
307 ( vec_integer(i), i= 1,nvals), rest
308 end if
309 else if (present(vec_real)) then
310 write(controlparsout_file%unit,"("// nvalschar// "("//format_real//") ,A)", iostat=err) &
311 ( vec_real(i), i= 1,nvals), rest
312 else if (present(vec_char)) then
313 write(controlparsout_file%unit,"("// nvalschar// "("//format_character//") ,A)", iostat=err) &
314 ( vec_char(i), i= 1,nvals), rest
315 else if (present(vec_logical)) then
316 write(controlparsout_file%unit,"("// nvalschar// "("//format_logical//") ,A)", iostat=err) &
317 ( vec_logical(i), i= 1,nvals), rest
318
319 end if
320
322!==============================================================================
342!==============================================================================
343 SUBROUTINE assignreportintervals(nvals, repInts)
344
346 use loggermodule
347 IMPLICIT NONE
348 INTEGER, INTENT(in ):: nvals
349 INTEGER, INTENT(in ):: repInts(30)
350 INTEGER:: i, irepInts, simuendyear
351 character (len=3) :: charvar
352 !--- write the report invervals, their starts and ends to an array
353 simuendyear = simustartyear + numyrs
354 reportintervals = simuendyear + 1
355 if (nvals == 1) then ! only one interval for entire simulation
356 reportintervals(1,1) = repints(1)
358 reportintervals(1,3) = simuendyear
360 else if (mod(nvals,3) == 0 ) then ! correct intervals, store the interval, start and end for all ReportIntervals
361 nreportintervals = nvals/3
362 do irepints = 1, nreportintervals
363 reportintervals(irepints,1) = repints((irepints-1)*3 +1)
364 reportintervals(irepints,2) = repints((irepints-1)*3 +2)
365 reportintervals(irepints,3) = repints((irepints-1)*3 +3)
366 end do
367 else
368 call inttochar(3,nvals,charvar)
369 call logerror("Number of values for report interval must be 1 or multiple of 3"// charvar)
370 error stop
371 end if
372 !--- write the infos
373 call loginfo("Output will be written")
374 do i =1,nreportintervals
375 if(reportintervals(i,1) == 1) then
376 write(logmessage, "(A,I5,A,I5)") " every year from ",&
377 reportintervals(i,2)," to ",reportintervals(i,3)
378 else
379 write(logmessage, "(A,I4,A,I5,A,I5)") " every ", reportintervals(i,1), " years from ",&
380 reportintervals(i,2)," to ", reportintervals(i,3)
381 end if
382 call loginfo(logmessage)
383 end do
384 call loginfo(" every year for all other years")
385end SUBROUTINE assignreportintervals
386end module writelinemod
387!==============================================================================
448!==============================================================================
449SUBROUTINE readcontrolpars()
450
451
452 use all_par, only: numyrs, &
454 maxlat, maxlon,&
469 driverdefault ! Use control and species parameters
470 use writelinemod
471 use loggermodule
473 IMPLICIT NONE
474 ! Local variables ---------------------------------------------------------------------------------
475 INTEGER :: err, nvals
476 INTEGER :: repInts(30)
477
478 character(len=:), allocatable :: dummy
479 character(len=:), allocatable :: rest
480
481 !Here the SUBROUTINE starts **********************************************************************
482 !---- opens the control pars file
483 call loginfo("Reading control-pars file: "//controlpars_file%path)
484 call openfiler(controlpars_file, err) ! closed (this l. 271)
485 if(err /= 0) then
486 call logerror("Cannot open control-pars file:"//controlpars_file%path)
487 error stop
488 end if
489
490 !---- Experiment ID ----
491 call extractword(controlpars_file,1,dummy, rest, err)
492 call checkreaderror(err)
493 call extractword(controlpars_file,1,experimentid, rest, err)
494 call checkreaderror(err)
495 ! we got experimentID, so we can define the resultPath for the output files
496 resultpath = relativepathletter//"R"//pathletter//experimentid//pathletter
497 resultpath_h = resultpath // "HCL/"
498 statepath = relativepathletter//"S"//pathletter//experimentid//pathletter
499 ! CREATE DIR FOR RESULTS
500 call execute_command_line ('mkdir '//'"'//resultpath//'"', exitstat=err)
501 call execute_command_line ('mkdir '//'"'//resultpath_h//'"' , exitstat=err)
502 call execute_command_line ('mkdir '//'"'//statepath//'"' , exitstat=err)
503
504
505 controlparsout_file%path = resultpath//experimentid//"_"//"control.pars"
506 call openfilew(controlparsout_file, err) ! closed (this l. 272)
507 if (err /= 0) then
508 call logerror("Could not create output control-pars file:"//controlparsout_file%path)
509 error stop
510 end if
511 !
512
513 write(controlparsout_file%unit,"("//format_character//",A)", iostat=err) dummy, " Simulation ====="
514 call checkwriteerror(err)
515 write(controlparsout_file%unit,"("//format_character//",A)", iostat=err) experimentid, rest
516 call checkwriteerror(err)
517
518!---- Time
519 call rwchar(dummy) ! The dummy reading is for the empty lines in the control file
520 call rwinteger(numyrs)
522
523 call readwriteseveralvaluessametypefromline(nvals, err, vec_integer=repints)
524 call assignreportintervals(nvals, repints)
527
528 call readwriteseveralvaluessametypefromline(nvals, err, vec_integer=stateoutputyears)
530
532 if (readstatefile) then
533 if (inoculationtime /=0) then
535 call loginfo("inoculation time set to 0, because simulation starts from initial values")
536 end if
537 else
538 if(inoculationtime == 0) then
539 call logerror("inoculation time is zero and no initial values => no trees. Set it to >=1");
540 error stop
541 end if
542 end if
543!---- Space
544 call rwchar(dummy) !
545 call rwreal(pltsiz)
546 call rwinteger(maxlat)
547 call rwinteger(maxlon)
550 call rwreal(lonrealstart)
551 call rwreal(lonrealend)
552 call rwreal(latrealstart)
553 call rwreal(latrealend)
554
559 call rwchar(boundaries)
560!---- Environment
561 call rwchar(dummy)
565!---- Defaults for other drivers
566 call rwchar(dummy)
567 call rwreal(driverdefault(7))
568 call rwreal(driverdefault(8))
569 call rwreal(driverdefault(9))
570 call rwreal(driverdefault(10))
571!---- Dispersal
572 call rwchar(dummy)
573 call rwlogical(dofft)
576 call rwreal(epskernel)
577 epskernel = epskernel * 1.e-5
578 call rwreal(alpha_all)
579 call rwlogical(active)
582!---- Seeds
583 call rwchar(dummy)
588!---- Density regulation
589 call rwchar(dummy)
592 call rwreal(seedantagraz)
593 call rwreal(seedantaeff)
594 call rwreal(seedantamort)
595 call rwreal(seedantarain)
597 call rwreal(seedcarrcap)
598 seedcarrcap = seedcarrcap * pltsiz / 833.0 ! scale from 833 to the chosen plot size
599!--- Immigration
600 call rwchar(dummy)
602 call rwchar(immifilename)
603!---- Disturbances
604 call rwchar(dummy)
606 call rwreal(disturbprob)
608!---- Light
609 call rwchar(dummy)
610 call rwreal(fcvarinit)
611 call rwreal(fcvardyn)
612!---- Clump (but actually these parameters refer to the establishment)
613 call rwchar(dummy)
616!---- Species File
617 call rwchar(dummy)
618 call rwchar(specfilename)
619!---- Output
620 call rwchar(dummy)
621 call rwlogical(writeoutput%netcdf)
622 call rwlogical(writeoutput%biomass)
623 call rwlogical(writeoutput%number)
624 call rwlogical(writeoutput%hstruct)
625 call rwlogical(writeoutput%seeds)
626 call rwlogical(writeoutput%antagonists)
627 call rwlogical(writeoutput%pollen)
628 call rwlogical(writeoutput%lai)
629 call rwlogical(writeoutput%basalArea)
630 call rwlogical(writeoutput%NPP)
631 call rwlogical(writeoutput%ingrowth)
632 call rwlogical(writeoutput%biodiv)
633 call rwlogical(writeoutput%light)
635!---- Check and close the file
636 if(err /= 0) then
637 call logerror("Error reading control pars file:"//controlpars_file%path);
638 error stop
639 end if
640
641 call closefile(controlpars_file)
642 call closefile(controlparsout_file)
643 end SUBROUTINE readcontrolpars
644 ! ****<Here the SUBROUTINE ends>******************************************************************
645
subroutine inttochar(ndigits, intvalue, charvar)
IntToChar
Definition IntToChar.f90:43
subroutine readcontrolpars()
ReadControlPars
character(len=:), allocatable experimentid
Definition All_par.f90:105
real latrealend
Definition All_par.f90:50
real pltsiz
Definition All_par.f90:125
integer stateoutputdist
Definition All_par.f90:31
real seedantamort
Definition All_par.f90:80
real lonrealstart
Definition All_par.f90:50
integer kerneltype
Definition All_par.f90:66
integer simustartyear
Definition All_par.f90:27
logical estabeqhc0
Definition All_par.f90:90
integer startlatend
Definition All_par.f90:52
logical envfromfile
Definition All_par.f90:59
logical includeenv
Definition All_par.f90:58
real seedantaeff
Definition All_par.f90:79
integer, dimension(10, 3) reportintervals
Definition All_par.f90:29
real seedlcrowndiamincm
Definition All_par.f90:127
real seedantarain
Definition All_par.f90:81
real cellsidelength
Definition All_par.f90:63
logical withseedantagonists
Definition All_par.f90:77
real unitofspatialdata
Definition All_par.f90:53
real disturbprob
Definition All_par.f90:87
logical calcseedbank
Definition All_par.f90:75
logical readstatefile
Definition All_par.f90:56
logical withseedcarrcap
Definition All_par.f90:82
logical dispersaldifferent
Definition All_par.f90:72
real disturbintensity
Definition All_par.f90:88
real lonrealend
Definition All_par.f90:50
real seedantagraz
Definition All_par.f90:78
integer startlonend
Definition All_par.f90:52
logical contlightdepgerm
Definition All_par.f90:91
type(wroutp) writeoutput
Definition All_par.f90:143
logical disturbances
Definition All_par.f90:86
integer numyrs
Definition All_par.f90:26
real, dimension(nalloweddrivernames) driverdefault
Definition All_par.f90:115
real fcvardyn
Definition All_par.f90:124
character(len=:), allocatable bioclimfilename
Definition All_par.f90:103
real latrealstart
Definition All_par.f90:50
character(len=:), allocatable e
Definition All_par.f90:93
character(len=:), allocatable specfilename
Definition All_par.f90:101
integer, dimension(10) stateoutputyears
Definition All_par.f90:32
logical seedsdifferent
Definition All_par.f90:70
integer maxlon
Definition All_par.f90:46
logical mastseeding
Definition All_par.f90:74
integer startlatstart
Definition All_par.f90:52
integer nreportintervals
Definition All_par.f90:30
integer outerseeds
Definition All_par.f90:94
real seedcarrcap
Definition All_par.f90:83
character(len=:), allocatable boundaries
Definition All_par.f90:93
logical tabsepoutput
Definition All_par.f90:89
real epskernel
Definition All_par.f90:64
logical dofft
Definition All_par.f90:73
logical mathgtdifferent
Definition All_par.f90:71
character(len=:), allocatable immifilename
Definition All_par.f90:102
integer, allocatable, parameter immigration
Definition All_par.f90:37
integer inoculationtime
Definition All_par.f90:55
logical dostochseeddisp
Definition All_par.f90:69
real alpha_all
Definition All_par.f90:62
real fcvarinit
Definition All_par.f90:123
integer startlonstart
Definition All_par.f90:52
logical active
Definition All_par.f90:68
integer maxlat
Definition All_par.f90:45
character(len=:), allocatable statepath
character(len=:), allocatable resultpath
type(file) controlpars_file
character(len=:), allocatable resultpath_h
type(file) controlparsout_file
LoggerModule.
subroutine loginfo(msg)
LogInfo
character(len=1024) logmessage
subroutine logerror(msg)
LogError
subroutine assignreportintervals(nvals, repints)
AssignReportIntervals
subroutine rwchar(outchar)
RWChar
subroutine rwreal(outreal)
RWReal
subroutine readwriteseveralvaluessametypefromline(nvals, err, vec_integer, vec_real, vec_char, vec_logical)
ReadWriteSeveralValuesSameTypeFromLine
subroutine checkwriteerror(err)
CheckWriteError
subroutine checkreaderror(err)
CheckReadError
subroutine readseveralvaluessametypefromline(nvals, rest, err, vec_integer, vec_real, vec_char, vec_logical)
ReadSeveralValuesSameTypeFromLine
subroutine rwlogical(outlogical)
subroutine rwinteger(outint)
RWInteger