-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNORTRIP_multiroad_find_init_file.f90
130 lines (110 loc) · 7.14 KB
/
NORTRIP_multiroad_find_init_file.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
!NORTRIP_multiroad_find_init_file.f90
subroutine NORTRIP_multiroad_find_init_file
use NORTRIP_multiroad_index_definitions
implicit none
logical exists
integer init_date(num_date_index)
integer init_counter
logical init_found
character(256) filename_NORTRIP_data_temp
character(256) filename_init_start
character(256) filename_init_start_netcdf
write(unit_logfile,'(A)') '================================================================'
write(unit_logfile,'(A)') 'Finding initialisation data (NORTRIP_multiroad_find_init_file)'
write(unit_logfile,'(A)') '================================================================'
pathname_init_in=path_init_for_NORTRIP
init_date=start_date_input
!Look for the init file with the time stamp from the hour before
!call incrtm(-1,init_date(1),init_date(2),init_date(3),init_date(4))
!Set the NORTRIP input initialisation filename using the given dates
call date_to_datestr_bracket(init_date,filename_NORTRIP_template,filename_NORTRIP_data_temp)
call date_to_datestr_bracket(init_date,filename_NORTRIP_data_temp,filename_NORTRIP_data_temp)
call date_to_datestr_bracket(init_date,filename_NORTRIP_data_temp,filename_NORTRIP_data_temp)
filename_init_in=trim(filename_NORTRIP_data_temp)//'_init.txt'
filename_init_start=filename_init_in
pathfilename_init_in=trim(pathname_init_in)//trim(filename_init_in)
!Update the date string 3 times incase there are more than one bracket
call date_to_datestr_bracket(init_date,pathfilename_init_in,pathfilename_init_in)
call date_to_datestr_bracket(init_date,pathfilename_init_in,pathfilename_init_in)
call date_to_datestr_bracket(init_date,pathfilename_init_in,pathfilename_init_in)
filename_init_in_netcdf=trim(filename_NORTRIP_data_temp)//'_init.nc'
filename_init_start_netcdf=filename_init_in_netcdf
pathfilename_init_in=trim(pathname_init_in)//trim(filename_init_in_netcdf)
!Update the date string 3 times incase there are more than one bracket
call date_to_datestr_bracket(init_date,pathfilename_init_in_netcdf,pathfilename_init_in_netcdf)
call date_to_datestr_bracket(init_date,pathfilename_init_in_netcdf,pathfilename_init_in_netcdf)
call date_to_datestr_bracket(init_date,pathfilename_init_in_netcdf,pathfilename_init_in_netcdf)
write(unit_logfile,'(A,A)') ' Looking for NORTRIP initialisation file: ', trim(filename_init_start)
write(unit_logfile,'(A,A)') ' Looking for NORTRIP initialisation netcdf file: ', trim(filename_init_start_netcdf)
!============================Look for init file in text format (_init.txt)==================================================
!Test existence of the filename. If does not exist then update by subtracting 1 day
init_counter=0
init_found=.false.
do while(init_counter.lt.30*24.and..not.init_found)
!Set the template NORTRIP filename using the given dates
call date_to_datestr_bracket(init_date,filename_NORTRIP_template,filename_NORTRIP_data_temp)
filename_init_in=trim(filename_NORTRIP_data_temp)//'_init.txt'
pathfilename_init_in=trim(pathname_init_in)//trim(filename_init_in)
!Update the date string 3 times incase there are more than one bracket
call date_to_datestr_bracket(init_date,pathfilename_init_in,pathfilename_init_in)
call date_to_datestr_bracket(init_date,pathfilename_init_in,pathfilename_init_in)
call date_to_datestr_bracket(init_date,pathfilename_init_in,pathfilename_init_in)
init_counter=init_counter+1
inquire(file=trim(pathfilename_init_in),exist=exists)
if (exists) then
init_found=.true.
else
!Wind back the time one hour to search for a valid init file
!write(*,'(A,A,A)') ' WARNING: No initialisation file found for ', trim(filename_init_in),'. Trying one day earlier'
!call incrtm(-hours_between_init,init_date(1),init_date(2),init_date(3),init_date(4))
call incrtm(-1,init_date(1),init_date(2),init_date(3),init_date(4))
endif
enddo
if (init_found) then
if (init_counter.eq.1) then
write(unit_logfile,'(A,A)') ' Found correct NORTRIP initialisation file: ',trim(pathfilename_init_in)
else
write(unit_logfile,'(A,A,A,I4,A)') ' Found previous NORTRIP initialisation file ',trim(pathfilename_init_in),' from ',init_counter-1,' hours before'
endif
else
write(unit_logfile,'(A,A)') ' WARNING: No .txt initialisation file found in the last 30 days ',trim(pathfilename_init_in)
filename_init_in=''
endif
!==========================================================================================================================
!!==============================Look for init file in netcdf format=========================================================
!Test existence of the filename. If does not exist then update by subtracting 1 day
init_counter=0
init_found=.false.
init_date=start_date_input
do while(init_counter.lt.30*24.and..not.init_found)
!Set the template NORTRIP filename using the given dates
call date_to_datestr_bracket(init_date,filename_NORTRIP_template,filename_NORTRIP_data_temp)
filename_init_in_netcdf=trim(filename_NORTRIP_data_temp)//'_init.nc'
pathfilename_init_in_netcdf=trim(pathname_init_in)//trim(filename_init_in_netcdf)
!Update the date string 3 times incase there are more than one bracket
call date_to_datestr_bracket(init_date,pathfilename_init_in_netcdf,pathfilename_init_in_netcdf)
call date_to_datestr_bracket(init_date,pathfilename_init_in_netcdf,pathfilename_init_in_netcdf)
call date_to_datestr_bracket(init_date,pathfilename_init_in_netcdf,pathfilename_init_in_netcdf)
init_counter=init_counter+1
inquire(file=trim(pathfilename_init_in_netcdf),exist=exists)
if (exists) then
init_found=.true.
else
!Wind back the time one hour to search for a valid init file
!write(*,'(A,A,A)') ' WARNING: No initialisation file found for ', trim(filename_init_in_netcdf),'. Trying one day earlier'
!call incrtm(-hours_between_init,init_date(1),init_date(2),init_date(3),init_date(4))
call incrtm(-1,init_date(1),init_date(2),init_date(3),init_date(4))
endif
enddo
if (init_found) then
if (init_counter.eq.1) then
write(unit_logfile,'(A,A)') ' Found correct NORTRIP initialisation netcdf file: ',trim(filename_init_in_netcdf)
else
write(unit_logfile,'(A,A,A,I4,A)') ' Found previous NORTRIP initialisation netcdf file ',trim(filename_init_in_netcdf),' from ',init_counter-1,' hours before'
endif
else
write(unit_logfile,'(A,A)') ' WARNING: No .nc initialisation file found in the last 30 days ',trim(filename_init_in_netcdf)
filename_init_in_netcdf=''
endif
!!==========================================================================================================================
end subroutine NORTRIP_multiroad_find_init_file