merge standard release WRF/WPS V3.0.1.1 into wrffire
[wrffire.git] / WPS / ungrib / src / read_namelist.F
blob8938a5fc1a4fec8187f31b4bf2f84e596d7f2209
1 subroutine read_namelist(hstart, hend, delta_time, ntimes,&
2      ordered_by_date, debug_level, out_format, prefix)
4   use misc_definitions_module
5   use module_debug
7   implicit none
8   integer , parameter :: maxim_doms = 21
9   character(len=200) :: extdataroot, file_name_namelist
10   character(len=19) :: hstart, hend
11   integer :: delta_time
12   integer :: ntimes
13   logical :: ordered_by_date
14   integer :: debug_level
16   integer :: ierr
17   integer :: idts
19 ! Declare the namelist variables:
21   integer , dimension(maxim_doms) :: start_year
22   integer , dimension(maxim_doms) :: start_month
23   integer , dimension(maxim_doms) :: start_day
24   integer , dimension(maxim_doms) :: start_hour
25   integer , dimension(maxim_doms) :: start_minute
26   integer , dimension(maxim_doms) :: start_second
28   integer , dimension(maxim_doms) :: end_year
29   integer , dimension(maxim_doms) :: end_month
30   integer , dimension(maxim_doms) :: end_day
31   integer , dimension(maxim_doms) :: end_hour
32   integer , dimension(maxim_doms) :: end_minute
33   integer , dimension(maxim_doms) :: end_second
35   integer , dimension(maxim_doms) :: sr_x
36   integer , dimension(maxim_doms) :: sr_y
38   character (len=128) , dimension(maxim_doms) :: start_date, end_date
39   character (len=MAX_FILENAME_LEN) :: opt_output_from_geogrid_path
40   integer :: interval_seconds = 0
41   character (len=3) :: wrf_core = 'ARW'
42   integer :: max_dom, io_form_geogrid
44   character(len=3) :: out_format
45   character(len=MAX_FILENAME_LEN) :: prefix
47   namelist /share/ wrf_core, max_dom, &
48        start_year, start_month, start_day, start_hour, &
49        start_minute, start_second, &
50        end_year, end_month, end_day, end_hour, &
51        end_minute, end_second,&
52        interval_seconds, &
53        start_date, end_date, &
54        io_form_geogrid, opt_output_from_geogrid_path, debug_level, &
55        sr_x, sr_y
57   namelist /ungrib/ out_format, &
58        ordered_by_date, prefix
60   start_year = 0
61   start_month = 0
62   start_day = 0
63   start_hour = 0
64   start_minute = 0
65   start_second = 0
67   end_year = 0
68   end_month = 0
69   end_day = 0
70   end_hour = 0
71   end_minute = 0
72   end_second = 0
74   ! Set defaults. 
75   io_form_geogrid = 2
76   max_dom = 1
77   wrf_core = 'ARW'
78   debug_level = 0
80 ! Start routine:
82 ! Build the namelist file name:
84 #ifndef __crayx1
85   CALL GETENV('EXT_DATAROOT',extdataroot)
86 #endif
87   file_name_namelist =  'namelist.wps'
89 ! Open the namelist file:
90   open(10, file=file_name_namelist, status='old', iostat=ierr)
91   call mprintf((ierr.ne.0),ERROR,"**** Error opening namelist file namelist.wps")
93    REWIND (10) 
95   ! set default:
96   ordered_by_date = .TRUE.
97   start_date(1)(1:4) = '0000'
98   end_date(1)(1:4)   = '0000'
100   read(10,NML=share)
102   if (debug_level.gt.100) then
103      call set_debug_level(DEBUG)
104   else
105      call set_debug_level(WARN)
106   end if
109 ! Build the Starting date HSTART and the ending date HEND from the namelist
110 ! date/time information. start_date takes priority over the multi-variable method.
112   if ( start_date(1)(1:4) .eq. '0000' ) then
113     call build_hdate(hstart, start_year(1), start_month(1), start_day(1), start_hour(1), &
114        start_minute(1), start_second(1))
115   else
116     hstart = start_date(1)(1:19)
117   endif
118   if ( end_date(1)(1:4) .eq. '0000' ) then
119     call build_hdate(hend, end_year(1), end_month(1), end_day(1), end_hour(1), &
120        end_minute(1), end_second(1))
121   else
122     hend = end_date(1)(1:19)
123   endif
125 ! Compute the time difference between start date and end date:
127   call geth_idts(hend, hstart, idts)
129 ! Check that INTERVAL is greater than zero:
131   if (interval_seconds <= 0) then
132      call mprintf(.true.,STDOUT,"ERROR STOP IN READ_NAMELIST")
133      call mprintf(.true.,STDOUT,"INTERVAL must be greater than zero:")
134      call mprintf(.true.,STDOUT,"Start time: %s",s1=hstart)
135      call mprintf(.true.,STDOUT,"End time:   %s",s1=hend)
136      call mprintf(.true.,STDOUT,"INTERVAL:   %i",i1=interval_seconds)
137      call mprintf(.true.,LOGFILE,"ERROR STOP IN READ_NAMELIST")
138      call mprintf(.true.,LOGFILE,"INTERVAL must be greater than zero:")
139      call mprintf(.true.,LOGFILE,"Start time: %s",s1=hstart)
140      call mprintf(.true.,LOGFILE,"End time:   %s",s1=hend)
141      call mprintf(.true.,LOGFILE,"INTERVAL:   %i",i1=interval_seconds)
142      call mprintf(.true.,ERROR,"Change your namelist, and resubmit")
143   endif
145 ! Check that the selected INTERVAL evenly fills difference between 
146 ! start time and end time:
148   if ((idts/interval_seconds)*interval_seconds /= idts) then
149      call mprintf(.true.,STDOUT,"ERROR STOP IN READ_NAMELIST")
150      call mprintf(.true.,STDOUT,"INTERVAL must fit evenly between start time and end time:")
151      call mprintf(.true.,STDOUT,"Start time: %s",s1=hstart)
152      call mprintf(.true.,STDOUT,"End time:   %s",s1=hend)
153      call mprintf(.true.,STDOUT,"INTERVAL  : %i seconds,  %f hours",&
154           i1=interval_seconds,f1=float(interval_seconds)/3600.)
155      call mprintf(.true.,LOGFILE,"ERROR STOP IN READ_NAMELIST")
156      call mprintf(.true.,LOGFILE,"INTERVAL must fit evenly between start time and end time:")
157      call mprintf(.true.,LOGFILE,"Start time: %s",s1=hstart)
158      call mprintf(.true.,LOGFILE,"End time:   %s",s1=hend)
159      call mprintf(.true.,LOGFILE,"INTERVAL  : %i seconds,  %f hours",&
160           i1=interval_seconds,f1=float(interval_seconds)/3600.)
161      call mprintf(.true.,ERROR,"Change your namelist, and resubmit")
162   endif
164 ! Check that start time is not later than end time:
166   if (hstart > hend) then
167      call mprintf(.true.,STDOUT,"ERROR STOP IN READ_NAMELIST")
168      call mprintf(.true.,STDOUT,"Start time must not be later than end time:")
169      call mprintf(.true.,STDOUT,"Start time: %s",s1=hstart)
170      call mprintf(.true.,STDOUT,"End time:   %s",s1=hend)
171      call mprintf(.true.,STDOUT,"INTERVAL:   %i",i1=interval_seconds)
172      call mprintf(.true.,LOGFILE,"ERROR STOP IN READ_NAMELIST")
173      call mprintf(.true.,LOGFILE,"Start time must not be later than end time:")
174      call mprintf(.true.,LOGFILE,"Start time: %s",s1=hstart)
175      call mprintf(.true.,LOGFILE,"End time:   %s",s1=hend)
176      call mprintf(.true.,LOGFILE,"INTERVAL:   %i",i1=interval_seconds)
177      call mprintf(.true.,ERROR,"Change your namelist, and resubmit")
178   endif
180 ! Compute the number of time periods to process:
182   ntimes = idts/interval_seconds + 1
184   call mprintf(.true.,STDOUT, &
185   "Start_date =  %s ,      End_date = %s ",s1=hstart,s2=hend)
186   call mprintf(.true.,LOGFILE, &
187   "Start_date =  %s ,      End_date = %s ",s1=hstart,s2=hend)
189   if (debug_level.gt.0) then
190      call mprintf(.true.,LOGFILE,"Namelist information (coarse domain): ")
191      call mprintf(.true.,LOGFILE,'  START_YEAR       = %i',i1=start_year(1))
192      call mprintf(.true.,LOGFILE,'  START_MONTH      = %i',i1=start_month(1))
193      call mprintf(.true.,LOGFILE,'  START_DAY        = %i',i1=start_day(1))
194      call mprintf(.true.,LOGFILE,'  START_HOUR       = %i',i1=start_hour(1))
195 !    call mprintf(.true.,LOGFILE,"start_minute = %i",i1=start_minute(1))
196 !    call mprintf(.true.,LOGFILE,"start_second = %i",i1=start_second(1))
197      call mprintf(.true.,LOGFILE,'  END_YEAR         = %i',i1=end_year(1))
198      call mprintf(.true.,LOGFILE,'  END_MONTH        = %i',i1=end_month(1))
199      call mprintf(.true.,LOGFILE,'  END_DAY          = %i',i1=end_day(1))
200      call mprintf(.true.,LOGFILE,'  END_HOUR         = %i',i1=end_hour(1))
201 !    call mprintf(.true.,LOGFILE,"end_minute = %i",i1=end_minute(1))
202 !    call mprintf(.true.,LOGFILE,"end_second = %i",i1=end_second(1))
203      call mprintf(.true.,LOGFILE,'  START_DATE       = %s',s1=start_date(1))
204      call mprintf(.true.,LOGFILE,'  END_DATE         = %s',s1=end_date(1))
205      call mprintf(.true.,LOGFILE,'  INTERVAL_SECONDS = %i',i1=interval_seconds)
206      call mprintf(.true.,LOGFILE,'  DEBUG_LEVEL      = %i',i1=debug_level)
207      call mprintf(.true.,LOGFILE,'/')
208   else
209      debug_level=0
210   endif
212   delta_time = interval_seconds
214   rewind(10)
215   out_format = 'WPS'
216   prefix = 'FILE'
217   read(10,NML=ungrib,END=100)
219      call mprintf(.true.,LOGFILE,'&UNGRIB')
220      call mprintf(.true.,LOGFILE,"out_format = %s",s1=out_format)
221      if (ordered_by_date) then
222        call mprintf(.true.,LOGFILE,"ordered_by_date = %s",s1='TRUE')
223      else
224        call mprintf(.true.,LOGFILE,"ordered_by_date = %s",s1='FALSE')
225      endif
226      call mprintf(.true.,LOGFILE,"prefix = %s",s1=trim(prefix))
227      call mprintf(.true.,LOGFILE,'/')
229 100  continue
230    if (out_format(1:2) .eq. 'WP' .or. out_format(1:2) .eq. 'wp') then
231      out_format = 'WPS'
232      call mprintf(.true.,STDOUT,'output format is WPS')
233      call mprintf(.true.,LOGFILE,'output format is WPS')
234    else if (out_format(1:2) .eq. 'SI' .or. out_format(1:2) .eq. 'si') then
235      out_format = 'SI '
236      call mprintf(.true.,STDOUT,'output format is SI')
237      call mprintf(.true.,LOGFILE,'output format is SI')
238    else if (out_format(1:2) .eq. 'MM' .or. out_format(1:2) .eq. 'mm') then
239      out_format = 'MM5'
240      call mprintf(.true.,STDOUT,'output format is MM5 pregrid')
241      call mprintf(.true.,LOGFILE,'output format is MM5 pregrid')
242    else 
243      call mprintf(.true.,ERROR, &
244  'read_namelist: I do not recognize the output format, %s , stopping.',s1=out_format)
245    endif
247 ! Close the namelist file:
249   close(10)
250   
251 end subroutine read_namelist