MPTRAC
trac_fortran.f90
Go to the documentation of this file.
1! This file is part of MPTRAC.
2!
3! MPTRAC is free software: you can redistribute it and/or modify it
4! under the terms of the GNU General Public License as published by
5! the Free Software Foundation, either version 3 of the License, or
6! (at your option) any later version.
7!
8! MPTRAC is distributed in the hope that it will be useful,
9! but WITHOUT ANY WARRANTY; without even the implied warranty of
10! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11! GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License
14! along with MPTRAC. If not, see <http://www.gnu.org/licenses/>.
15!
16! Copyright (C) 2013-2024 Forschungszentrum Juelich GmbH
17
19
21 USE mptrac_func
22 USE iso_fortran_env
23 USE iso_c_binding
24
25 IMPLICIT NONE
26
27 CHARACTER(len=40) :: filename_ctl, filename_atm, dirname
28 INTEGER(c_int) :: argc
29 TYPE(ctl_t) :: ctl
30 TYPE(atm_t) :: atm
31 TYPE(clim_t) :: clim
32 TYPE(met_t), TARGET :: met0, met1
33 TYPE(met_t), POINTER :: met0p, met1p
34 REAL(real64) :: t
35 REAL(real64), DIMENSION(npp) :: dt
36 CHARACTER(len=32) :: arg
37 TYPE(c_ptr), ALLOCATABLE, DIMENSION(:) :: argv_ptrs
38 CHARACTER(len=32), ALLOCATABLE, DIMENSION(:), TARGET :: tmp
39 INTEGER :: i, stat
40
41 ! Read command line arguments...
42 argc = command_argument_count()
43
44 IF (argc < 4) THEN
45 WRITE(*,*) "Error: Give parameters: <dirlist> <ctl> <atm_in>"
46 CALL exit
47 ENDIF
48
49 ALLOCATE(tmp(argc), argv_ptrs(argc))
50
51 DO i = 1, argc
52 CALL get_command_argument(i, arg)
53 IF (len_trim(arg) == 0) EXIT
54 tmp(i) = trim(arg)//c_null_char
55 argv_ptrs(i) = c_loc(tmp(i))
56 ENDDO
57
58 ! Open directory list...
59 OPEN(10,file=tmp(1),iostat=stat)
60 IF (stat .ne. 0) THEN
61 WRITE(*,*) "Error: Cannot open directory list!"
62 CALL exit
63 ENDIF
64
65 DO WHILE (1 .eq. 1)
66 READ(10,'(a)', END=200) dirname
67
68 filename_ctl = trim(dirname)//"/"//tmp(2)
69 filename_atm = trim(dirname)//"/"//tmp(3)
70
71 ! Read control parameters...
72 CALL mptrac_read_ctl(trim(filename_ctl)//c_null_char, argc, argv_ptrs, ctl)
73
74 ! Read climatological data...
75 CALL mptrac_read_clim(ctl, clim)
76
77 ! Read atmospheric data...
78 CALL mptrac_read_atm(trim(filename_atm)//c_null_char, ctl, atm)
79
80 ! Initialize timesteps...
81 CALL mptrac_module_timesteps_init(ctl, atm)
82
83 ! Get meteo data...
84 met0p => met0
85 met1p => met1
86 CALL mptrac_get_met(ctl, clim, ctl%t_start, met0p, met1p)
87
88 t = ctl%t_start
89
90 DO WHILE (ctl%direction * (t - ctl%t_stop) < ctl%dt_mod)
91
92 ! Adjust length of final time step...
93 IF (ctl%direction * (t - ctl%t_stop) > 0) THEN
94 t = ctl%t_stop
95 ENDIF
96
97 ! Set time steps of air parcels...
98 CALL mptrac_module_timesteps(ctl, met0, atm, dt, t)
99
100 IF (t .NE. ctl%t_start) THEN
101 ! Get meteo data...
102 CALL mptrac_get_met(ctl, clim, t, met0p, met1p)
103 ENDIF
104
105 ! Advection...
106 CALL mptrac_module_advect(ctl, met0, met1, atm, dt)
107
108 ! Write output...
109 CALL mptrac_write_output(trim(dirname)//c_null_char, ctl, met0, met1, atm, t)
110
111 t = t + ctl%direction * ctl%dt_mod
112
113 END DO
114
115 END DO
116200 CONTINUE
117
118END PROGRAM trac_fortran
Air parcel data.
Definition: mptrac.h:3120
Climatological data.
Definition: mptrac.h:3282
Control parameters.
Definition: mptrac.h:2155
Meteo data structure.
Definition: mptrac.h:3341
program trac_fortran