1 module read_util_module
10 subroutine getarg(i, harg)
12 character(len=*) :: harg
13 integer :: ierr, ilen, i
15 call pxfgetarg(i, harg, ilen, ierr)
20 subroutine arguments(v2file, lmore)
22 character(len=*) :: v2file
23 character(len=120) :: harg
26 integer :: ierr, i, numarg
27 integer, external :: iargc
34 do while ( i < numarg)
36 print*, 'harg = ', trim(harg)
38 if (harg == "-v") then
41 elseif (harg == "-h") then
49 end subroutine arguments
53 character(len=120) :: cmd
56 write(*,'(/,"Usage: ", A, " [-v] v2file ")') trim(cmd)
57 write(*,'(8x, "-v : Print extra info")')
58 write(*,'(8x, "v3file : MM5v3 file name to read.")')
59 write(*,'(8x, "-h : print this help message and exit.",/)')
62 end module read_util_module
66 use module_ext_internal
68 #include "wrf_status_codes.h"
69 #include "wrf_io_flags.h"
70 character(len=255) :: flnm
71 character(len=255) :: flnm2
72 character(len=120) :: arg3
73 character(len=19) :: DateStr
74 character(len=19) :: DateStr2
75 character(len=31) :: VarName
76 character(len=31) :: VarName2
79 integer :: flag, flag2
80 integer :: iunit, iunit2
81 integer :: WrfType, WrfType2
86 integer :: ndim, ndim2
89 real*8 :: sumE, sum1, sum2, diff1, diff2, serr, perr, rmse, rms1, rms2, tmp1, tmp2
91 integer, dimension(4) :: start_index, end_index, start_index2, end_index2
92 integer , Dimension(3) :: MemS,MemE,PatS,PatE
93 character (len= 4) :: staggering, staggering2
94 character (len= 3) :: ordering, ordering2, ord
95 character (len=24) :: start_date, start_date2
96 character (len=24) :: current_date, current_date2
97 character (len=31) :: name, name2, tmpname
98 character (len=25) :: units, units2
99 character (len=46) :: description, description2
101 character (len=80), dimension(3) :: dimnames
104 integer :: ikdiffs, ifdiffs
106 real, allocatable, dimension(:,:,:,:) :: data,data2
108 integer :: ierr, ierr2, ier, ier2, Status, Status_next_time, Status_next_time2, Status_next_var, Status_next_var_2
110 logical :: newtime = .TRUE.
111 logical :: justplot, efound
113 integer, external :: iargc
114 logical, external :: iveceq
118 call ext_int_ioinit(' ', Status)
122 if ( iargc() .ge. 2 ) then
126 call ext_int_open_for_read( trim(flnm), 0, 0, "", dh1, Status)
127 if ( Status /= 0 ) then
128 print*,'error opening ',flnm, ' Status = ', Status ; stop
130 call ext_int_open_for_read( trim(flnm2), 0, 0, "", dh2, Status)
131 if ( Status /= 0 ) go to 923
135 ! bounce here if second name is not openable -- this would mean that
136 ! it is a field name instead.
138 print*,'could not open ',flnm2
142 if ( iargc() .eq. 3 ) then
145 print*,'LEVLIM = ',LEVLIM
148 print*,'Usage: command file1 file2'
152 print*,'Just plot ',Justplot
155 print*, 'flnm = ', trim(flnm)
157 call ext_int_get_next_time(dh1, DateStr, Status_next_time)
159 DO WHILE ( Status_next_time .eq. 0 )
160 write(*,*)'Next Time ',TRIM(Datestr)
161 call ext_int_get_next_var (dh1, VarName, Status_next_var)
162 DO WHILE ( Status_next_var .eq. 0 )
163 ! write(*,*)'Next Var |',TRIM(VarName),'|'
167 call ext_int_get_var_info (dh1,VarName,ndim,ordering,staggering,start_index,end_index, WrfType, ierr )
168 if(WrfType /= WRF_REAL .AND. WrfType /= WRF_DOUBLE) then
169 call ext_int_get_next_var (dh1, VarName, Status_next_var)
173 write(*,'(A9,1x,I1,3(1x,I5),1x,A,1x,A)')&
174 VarName, ndim, end_index(1), end_index(2), end_index(3), &
175 trim(ordering), trim(DateStr)
177 if ( VarName .eq. name ) then
178 write(*,*)'Writing fort.88 file for ', trim(name)
180 allocate(data(end_index(1), end_index(2), end_index(3), 1))
182 if ( ndim .eq. 3 ) then
184 else if ( ndim .eq. 2 ) then
186 else if ( ndim .eq. 1 ) then
188 else if ( ndim .eq. 0 ) then
192 call ext_int_read_field(dh1,DateStr,TRIM(name),data,WRF_REAL,0,0,0,ord, &
195 start_index,end_index, & !dom
196 start_index,end_index, & !mem
197 start_index,end_index, & !pat
201 write(*,*)'error reading data record'
202 write(*,*)' ndim = ', ndim
203 write(*,*)' end_index(1) ',end_index(1)
204 write(*,*)' end_index(2) ',end_index(2)
205 write(*,*)' end_index(3) ',end_index(3)
209 IF ( ndim .eq. 3 ) THEN
210 do k = start_index(2), end_index(2)
211 if ( levlim .eq. -1 .or. k .eq. levlim ) then
212 write(88,*)end_index(1),end_index(3),' ',trim(name),' ',k,' time ',n
213 do j = 1, end_index(3)
214 do i = 1, end_index(1)
215 write(88,*) data(i,k,j,1)
220 ELSE IF ( ndim .eq. 2 ) THEN
222 write(88,*)end_index(1),end_index(2),' ',trim(name),' ',k,' time ',n
223 do j = 1, end_index(2)
224 do i = 1, end_index(1)
225 write(88,*) data(i,j,1,1)
231 call ext_int_get_next_var (dh1, VarName, Status_next_var)
233 call ext_int_get_next_time(dh1, DateStr, Status_next_time)
236 write (6,FMT='(4A)') 'Diffing ',trim(flnm),' ',trim(flnm2)
238 call ext_int_get_next_time(dh1, DateStr, Status_next_time)
239 call ext_int_get_next_time(dh2, DateStr2, Status_next_time2)
241 IF ( DateStr .NE. DateStr2 ) THEN
242 print*,'They differ big time. Dates do not match'
243 print*,' ',flnm,' ',DateStr
244 print*,' ',flnm2,' ',DateStr2
248 DO WHILE ( Status_next_time .eq. 0 .AND. Status_next_time2 .eq. 0 )
249 !write(*,*)'Next Time ',TRIM(Datestr)
251 call ext_int_get_next_var (dh1, VarName, Status_next_var)
252 call ext_int_get_next_var (dh2, VarName, Status_next_var)
253 DO WHILE ( Status_next_var .eq. 0 )
255 !write(*,*)'Next Var |',TRIM(VarName),'|'
259 call ext_int_get_var_info (dh1,VarName,ndim,ordering,staggering,start_index,end_index, WrfType, ierr )
260 call ext_int_get_var_info (dh2,VarName,ndim2,ordering2,staggering2,start_index2,end_index2, WrfType2, ierr2 )
262 !write(*,*)'ierr , err2 ',TRIM(VarName), ierr , ierr2, ' ',ordering, ' ', ordering2
264 IF ( ierr /= 0 ) THEN
265 write(*,*)'Big difference: ',VarName,' not found in ',flnm2
268 IF ( ndim /= ndim2 ) THEN
269 write(*,*)'Big difference: Number of dimensions for ',Varname,' differs in ',flnm2,'(',ndim,') /= (',ndim2
273 IF ( WrfType /= WrfType2 ) THEN
274 write(*,*)'Big difference: The types do not match', WrfType, WrfType2
278 if( WrfType == WRF_REAL) then
281 IF ( end_index(i) /= end_index2(i) ) THEN
282 write(*,*)'Big difference: dim ',i,' lengths differ for ',Varname,' differ in ',flnm2
294 ! write(*,'(A9,1x,I1,3(1x,I3),1x,A,1x,A)')&
295 ! VarName, ndim, end_index(1), end_index(2), end_index(3), &
296 ! trim(ordering), trim(DateStr)
298 allocate(data (end_index(1), end_index(2), end_index(3), 1))
299 allocate(data2(end_index(1), end_index(2), end_index(3), 1))
301 if ( ndim .eq. 3 ) then
303 else if ( ndim .eq. 2 ) then
305 else if ( ndim .eq. 1 ) then
307 else if ( ndim .eq. 0 ) then
311 call ext_int_read_field(dh1,DateStr,TRIM(VarName),data,WRF_REAL,0,0,0,ord, &
314 start_index,end_index, & !dom
315 start_index,end_index, & !mem
316 start_index,end_index, & !pat
319 IF ( ierr /= 0 ) THEN
320 write(*,*)'Error reading ',Varname,' from ',flnm
321 write(*,*)' ndim = ', ndim
322 write(*,*)' end_index(1) ',end_index(1)
323 write(*,*)' end_index(2) ',end_index(2)
324 write(*,*)' end_index(3) ',end_index(3)
327 call ext_int_read_field(dh2,DateStr,TRIM(VarName),data2,WRF_REAL,0,0,0,ord, &
330 start_index,end_index, & !dom
331 start_index,end_index, & !mem
332 start_index,end_index, & !pat
335 IF ( ierr /= 0 ) THEN
336 write(*,*)'Error reading ',Varname,' from ',flnm2
337 write(*,*)' ndim = ', ndim
338 write(*,*)' end_index(1) ',end_index(1)
339 write(*,*)' end_index(2) ',end_index(2)
340 write(*,*)' end_index(3) ',end_index(3)
350 DO K = 1,end_index(3)-start_index(3)+1
351 IF (LEVLIM.EQ.-1.OR.K.EQ.LEVLIM.OR.NDIM.eq.2) THEN
354 do i = 1, end_index(1)-cross
355 do j = 1, end_index(2)-cross
358 ! borrowed from Thomas Oppe's comp program
359 sumE = sumE + ( a - b ) * ( a - b )
362 diff1 = max ( diff1 , abs ( a - b ) )
363 diff2 = max ( diff2 , abs ( b ) )
366 IKDIFFS = IKDIFFS + 1
367 IFDIFFS = IFDIFFS + 1
374 rmsE = sqrt ( sumE / dble( n ) )
375 rms1 = sqrt ( sum1 / dble( n ) )
376 rms2 = sqrt ( sum2 / dble( n ) )
378 IF ( sum2 .GT. 0.0d0 ) THEN
379 serr = sqrt ( sumE / sum2 )
381 IF ( sumE .GT. 0.0d0 ) serr = 1.0
384 IF ( diff2 .GT. 0.0d0 ) THEN
387 IF ( diff1 .GT. 0.0d0 ) perr = 1.0
391 IF ( rms1 - rms2 .EQ. 0.0d0 ) THEN
394 IF ( rms2 .NE. 0 ) THEN
395 tmp1 = 1.0d0/( ( abs( rms1 - rms2 ) ) / rms2 )
396 IF ( tmp1 .NE. 0 ) THEN
402 IF (IFDIFFS .NE. 0 ) THEN
403 ! create the fort.88 and fort.98 files because regression scripts will
404 ! look for these to see if there were differences.
405 write(88,*)trim(varname)
406 write(98,*)trim(varname)
407 PRINT 77,trim(varname), IFDIFFS, ndim, rms1, rms2, digits, rmsE, perr
408 76 FORMAT (5x,'Field ',2x,'Ndifs',4x,'Dims ',6x,'RMS (1)',12x,'RMS (2)',5x,'DIGITS',4x,'RMSE',5x,'pntwise max')
409 77 FORMAT ( A10,1x,I9,2x,I3,1x,e18.10,1x,e18.10,1x,i3,1x,e12.4,1x,e12.4 )
416 call ext_int_get_next_var (dh1, VarName, Status_next_var)
417 call ext_int_get_next_var (dh2, VarName, Status_next_var)
419 call ext_int_get_next_time(dh1, DateStr, Status_next_time)
420 call ext_int_get_next_time(dh2, DateStr2, Status_next_time2)
421 IF ( DateStr .NE. DateStr2 ) THEN
422 print*,'They differ big time. Dates do not match'
423 print*,'They differ big time. Dates do not match'
424 print*,' ',flnm,' ',DateStr
425 print*,' ',flnm2,' ',DateStr2
434 logical function iveceq( a, b, n )
441 if ( a(i) .ne. b(i) ) iveceq = .false.
447 ! stubs for routines called by module_wrf_error (used by this implementation of IO api)
450 END SUBROUTINE wrf_abort
452 SUBROUTINE get_current_time_string( time_str )
453 CHARACTER(LEN=*), INTENT(OUT) :: time_str
455 END SUBROUTINE get_current_time_string
457 SUBROUTINE get_current_grid_name( grid_str )
458 CHARACTER(LEN=*), INTENT(OUT) :: grid_str
460 END SUBROUTINE get_current_grid_name