da_wrfvar_finalize.f90
References to this file elsewhere.
1 subroutine da_wrfvar_finalize
2
3 !-------------------------------------------------------------------------
4 ! Purpose: Tidy up at the end
5 !-------------------------------------------------------------------------
6
7 use module_domain, only : domain, head_grid
8
9 use da_control, only : trace_use, cost_unit, stderr, &
10 check_max_iv_unit,grad_unit,ierr,num_alpha_corr_types, &
11 rootproc,stats_unit, unit_start, rtm_option, rtm_option_crtm, use_rad, &
12 unit_end, jo_unit, unit_used
13 use da_radiance1, only : num_tovs_before, tovs_recv_pe,tovs_copy_count, &
14 tovs_send_pe,tovs_send_count,tovs_recv_start, num_tovs_after, &
15 tovs_send_start
16 use da_wrfvar_io, only : da_med_initialdata_output
17 use da_tracing, only : da_trace_entry, da_trace_exit
18 use da_wrfvar_top, only : config_flags
19 use da_tools1, only : da_free_unit
20 use da_wrf_interfaces, only : wrf_error_fatal,med_shutdown_io
21 use da_reporting, only : da_message
22
23 #ifdef CRTM
24 use module_radiance, only : crtm_destroy
25 use da_crtm, only : channelinfo, sensor_descriptor
26 #endif
27
28 implicit none
29
30 integer :: i
31 type(domain), pointer :: grid
32
33 if (trace_use) call da_trace_entry ("da_wrfvar_finalize")
34
35 ! output wrfvar analysis
36
37 if ((config_flags%real_data_init_type == 1) .or. &
38 (config_flags%real_data_init_type == 3)) then
39 call da_med_initialdata_output (head_grid , config_flags)
40 call med_shutdown_io (head_grid , config_flags)
41 end if
42
43 grid => head_grid
44
45 deallocate (grid%parents)
46 deallocate (grid%nests)
47 deallocate (grid%domain_clock)
48 deallocate (grid%alarms)
49 deallocate (grid%alarms_created)
50
51 deallocate (grid%i_start)
52 deallocate (grid%i_end)
53 deallocate (grid%j_start)
54 deallocate (grid%j_end)
55
56 #include "em_deallocs.inc"
57
58 deallocate (grid)
59
60 if (allocated(num_tovs_before)) deallocate (num_tovs_before)
61 if (allocated(num_tovs_after)) deallocate (num_tovs_after)
62 if (allocated(tovs_copy_count)) deallocate (tovs_copy_count)
63 if (allocated(tovs_send_pe)) deallocate (tovs_send_pe)
64 if (allocated(tovs_recv_pe)) deallocate (tovs_recv_pe)
65 if (allocated(tovs_send_start)) deallocate (tovs_send_start)
66 if (allocated(tovs_send_count)) deallocate (tovs_send_count)
67 if (allocated(tovs_recv_start)) deallocate (tovs_recv_start)
68
69 if (rootproc) then
70 close (cost_unit)
71 close (grad_unit)
72 close (stats_unit)
73 close (jo_unit)
74 close (check_max_iv_unit)
75 call da_free_unit (cost_unit)
76 call da_free_unit (grad_unit)
77 call da_free_unit (stats_unit)
78 call da_free_unit (jo_unit)
79 call da_free_unit (check_max_iv_unit)
80 end if
81
82 #ifdef CRTM
83 if (use_rad .and. rtm_option == rtm_option_crtm) then
84 ierr = CRTM_Destroy(ChannelInfo)
85 deallocate(Sensor_Descriptor)
86 end if
87 #endif
88
89 do i=unit_start,unit_end
90 if (unit_used(i)) then
91 write(unit=stderr,FMT=*) "unit",i,"still used"
92 end if
93 end do
94
95 call da_message ((/"SUCCESS COMPLETE WRFVAR"/))
96
97 if (trace_use) call da_trace_exit ("da_wrfvar_finalize")
98
99 end subroutine da_wrfvar_finalize
100
101