1 subroutine da_update_firstguess(grid, out_filename)
3 !---------------------------------------------------------------------------
4 ! Purpose: Only replace the fields touched by WRFDA, rather than re-generate
5 ! whole wrfvar_output from the scratch.
7 ! Update : jliu@ucar.edu Apr 1, 2013
8 ! Minor change for Purpose
9 ! Added copy file mods instead of copying file outside
10 ! Requires Fortran 2003 standard compiler
11 ! Creator : Junmei Ban, Mar 14, 2013
13 ! The following WRF fields are modified:
23 ! grid%t2, grid%q2, grid%u10, grid%v10, grid%th2
25 ! Note about dry and mosit theta perturbation:
26 !-----------------------------------------------
27 ! In the WRF model, grid%t_2 is either moist or dry theta perturbation,
28 ! depending on the use_theta_m switch. The grid%th_phy_m_t0 is always
29 ! the dry theta perturbation. The T/THM name is a character string of
30 ! the input/output field for the grid%t_2 variable.
32 ! Inside of the DA Registry, grid%t_2 is always the dry theta perturbation.
33 ! We should be careful about referring to the internal field (such as grid%t_2)
34 ! and the string that is used to name the field in the input/output file.
35 !---------------------------------------------------------------------------
37 use module_domain, only : get_ijk_from_grid, program_name
38 use da_control, only : use_radarobs, use_rad, crtm_cloud, &
39 use_radar_rhv, use_radar_rqv
40 use module_state_description, only : p_qv, p_qc, p_qr, p_qi, &
42 f_qc, f_qr, f_qi, f_qs, f_qg
43 use module_model_constants, only: R_d, R_v, T0
45 use module_domain_type, only : fieldlist
46 use da_control, only : use_chemic_surfobs, stdout
47 use module_state_description, only : PARAM_FIRST_SCALAR, num_chem
53 integer(c_int32_t) function copyfile(ifile, ofile) bind(c)
54 import :: c_int32_t, C_CHAR
55 CHARACTER(KIND=C_CHAR), DIMENSION(*), intent(in) :: ifile, ofile
61 type(domain), intent(in) :: grid
62 character(*), intent(in), optional :: out_filename
64 ! Declare local parameters
65 character(len=120) :: file_name
66 character(len=19) :: DateStr1
67 character(len=4) :: staggering=' N/A'
68 character(len=3) :: ordering
69 character(len=80), dimension(3) :: dimnames
70 character(len=80) :: rmse_var
75 integer :: it, ierr, Status, Status_next_time
77 integer :: nlon_regional,nlat_regional,nsig_regional
78 integer :: ids, ide, jds, jde, kds, kde, &
79 ims, ime, jms, jme, kms, kme, &
80 ips, ipe, jps, jpe, kps, kpe
81 integer, dimension(4) :: start_index, end_index1
82 real, dimension(:), allocatable :: globbuf
83 real*4,allocatable :: field3(:,:,:),field2(:,:)
84 real*4,allocatable :: field3u(:,:,:),field3v(:,:,:),field3ph(:,:,:)
85 character(len=4) :: fgname
86 integer :: julyr, julday
93 character(len=200) :: varname
94 type( fieldlist ), pointer :: p
100 call get_ijk_from_grid ( grid , &
101 ids, ide, jds, jde, kds, kde, &
102 ims, ime, jms, jme, kms, kme, &
103 ips, ipe, jps, jpe, kps, kpe )
106 ! update wrfvar_output file with analysis variables from 3dvar
108 if (present(out_filename)) then
109 file_name = trim(out_filename)
110 if (file_name == 'ana02') then
116 file_name = 'wrfvar_output'
121 ierr = copyfile(trim(fgname)//C_NULL_CHAR, trim(file_name)//C_NULL_CHAR)
122 if ( ierr /= 0 ) then
123 write(unit=message(1),fmt='(a)') "Failed to create "//trim(file_name)//" from "//trim(fgname)
124 call da_error(__FILE__,__LINE__,message(1:1))
127 call ext_ncd_open_for_update( trim(file_name), 0, 0, "", dh1, Status)
128 if ( Status /= 0 )then
129 write(unit=message(1),fmt='(a)') "Failed to open "//trim(file_name)
130 call da_error(__FILE__,__LINE__,message(1:1))
133 !------------- get date info
135 call ext_ncd_get_next_time(dh1, DateStr1, Status_next_time)
136 if ( var4d .or. num_fgat_time == 1 ) then ! Don't do it for FGAT
137 if ( DateStr1 /= start_date )then
138 ! impossible scenario
139 ! start_date is set to be equal to file date in da_med_initialdata_input.inc
140 write(unit=message(1),fmt='(a)') 'date info mismatch '//trim(DateStr1)//" != "//trim(start_date)
141 call da_error(__FILE__,__LINE__,message(1:1))
145 ! update analysis time info in global attributes
146 ! needs to be done before the ext_ncd_write_field calls
147 if ( var4d .or. num_fgat_time == 1 ) then ! For 4dvar or 3dvar
148 call get_julgmt(start_date, julyr, julday, gmt)
149 CALL ext_ncd_put_dom_ti_char (dh1, 'TITLE', ' OUTPUT FROM '//trim(program_name), ierr)
150 CALL ext_ncd_put_dom_ti_char (dh1, 'START_DATE', trim(start_date), ierr)
151 CALL ext_ncd_put_dom_ti_char (dh1, 'SIMULATION_START_DATE', trim(start_date), ierr)
153 call get_julgmt(DateStr1//' ', julyr, julday, gmt)
154 CALL ext_ncd_put_dom_ti_char (dh1, 'TITLE', ' OUTPUT FROM '//trim(program_name), ierr)
155 CALL ext_ncd_put_dom_ti_char (dh1, 'START_DATE', trim(DateStr1), ierr)
156 CALL ext_ncd_put_dom_ti_char (dh1, 'SIMULATION_START_DATE', trim(DateStr1), ierr)
159 CALL ext_ncd_put_dom_ti_real (dh1, 'GMT', gmt4, 1, ierr)
160 CALL ext_ncd_put_dom_ti_integer (dh1, 'JULYR', julyr, 1, ierr)
161 CALL ext_ncd_put_dom_ti_integer (dh1, 'JULDAY', julday, 1, ierr)
163 !------------- get grid info
165 call ext_ncd_get_var_info (dh1,rmse_var,ndim1,ordering,staggering, &
166 start_index,end_index1, WrfType, ierr )
167 nlon_regional=end_index1(1)
168 nlat_regional=end_index1(2)
169 nsig_regional=end_index1(3)
171 !write(6,*)' nlon,nlat,nsig_regional=',nlon_regional,nlat_regional,nsig_regional
172 allocate(field2(nlon_regional,nlat_regional),field3(nlon_regional,nlat_regional,nsig_regional))
173 allocate(field3u(nlon_regional+1,nlat_regional,nsig_regional))
174 allocate(field3v(nlon_regional,nlat_regional+1,nsig_regional))
175 allocate(field3ph(nlon_regional,nlat_regional,nsig_regional+1))
177 end if ! end of rootproc
184 ALLOCATE(globbuf((ide-1-ids+3)*3*(jde-1-jds+3)))
189 call wrf_patch_to_global_double(grid%mu_2,globbuf,1,' ','xy', &
190 ids, ide-1, jds, jde-1, 1, 1, &
191 ims, ime, jms, jme, 1, 1, &
192 ips, min(ipe,ide-1), jps, min(jpe,jde-1),1, 1)
195 do j= 1,nlat_regional
196 do i= 1,nlon_regional
198 field2(i,j)=globbuf(i+(j-1)*(nlon_regional+1))
200 field2(i,j)=grid%mu_2(i,j)
205 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
206 start_index,end_index1, WrfType, ierr )
207 ! write(6,*)' rmse_var=',trim(rmse_var)
208 ! write(6,*)' ordering=',ordering
209 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
210 ! write(6,*)' ndim1=',ndim1
211 ! write(6,*)' staggering=',staggering
212 ! write(6,*)' start_index=',start_index
213 ! write(6,*)' end_index1=',end_index1
214 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
215 field2,WRF_REAL,0,0,0,ordering, &
216 staggering, dimnames , &
217 start_index,end_index1, & !dom
218 start_index,end_index1, & !mem
219 start_index,end_index1, & !pat
232 ALLOCATE(globbuf((ide-1-ids+3)*3*(jde-1-jds+3))) ! global_mu_2(ids:ide-1,jds:jde-1) )
237 call wrf_patch_to_global_double(grid%psfc,globbuf,1,' ','xy', &
238 ids, ide-1, jds, jde-1, 1, 1, &
239 ims, ime, jms, jme, 1, 1, &
240 ips, min(ipe,ide-1), jps, min(jpe,jde-1),1, 1)
243 do j= 1,nlat_regional
244 do i= 1,nlon_regional
246 field2(i,j)=globbuf(i+(j-1)*(nlon_regional+1))
248 field2(i,j)=grid%psfc(i,j)
253 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
254 start_index,end_index1, WrfType, ierr )
255 ! write(6,*)' rmse_var=',trim(rmse_var)
256 ! write(6,*)' ordering=',ordering
257 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
258 ! write(6,*)' ndim1=',ndim1
259 ! write(6,*)' staggering=',staggering
260 ! write(6,*)' start_index=',start_index
261 ! write(6,*)' end_index1=',end_index1
262 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
263 field2,WRF_REAL,0,0,0,ordering, &
264 staggering, dimnames , &
265 start_index,end_index1, & !dom
266 start_index,end_index1, & !mem
267 start_index,end_index1, & !pat
280 ALLOCATE(globbuf((ide-1-ids+3)*3*(jde-1-jds+3)))
285 call wrf_patch_to_global_double(grid%t2,globbuf,1,' ','xy', &
286 ids, ide-1, jds, jde-1, 1, 1, &
287 ims, ime, jms, jme, 1, 1, &
288 ips, min(ipe,ide-1), jps, min(jpe,jde-1),1, 1)
291 do j= 1,nlat_regional
292 do i= 1,nlon_regional
294 field2(i,j)=globbuf(i+(j-1)*(nlon_regional+1))
296 field2(i,j)=grid%t2(i,j)
301 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
302 start_index,end_index1, WrfType, ierr )
303 ! write(6,*)' rmse_var=',trim(rmse_var)
304 ! write(6,*)' ordering=',ordering
305 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
306 ! write(6,*)' ndim1=',ndim1
307 ! write(6,*)' staggering=',staggering
308 ! write(6,*)' start_index=',start_index
309 ! write(6,*)' end_index1=',end_index1
310 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
311 field2,WRF_REAL,0,0,0,ordering, &
312 staggering, dimnames , &
313 start_index,end_index1, & !dom
314 start_index,end_index1, & !mem
315 start_index,end_index1, & !pat
328 ALLOCATE(globbuf((ide-1-ids+3)*3*(jde-1-jds+3)))
333 call wrf_patch_to_global_double(grid%th2,globbuf,1,' ','xy', &
334 ids, ide-1, jds, jde-1, 1, 1, &
335 ims, ime, jms, jme, 1, 1, &
336 ips, min(ipe,ide-1), jps, min(jpe,jde-1),1, 1)
339 do j= 1,nlat_regional
340 do i= 1,nlon_regional
342 field2(i,j)=globbuf(i+(j-1)*(nlon_regional+1))
344 field2(i,j)=grid%th2(i,j)
349 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
350 start_index,end_index1, WrfType, ierr )
351 ! write(6,*)' rmse_var=',trim(rmse_var)
352 ! write(6,*)' ordering=',ordering
353 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
354 ! write(6,*)' ndim1=',ndim1
355 ! write(6,*)' staggering=',staggering
356 ! write(6,*)' start_index=',start_index
357 ! write(6,*)' end_index1=',end_index1
358 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
359 field2,WRF_REAL,0,0,0,ordering, &
360 staggering, dimnames , &
361 start_index,end_index1, & !dom
362 start_index,end_index1, & !mem
363 start_index,end_index1, & !pat
376 ALLOCATE(globbuf((ide-1-ids+3)*3*(jde-1-jds+3)))
381 call wrf_patch_to_global_double(grid%q2,globbuf,1,' ','xy', &
382 ids, ide-1, jds, jde-1, 1, 1, &
383 ims, ime, jms, jme, 1, 1, &
384 ips, min(ipe,ide-1), jps, min(jpe,jde-1),1, 1)
387 do j= 1,nlat_regional
388 do i= 1,nlon_regional
390 field2(i,j)=globbuf(i+(j-1)*(nlon_regional+1))
392 field2(i,j)=grid%q2(i,j)
397 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
398 start_index,end_index1, WrfType, ierr )
399 ! write(6,*)' rmse_var=',trim(rmse_var)
400 ! write(6,*)' ordering=',ordering
401 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
402 ! write(6,*)' ndim1=',ndim1
403 ! write(6,*)' staggering=',staggering
404 ! write(6,*)' start_index=',start_index
405 ! write(6,*)' end_index1=',end_index1
406 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
407 field2,WRF_REAL,0,0,0,ordering, &
408 staggering, dimnames , &
409 start_index,end_index1, & !dom
410 start_index,end_index1, & !mem
411 start_index,end_index1, & !pat
424 ALLOCATE(globbuf((ide-1-ids+3)*3*(jde-1-jds+3))) ! global_mu_2(ids:ide-1,jds:jde-1) )
429 call wrf_patch_to_global_double(grid%u10,globbuf,1,' ','xy', &
430 ids, ide-1, jds, jde-1, 1, 1, &
431 ims, ime, jms, jme, 1, 1, &
432 ips, min(ipe,ide-1), jps, min(jpe,jde-1),1, 1)
435 do j= 1,nlat_regional
436 do i= 1,nlon_regional
438 field2(i,j)=globbuf(i+(j-1)*(nlon_regional+1))
440 field2(i,j)=grid%u10(i,j)
445 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
446 start_index,end_index1, WrfType, ierr )
447 ! write(6,*)' rmse_var=',trim(rmse_var)
448 ! write(6,*)' ordering=',ordering
449 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
450 ! write(6,*)' ndim1=',ndim1
451 ! write(6,*)' staggering=',staggering
452 ! write(6,*)' start_index=',start_index
453 ! write(6,*)' end_index1=',end_index1
454 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
455 field2,WRF_REAL,0,0,0,ordering, &
456 staggering, dimnames , &
457 start_index,end_index1, & !dom
458 start_index,end_index1, & !mem
459 start_index,end_index1, & !pat
472 ALLOCATE(globbuf((ide-1-ids+3)*3*(jde-1-jds+3)))
477 call wrf_patch_to_global_double(grid%v10,globbuf,1,' ','xy', &
478 ids, ide-1, jds, jde-1, 1, 1, &
479 ims, ime, jms, jme, 1, 1, &
480 ips, min(ipe,ide-1), jps, min(jpe,jde-1),1, 1)
483 do j= 1,nlat_regional
484 do i= 1,nlon_regional
486 field2(i,j)=globbuf(i+(j-1)*(nlon_regional+1))
488 field2(i,j)=grid%v10(i,j)
493 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
494 start_index,end_index1, WrfType, ierr )
495 ! write(6,*)' rmse_var=',trim(rmse_var)
496 ! write(6,*)' ordering=',ordering
497 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
498 ! write(6,*)' ndim1=',ndim1
499 ! write(6,*)' staggering=',staggering
500 ! write(6,*)' start_index=',start_index
501 ! write(6,*)' end_index1=',end_index1
502 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
503 field2,WRF_REAL,0,0,0,ordering, &
504 staggering, dimnames , &
505 start_index,end_index1, & !dom
506 start_index,end_index1, & !mem
507 start_index,end_index1, & !pat
520 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
522 allocate( globbuf( 1 ) )
526 CALL wrf_patch_to_global_double ( grid%p, globbuf, 1, '', 'xyz' , &
527 ids, ide-1, jds, jde-1, kds, kde-1, &
528 ims, ime, jms, jme, kms, kme, &
529 ips, min(ipe,ide-1), jps, min(jpe,jde-1), kps, kpe-1 )
532 do k= 1,nsig_regional
533 do j= 1,nlat_regional
534 do i= 1,nlon_regional
536 field3(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
538 field3(i,j,k)=grid%p(i,j,k)
544 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
545 start_index,end_index1, WrfType, ierr )
546 ! write(6,*)' rmse_var=',trim(rmse_var)
547 ! write(6,*)' ordering=',ordering
548 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
549 ! write(6,*)' ndim1=',ndim1
550 ! write(6,*)' staggering=',staggering
551 ! write(6,*)' start_index=',start_index
552 ! write(6,*)' end_index1=',end_index1
553 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
554 field3,WRF_REAL,0,0,0,ordering, &
555 staggering, dimnames , &
556 start_index,end_index1, & !dom
557 start_index,end_index1, & !mem
558 start_index,end_index1, & !pat
560 end if ! end of rootproc
571 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
573 allocate( globbuf( 1 ) )
576 CALL wrf_patch_to_global_double ( grid%t_2, globbuf, 1, '', 'xyz' , &
577 ids, ide-1, jds, jde-1, kds, kde-1, &
578 ims, ime, jms, jme, kms, kme, &
579 ips, min(ipe,ide-1), jps, min(jpe,jde-1), kps, kpe-1 )
582 do k= 1,nsig_regional
583 do j= 1,nlat_regional
584 do i= 1,nlon_regional
586 field3(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
588 field3(i,j,k)=grid%t_2(i,j,k)
594 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
595 start_index,end_index1, WrfType, ierr )
596 ! write(6,*)' rmse_var=',trim(rmse_var)
597 ! write(6,*)' ordering=',ordering
598 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
599 ! write(6,*)' ndim1=',ndim1
600 ! write(6,*)' staggering=',staggering
601 ! write(6,*)' start_index=',start_index
602 ! write(6,*)' end_index1=',end_index1
603 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
604 field3,WRF_REAL,0,0,0,ordering, &
605 staggering, dimnames , &
606 start_index,end_index1, & !dom
607 start_index,end_index1, & !mem
608 start_index,end_index1, & !pat
618 ! collect QVAPOR from patches to a global array
622 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
624 allocate( globbuf( 1 ) )
627 CALL wrf_patch_to_global_double ( grid%moist(:,:,:,p_qv), globbuf, 1, '', 'xyz' , &
628 ids, ide-1, jds, jde-1, kds, kde-1, &
629 ims, ime, jms, jme, kms, kme, &
630 ips, min(ipe,ide-1), jps, min(jpe,jde-1), kps, kpe-1 )
635 ! Update THM (moist theta perturbation) before updating QVAPOR
637 if (grid%use_theta_m == 1) then ! convert dry theta perturbation to moist one
638 write(unit=message(1),fmt='(A, I2)') 'convert T to THM when use_theta_m = ', grid%use_theta_m
639 call da_message(message(1:1))
640 do k= 1,nsig_regional
641 do j= 1,nlat_regional
642 do i= 1,nlon_regional
644 qvf=1.+(R_v/R_d)*globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
646 qvf=1.+(R_v/R_d)*grid%moist(i,j,k,p_qv)
648 ! field3 here is dry theta perturbation generated earlier
649 field3(i,j,k)=(field3(i,j,k)+T0)*qvf - T0
653 else ! THM = T when use_theta_m = 0
654 write(unit=message(1),fmt='(A, I2)') 'THM = T when use_theta_m = ', grid%use_theta_m
655 call da_message(message(1:1))
659 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
660 start_index,end_index1, WrfType, ierr )
662 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
663 field3,WRF_REAL,0,0,0,ordering, &
664 staggering, dimnames , &
665 start_index,end_index1, & !dom
666 start_index,end_index1, & !mem
667 start_index,end_index1, & !pat
674 do k= 1,nsig_regional
675 do j= 1,nlat_regional
676 do i= 1,nlon_regional
678 field3(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
680 field3(i,j,k)=grid%moist(i,j,k,p_qv)
686 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
687 start_index,end_index1, WrfType, ierr )
688 ! write(6,*)' rmse_var=',trim(rmse_var)
689 ! write(6,*)' ordering=',ordering
690 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
691 ! write(6,*)' ndim1=',ndim1
692 ! write(6,*)' staggering=',staggering
693 ! write(6,*)' start_index=',start_index
694 ! write(6,*)' end_index1=',end_index1
695 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
696 field3,WRF_REAL,0,0,0,ordering, &
697 staggering, dimnames , &
698 start_index,end_index1, & !dom
699 start_index,end_index1, & !mem
700 start_index,end_index1, & !pat
702 end if ! end of rootproc
713 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
715 allocate( globbuf( 1 ) )
718 CALL wrf_patch_to_global_double ( grid%ph_2, globbuf, 1, 'Z', 'xyz' , &
719 ids, ide-1, jds, jde-1, kds, kde, &
720 ims, ime, jms, jme, kms, kme, &
721 ips, min(ipe,ide-1), jps, min(jpe,jde-1), kps, kpe )
724 do k= 1,nsig_regional+1
725 do j= 1,nlat_regional
726 do i= 1,nlon_regional
728 field3ph(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
730 field3ph(i,j,k)=grid%ph_2(i,j,k)
736 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
737 start_index,end_index1, WrfType, ierr )
738 ! write(6,*)' rmse_var=',trim(rmse_var)
739 ! write(6,*)' ordering=',ordering
740 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
741 ! write(6,*)' ndim1=',ndim1
742 ! write(6,*)' staggering=',staggering
743 ! write(6,*)' start_index=',start_index
744 ! write(6,*)' end_index1=',end_index1
745 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
746 field3ph,WRF_REAL,0,0,0,ordering, &
747 staggering, dimnames , &
748 start_index,end_index1, & !dom
749 start_index,end_index1, & !mem
750 start_index,end_index1, & !pat
752 end if ! end of rootproc
763 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
765 allocate( globbuf( 1 ) )
768 CALL wrf_patch_to_global_double ( grid%u_2, globbuf, 1, 'X', 'xyz' , &
769 ids, ide, jds, jde-1, kds, kde-1, &
770 ims, ime, jms, jme, kms, kme, &
771 ips, min(ipe,ide), jps, min(jpe,jde-1), kps, kpe-1 )
774 do k= 1,nsig_regional
775 do j= 1,nlat_regional
776 do i= 1,nlon_regional+1
778 field3u(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
780 field3u(i,j,k)=grid%u_2(i,j,k)
786 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
787 start_index,end_index1, WrfType, ierr )
788 ! write(6,*)' rmse_var=',trim(rmse_var)
789 ! write(6,*)' ordering=',ordering
790 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
791 ! write(6,*)' ndim1=',ndim1
792 ! write(6,*)' staggering=',staggering
793 ! write(6,*)' start_index=',start_index
794 ! write(6,*)' end_index1=',end_index1
795 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
796 field3u,WRF_REAL,0,0,0,ordering, &
797 staggering, dimnames , &
798 start_index,end_index1, & !dom
799 start_index,end_index1, & !mem
800 start_index,end_index1, & !pat
802 end if ! end of rootproc
813 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
815 allocate( globbuf( 1 ) )
818 CALL wrf_patch_to_global_double ( grid%v_2, globbuf, 1, 'Y', 'xyz' , &
819 ids, ide-1, jds, jde, kds, kde-1, &
820 ims, ime, jms, jme, kms, kme, &
821 ips, min(ipe,ide-1), jps, min(jpe,jde), kps, kpe-1 )
824 do k= 1,nsig_regional
825 do j= 1,nlat_regional+1
826 do i= 1,nlon_regional
828 field3v(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
830 field3v(i,j,k)=grid%v_2(i,j,k)
836 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
837 start_index,end_index1, WrfType, ierr )
838 ! write(6,*)' rmse_var=',trim(rmse_var)
839 ! write(6,*)' ordering=',ordering
840 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
841 ! write(6,*)' ndim1=',ndim1
842 ! write(6,*)' staggering=',staggering
843 ! write(6,*)' start_index=',start_index
844 ! write(6,*)' end_index1=',end_index1
845 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
846 field3v,WRF_REAL,0,0,0,ordering, &
847 staggering, dimnames , &
848 start_index,end_index1, & !dom
849 start_index,end_index1, & !mem
850 start_index,end_index1, & !pat
852 end if ! end of rootproc
863 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
865 allocate( globbuf( 1 ) )
868 CALL wrf_patch_to_global_double ( grid%w_2, globbuf, 1, 'Z', 'xyz' , &
869 ids, ide-1, jds, jde-1, kds, kde, &
870 ims, ime, jms, jme, kms, kme, &
871 ips, min(ipe,ide-1), jps, min(jpe,jde-1), kps, kpe )
874 do k= 1,nsig_regional+1
875 do j= 1,nlat_regional
876 do i= 1,nlon_regional
878 field3ph(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
880 field3ph(i,j,k)=grid%w_2(i,j,k)
886 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
887 start_index,end_index1, WrfType, ierr )
888 ! write(6,*)' rmse_var=',trim(rmse_var)
889 ! write(6,*)' ordering=',ordering
890 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
891 ! write(6,*)' ndim1=',ndim1
892 ! write(6,*)' staggering=',staggering
893 ! write(6,*)' start_index=',start_index
894 ! write(6,*)' end_index1=',end_index1
895 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
896 field3ph,WRF_REAL,0,0,0,ordering, &
897 staggering, dimnames , &
898 start_index,end_index1, & !dom
899 start_index,end_index1, & !mem
900 start_index,end_index1, & !pat
908 !-------------Update QCLOUD, QRAIN, QICE, QSNOW & QGROUP
909 if ( cloud_cv_options >= 1 ) then ! update qcw and qrn
916 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
918 allocate( globbuf( 1 ) )
921 CALL wrf_patch_to_global_double ( grid%moist(:,:,:,p_qc), globbuf, 1, '', 'xyz' , &
922 ids, ide-1, jds, jde-1, kds, kde-1, &
923 ims, ime, jms, jme, kms, kme, &
924 ips, min(ipe,ide-1), jps, min(jpe,jde-1), kps, kpe-1 )
927 do k= 1,nsig_regional
928 do j= 1,nlat_regional
929 do i= 1,nlon_regional
931 field3(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
933 field3(i,j,k)=grid%moist(i,j,k,p_qc)
939 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
940 start_index,end_index1, WrfType, ierr )
941 ! write(6,*)' rmse_var=',trim(rmse_var)
942 ! write(6,*)' ordering=',ordering
943 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
944 ! write(6,*)' ndim1=',ndim1
945 ! write(6,*)' staggering=',staggering
946 ! write(6,*)' start_index=',start_index
947 ! write(6,*)' end_index1=',end_index1
948 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
949 field3,WRF_REAL,0,0,0,ordering, &
950 staggering, dimnames , &
951 start_index,end_index1, & !dom
952 start_index,end_index1, & !mem
953 start_index,end_index1, & !pat
955 end if ! end of rootproc
968 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
970 allocate( globbuf( 1 ) )
973 CALL wrf_patch_to_global_double ( grid%moist(:,:,:,p_qr), globbuf, 1, '', 'xyz' , &
974 ids, ide-1, jds, jde-1, kds, kde-1, &
975 ims, ime, jms, jme, kms, kme, &
976 ips, min(ipe,ide-1), jps, min(jpe,jde-1), kps, kpe-1 )
979 do k= 1,nsig_regional
980 do j= 1,nlat_regional
981 do i= 1,nlon_regional
983 field3(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
985 field3(i,j,k)=grid%moist(i,j,k,p_qr)
991 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
992 start_index,end_index1, WrfType, ierr )
993 ! write(6,*)' rmse_var=',trim(rmse_var)
994 ! write(6,*)' ordering=',ordering
995 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
996 ! write(6,*)' ndim1=',ndim1
997 ! write(6,*)' staggering=',staggering
998 ! write(6,*)' start_index=',start_index
999 ! write(6,*)' end_index1=',end_index1
1000 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
1001 field3,WRF_REAL,0,0,0,ordering, &
1002 staggering, dimnames , &
1003 start_index,end_index1, & !dom
1004 start_index,end_index1, & !mem
1005 start_index,end_index1, & !pat
1007 end if ! end of rootproc
1014 end if ! cloud_cv_options >= 1
1016 if ( cloud_cv_options >= 2 ) then ! update qci, qsn, qgr
1023 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
1025 allocate( globbuf( 1 ) )
1028 CALL wrf_patch_to_global_double ( grid%moist(:,:,:,p_qi), globbuf, 1, '', 'xyz' , &
1029 ids, ide-1, jds, jde-1, kds, kde-1, &
1030 ims, ime, jms, jme, kms, kme, &
1031 ips, min(ipe,ide-1), jps, min(jpe,jde-1), kps, kpe-1 )
1034 do k= 1,nsig_regional
1035 do j= 1,nlat_regional
1036 do i= 1,nlon_regional
1038 field3(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
1040 field3(i,j,k)=grid%moist(i,j,k,p_qi)
1046 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
1047 start_index,end_index1, WrfType, ierr )
1048 ! write(6,*)' rmse_var=',trim(rmse_var)
1049 ! write(6,*)' ordering=',ordering
1050 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
1051 ! write(6,*)' ndim1=',ndim1
1052 ! write(6,*)' staggering=',staggering
1053 ! write(6,*)' start_index=',start_index
1054 ! write(6,*)' end_index1=',end_index1
1055 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
1056 field3,WRF_REAL,0,0,0,ordering, &
1057 staggering, dimnames , &
1058 start_index,end_index1, & !dom
1059 start_index,end_index1, & !mem
1060 start_index,end_index1, & !pat
1062 end if ! end of rootproc
1076 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
1078 allocate( globbuf( 1 ) )
1081 CALL wrf_patch_to_global_double ( grid%moist(:,:,:,p_qs), globbuf, 1, '', 'xyz' , &
1082 ids, ide-1, jds, jde-1, kds, kde-1, &
1083 ims, ime, jms, jme, kms, kme, &
1084 ips, min(ipe,ide-1), jps, min(jpe,jde-1), kps, kpe-1 )
1087 do k= 1,nsig_regional
1088 do j= 1,nlat_regional
1089 do i= 1,nlon_regional
1091 field3(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
1093 field3(i,j,k)=grid%moist(i,j,k,p_qs)
1099 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
1100 start_index,end_index1, WrfType, ierr )
1101 ! write(6,*)' rmse_var=',trim(rmse_var)
1102 ! write(6,*)' ordering=',ordering
1103 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
1104 ! write(6,*)' ndim1=',ndim1
1105 ! write(6,*)' staggering=',staggering
1106 ! write(6,*)' start_index=',start_index
1107 ! write(6,*)' end_index1=',end_index1
1108 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
1109 field3,WRF_REAL,0,0,0,ordering, &
1110 staggering, dimnames , &
1111 start_index,end_index1, & !dom
1112 start_index,end_index1, & !mem
1113 start_index,end_index1, & !pat
1115 end if ! end of rootproc
1129 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
1131 allocate( globbuf( 1 ) )
1134 CALL wrf_patch_to_global_double ( grid%moist(:,:,:,p_qg), globbuf, 1, '', 'xyz' , &
1135 ids, ide-1, jds, jde-1, kds, kde-1, &
1136 ims, ime, jms, jme, kms, kme, &
1137 ips, min(ipe,ide-1), jps, min(jpe,jde-1), kps, kpe-1 )
1140 do k= 1,nsig_regional
1141 do j= 1,nlat_regional
1142 do i= 1,nlon_regional
1144 field3(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
1146 field3(i,j,k)=grid%moist(i,j,k,p_qg)
1152 call ext_ncd_get_var_info (dh1,trim(rmse_var),ndim1,ordering,staggering, &
1153 start_index,end_index1, WrfType, ierr )
1154 ! write(6,*)' rmse_var=',trim(rmse_var)
1155 ! write(6,*)' ordering=',ordering
1156 ! write(6,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
1157 ! write(6,*)' ndim1=',ndim1
1158 ! write(6,*)' staggering=',staggering
1159 ! write(6,*)' start_index=',start_index
1160 ! write(6,*)' end_index1=',end_index1
1161 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
1162 field3,WRF_REAL,0,0,0,ordering, &
1163 staggering, dimnames , &
1164 start_index,end_index1, & !dom
1165 start_index,end_index1, & !mem
1166 start_index,end_index1, & !pat
1168 end if ! end of rootproc
1175 end if ! cloud_cv_options >= 2
1176 !-------------End of update QCLOUD, QRAIN, QICE, QSNOW & QGROUP
1179 !The code can be modified if chem IC for gocart are already present in the original wrfinput file,
1180 ! but should not need to be. -Wei Sun 02/2019
1181 if ( use_chemic_surfobs ) then
1183 p => grid%head_statevars
1185 do while (trim(varname) .ne. 'CHEM' .and. ASSOCIATED( p ))
1187 varname = trim( p%DataName )
1190 if ( trim(varname) .eq. 'CHEM' ) then
1192 ordering = p%MemoryOrder
1193 staggering = p%Stagger
1194 start_index(1) = p%sd1
1195 start_index(2) = p%sd2
1196 start_index(3) = p%sd3
1197 end_index1(1) = p%ed1
1198 end_index1(2) = p%ed2
1199 end_index1(3) = p%ed3
1201 do ic = PARAM_FIRST_SCALAR, num_chem
1204 allocate( globbuf((ide-1-ids+3)*(jde-1-jds+3)*(kde-1-kds+3)))
1206 allocate( globbuf( 1 ) )
1209 CALL wrf_patch_to_global_double ( grid%chem(:,:,:,ic), globbuf, 1, '', 'xyz' , &
1210 ids, ide-1, jds, jde-1, kds, kde-1, &
1211 ims, ime, jms, jme, kms, kme, &
1212 ips, min(ipe,ide-1), jps, min(jpe,jde-1), kps, kpe-1 )
1215 do k= 1,nsig_regional
1216 do j= 1,nlat_regional
1217 do i= 1,nlon_regional
1219 field3(i,j,k)=globbuf(i+(j-1)*(nlon_regional+1)+(k-1)*(nlon_regional+1)*(nlat_regional+1))
1221 field3(i,j,k)=grid%chem(i,j,k,ic)
1226 rmse_var = TRIM( p%dname_table(grid%id,ic) )
1227 dimnames(1) = TRIM(p%dimname1)
1228 dimnames(2) = TRIM(p%dimname2)
1229 dimnames(3) = TRIM(p%dimname3)
1230 ! write(*,*)' rmse_var=',trim(rmse_var)
1231 ! write(*,*)' nlon, nlat, nsig= ',nlon_regional,nlat_regional,nsig_regional
1232 ! write(*,*)' ordering=',ordering
1233 ! write(*,*)' WrfType,WRF_REAL=',WrfType,WRF_REAL
1234 ! write(*,*)' ndim1=',ndim1
1235 ! write(*,*)' staggering=',staggering
1236 ! write(*,*)' start_index=',start_index
1237 ! write(*,*)' end_index1=',end_index1
1238 call ext_ncd_write_field(dh1,DateStr1,TRIM(rmse_var), &
1239 field3,WRF_REAL,0,0,0,ordering, &
1240 staggering, dimnames , &
1241 start_index,end_index1, & !dom
1242 start_index,end_index1, & !mem
1243 start_index,end_index1, & !pat
1245 end if ! end of rootproc
1251 write(unit=message(1),fmt='(a)') "Failed to find CHEM in statevar list!"
1252 call da_error(__FILE__,__LINE__,message(1:1))
1259 deallocate(field2,field3,field3u,field3v,field3ph)
1260 call ext_ncd_ioclose(dh1, Status)
1261 end if ! end of rootproc
1263 end subroutine da_update_firstguess