wrf.F

References to this file elsewhere.
1 !WRF:DRIVER_LAYER:MAIN
2 !
3 
4 PROGRAM wrf
5 
6    USE module_wrf_top
7 
8 #if defined(DM_PARALLEL) && defined(WRFNL) 
9    USE module_timing
10 #endif
11 
12 !<DESCRIPTION>
13 ! Main program of WRF model.  Responsible for starting up the model, reading in (and
14 ! broadcasting for distributed memory) configuration data, defining and initializing
15 ! the top-level domain, either from initial or restart data, setting up time-keeping, and
16 ! then calling the <a href=integrate.html>integrate</a> routine to advance the domain
17 ! to the ending time of the simulation. After the integration is completed, the model
18 ! is properly shut down.
19 !
20 !</DESCRIPTION>
21 
22    IMPLICIT NONE
23 
24 #if defined(DM_PARALLEL) && defined(WRFNL) 
25 
26    LOGICAL, EXTERNAL :: await_next
27    INTEGER           :: comm
28 
29 ! disable quilting for WRFVAR which splits the communicator its own way
30    CALL disable_quilting
31 
32    CALL init_modules(1)   ! Phase 1 returns after MPI_INIT() (if it is called)
33 
34 ! Initialize utilities (time manager, etc.)
35    CALL WRFU_Initialize( defaultCalendar=WRFU_CAL_GREGORIAN )
36 
37    CALL init_modules(2)   !
38 
39    DO WHILE ( await_next() )
40 
41    CALL system("echo -n model_start ; date")
42 
43 #endif
44 
45    ! Initialize WRF model.  
46    CALL wrf_init
47 
48    ! WRF model time-stepping.  Calls integrate().  
49    CALL wrf_run
50 
51 
52    ! WRF model clean-up.  This calls MPI_FINALIZE() for DM parallel runs.  
53 #if defined(DM_PARALLEL) && defined(WRFNL) 
54    CALL wrf_finalize(.true.)
55 
56    IF ( wrf_dm_on_monitor() ) THEN
57      CALL system("touch wrfnl_done")
58    ENDIF
59    CALL system("echo -n model_end ; date")
60    ENDDO
61 
62    CALL wrf_get_dm_communicator( comm )
63    CALL MPI_BARRIER(comm,ierr)
64 
65    ! Finalize time manager
66    CALL WRFU_Finalize
67    CALL wrf_shutdown
68 
69 #else
70    CALL wrf_finalize
71 #endif
72 
73 END PROGRAM wrf
74 
75 #if defined(DM_PARALLEL) && defined(WRFNL) 
76 
77 LOGICAL FUNCTION await_next()
78    LOGICAL, EXTERNAL :: wrf_dm_on_monitor
79    INTEGER result, myproc
80 
81 301 CONTINUE
82     result = 0
83 
84     IF ( wrf_dm_on_monitor() ) THEN
85       OPEN( 99, file="wrfnl_go_ahead",status="old",form="formatted",ERR=303 )
86       CLOSE(99)
87       CALL system("rm wrfnl_go_ahead")
88       result = 1
89 303   CONTINUE
90       OPEN( 99, file="wrfnl_stop_now",status="old",form="formatted",ERR=304 )
91       CLOSE(99)
92       CALL system("rm wrfnl_stop_now")
93       result = -1
94 304   CONTINUE
95     ENDIF
96     CALL wrf_dm_bcast_integer( result, 1 )
97     IF ( result .EQ. 0 ) THEN
98       CALL system("sleep 1")
99       GOTO 301
100     ELSE IF ( result .GT. 0 ) THEN
101       await_next = .TRUE.
102       call system("touch wrfnl_stop_now")
103     ELSE
104       await_next = .FALSE.
105     ENDIF
106 
107 END FUNCTION await_next
108 #endif
109 
110 
111