forked from metno/NORTRIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNORTRIP_initialise_time.f90
134 lines (109 loc) · 4.81 KB
/
NORTRIP_initialise_time.f90
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
!NORTRIP_initialise_time
!-----------------------------------------------------------------------
subroutine NORTRIP_initialise_time
use NORTRIP_definitions
!use datetime_module!,ONLY:datetime,date2num
implicit none
integer a(6),b(6)
double precision date_to_number
character(24) a_str,format_str,b_str
!Open log file
!if (unit_logfile.gt.0) then
! open(unit_logfile,file=filename_log,status='old',position='append')
!endif
if (ro_tot.eq.1) then
write(unit_logfile,'(A)') ''
write(unit_logfile,'(A)') 'Setting time parameters (NORTRIP_initialise_time)'
write(unit_logfile,'(A)') '================================================================'
!Set time loop index
min_time=1
max_time=n_time
max_time_inputdata=n_time
a=0
b=0
!Set the date_num_data parameter and date strings
!NOTE: THis, to be of any use, should be seconds, not days and should be fixed elsewhere.
do ti=1,n_time
a(1:5)=date_data(1:5,ti)
date_data(datenum_index,ti)=date_to_number(a,2000)
call date_to_datestr(a,trim('yyyy.mm.dd HH'),date_str(1,ti))
call date_to_datestr(a,trim('HH:MM dd mm '),date_str(2,ti))
call date_to_datestr(a,date_format_str,date_str(3,ti))
call date_to_datestr(a,trim('yyyy-mm-dd HH:MM:SS'),date_str(4,ti))
enddo
a(1:5)=date_data(1:5,1)
call date_to_datestr(a,date_format_str,min_date_str)
write(unit_logfile,'(2A24,i6)') 'Min date: ',trim(min_date_str),1
a(1:5)=date_data(1:5,n_time)
call date_to_datestr(a,date_format_str,max_date_str)
write(unit_logfile,'(2A24,i6)') 'Max date: ',trim(max_date_str),n_time
!Set time step for iteration based on the first time step of the input data
!dt=(date_data(datenum_index,min_time+1)-date_data(datenum_index,min_time))*24
!Use the following versioon to preserve the double precision
a(1:5)=date_data(1:5,1)
b(1:5)=date_data(1:5,2)
dt=(date_to_number(b,2000)-date_to_number(a,2000))*24.
!Set start and end dates based on date string (if specified in 'set_road_dust_inputdata_files_v1')
call find_time_index(start_date_str,min_time)
call find_time_index(start_date_save_str,min_time_save)
call find_time_index(end_date_str,max_time)
call find_time_index(end_date_save_str,max_time_save)
if (start_date_str.eq.'') then
start_date_str=min_date_str
min_time=1
endif
if (end_date_str.eq.'') then
end_date_str=max_date_str
max_time=n_time
endif
if (start_date_save_str.eq.'') then
start_date_save_str=start_date_str
min_time_save=min_time
endif
if (end_date_save_str.eq.'') then
end_date_save_str=end_date_str
max_time_save=max_time
endif
!Limit the saving to be within the time boundaries
min_time_save=max(min_time_save,min_time)
max_time_save=min(max_time_save,max_time)
a(1:5)=date_data(1:5,min_time_save)
call date_to_datestr(a,date_format_str,start_date_save_str)
a(1:5)=date_data(1:5,max_time_save)
call date_to_datestr(a,date_format_str,end_date_save_str)
write(unit_logfile,'(2A24,i6)') 'Start date: ',trim(start_date_str),min_time
write(unit_logfile,'(2A24,i6)') 'End date: ',trim(end_date_str),max_time
write(unit_logfile,'(2A24,i6)') 'Start save date: ',trim(start_date_save_str),min_time_save
write(unit_logfile,'(2A24,i6)') 'End save date: ',trim(end_date_save_str),max_time_save
write(unit_logfile,'(A24,f6.2)') 'Time step (hours): ',dt
write(unit_logfile,'(A)') '----------------------------------------------------------------'
!if (unit_logfile.gt.0) then
! close(unit_logfile,status='keep')
!endif
endif
end subroutine NORTRIP_initialise_time
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------
subroutine find_time_index(date_str_in,ti_index)
use NORTRIP_definitions
implicit none
character(24) date_str_in
integer ti_index
logical found
integer a(6)
if (date_str_in.ne.'') then
found=.false.
do ti=1,n_time
call datestr_to_date(date_str_in,date_format_str,a)
if ((a(1).eq.date_data(year_index,ti)).and.(a(2).eq.date_data(month_index,ti)).and.(a(3).eq.date_data(day_index,ti)).and.(a(4).eq.date_data(hour_index,ti)).and.(a(5).eq.date_data(minute_index,ti))) then
ti_index=ti
found=.true.
endif
enddo
if (.not.found) then
write(unit_logfile,*) 'WARNING: No match found for date: ',trim(date_str_in)
return
endif
endif
end subroutine find_time_index
!-----------------------------------------------------------------------