da_med_initialdata_input.inc
References to this file elsewhere.
1 subroutine da_med_initialdata_input (grid, config_flags, filename, in_date)
2
3 !-----------------------------------------------------------------------
4 ! Purpose: TBD
5 !-----------------------------------------------------------------------
6
7 implicit none
8
9 type(domain), intent(inout) :: grid
10 type (grid_config_rec_type), intent(inout) :: config_flags
11
12 character(*), intent (in) :: filename
13 character(*), intent (in), optional :: in_date
14
15 integer :: fid , status, n, nsave
16
17 integer :: julyr, julday
18 real :: gmt
19
20 if (trace_use) call da_trace_entry("da_med_initialdata_input")
21 if (trace_use) call da_trace("da_med_initialdata_input", &
22 Message="Reading "//trim(filename))
23
24 ! Initialize the mother domain.
25
26 grid%input_from_file = .true.
27
28 call ext_ncd_open_for_read(trim(filename), 0, 0, "", fid, ierr)
29
30 if (ierr /= 0) then
31 write(unit=message(1), fmt='(2a)') &
32 'Netcdf error opening file:', trim(filename)
33 call da_error(__FILE__,__LINE__,message(1:1))
34 end if
35
36 call ext_ncd_get_next_time(fid, current_date, Status)
37
38 if (present(in_date)) then
39 ! Set start_date to current_date.
40 read(in_date(1:19), fmt='(i4, 5(1x, i2))') &
41 grid%start_year, &
42 grid%start_month, &
43 grid%start_day, &
44 grid%start_hour, &
45 grid%start_minute, &
46 grid%start_second
47
48 nsave = -1
49 do n=1, 1000
50 if (current_date(1:19) == in_date(1:19)) then
51 nsave = n - 1
52 exit
53 end if
54 call ext_ncd_get_next_time(fid, current_date, Status)
55 end do
56
57 if (nsave < 0) then
58 call da_error(__FILE__,__LINE__,(/"Cannot find the needed time"/))
59 end if
60 else
61 ! Set start_date to current_date.
62 read(current_date(1:19), fmt='(i4, 5(1x, i2))') &
63 grid%start_year, &
64 grid%start_month, &
65 grid%start_day, &
66 grid%start_hour, &
67 grid%start_minute,&
68 grid%start_second
69 end if
70
71 call geth_julgmt(julyr, julday, gmt)
72 call nl_set_gmt (grid%id, gmt)
73 call nl_set_julyr (grid%id, julyr)
74 call nl_set_julday (grid%id, julday)
75
76 call nl_set_iswater (grid%id, grid%iswater)
77 call nl_set_cen_lat (grid%id , grid%cen_lat)
78 call nl_set_cen_lon (grid%id , grid%cen_lon)
79 call nl_set_truelat1 (grid%id , grid%truelat1)
80 call nl_set_truelat2 (grid%id , grid%truelat2)
81 call nl_set_moad_cen_lat (grid%id , grid%moad_cen_lat)
82 call nl_set_stand_lon (grid%id , grid%stand_lon)
83 call nl_set_map_proj (grid%id , grid%map_proj)
84
85 start_date=current_date
86
87 call geth_julgmt(julyr, julday, gmt)
88 config_flags%gmt = gmt
89 config_flags%julyr = julyr
90 config_flags%julday = julday
91
92 call ext_ncd_ioclose(fid, ierr)
93
94 call da_trace("da_med_initialdata_input", &
95 message="open_r_dataset for "//trim(filename))
96 call open_r_dataset (fid, trim(filename), grid , config_flags , &
97 "DATASET=INPUT", ierr)
98
99 if (ierr .NE. 0) then
100 write(unit=message(1),fmt='(A,A,A,I5)') 'Error opening ', &
101 trim(filename),' for reading ierr=',ierr
102 call da_error(__FILE__,__LINE__,message(1:1))
103 end if
104
105 if (present(in_date)) then
106 do n=1, nsave
107 call da_message((/"current_date="//trim(current_date)// &
108 ', in_date='//trim(in_date)/))
109 call ext_ncd_get_next_time(fid, current_date, Status)
110 end do
111 end if
112
113 call input_model_input (fid , grid , config_flags , ierr)
114
115 call close_dataset (fid , config_flags , "DATASET=INPUT")
116
117 if (trace_use) call da_trace_exit("da_med_initialdata_input")
118
119 end subroutine da_med_initialdata_input
120
121