23 module gsl_oro_data_sm_scale
27 integer,
parameter :: real_kind = selected_real_kind(6)
28 integer,
parameter :: dbl_kind = selected_real_kind(13)
30 real,
parameter :: pi = 3.1415926535897_real_kind
34 real (kind = real_kind),
allocatable :: lat1d_fine(:)
35 real (kind = real_kind),
allocatable :: lon1d_fine(:)
37 real (kind = real_kind),
parameter :: p5 = 0.5_real_kind
49 subroutine calc_gsl_oro_data_sm_scale(tile_num,res_indx,halo, &
50 duplicate_oro_data_file)
56 character(len=2),
intent(in) :: tile_num
57 character(len=7),
intent(in) :: res_indx
58 character(len=4),
intent(in) :: halo
60 logical,
intent(out) :: duplicate_oro_data_file
65 real (kind = real_kind) :: min_area_FV3
66 real (kind = real_kind) :: min_DX
70 integer :: ncid_in,ncid_out,err
72 integer :: dimid,latid,lonid
73 integer,
dimension (2) :: dimids
75 integer :: nfinepoints
77 real (kind = real_kind) :: sum2, sum4, var
80 real (kind = real_kind),
allocatable :: &
85 real (kind = real_kind) :: zs_mean
86 real (kind = real_kind),
allocatable :: &
87 std_dev(:),convexity(:), &
88 OA1(:),OA2(:),OA3(:),OA4(:), &
89 OL1(:),OL2(:),OL3(:),OL4(:)
91 real (kind = real_kind),
parameter :: max_convexity = 10._real_kind
93 integer :: nu, nd, nw, nt
94 real (kind = real_kind) :: ratio
97 real,
parameter :: ae = 6371200._real_kind
99 character(len=35) :: FV3_grid_input_file_name
100 character(len=150) :: fine_topo_source_file_name
101 character(len=35) :: oro_data_output_file_name
103 integer :: temp_int, dimX_FV3, dimY_FV3
104 real (kind = dbl_kind),
allocatable :: lat_FV3_raw(:,:), lon_FV3_raw(:,:)
105 real (kind = real_kind),
allocatable :: lat_FV3(:,:), lon_FV3(:,:)
106 real (kind = real_kind),
allocatable :: lat_FV3_deg(:,:)
107 real (kind = real_kind),
allocatable :: lon_FV3_deg(:,:)
108 real (kind = dbl_kind),
allocatable :: area_FV3_qtr(:,:)
109 real (kind = real_kind),
allocatable :: area_FV3(:,:)
110 real (kind = real_kind),
allocatable :: HGT_M_fine(:,:)
111 real (kind = real_kind) :: dlta_lat, dlta_lon
113 integer :: i_blk, j_blk
114 integer :: ii_loc, jj_loc, ii_m, jj_m
115 integer,
dimension(3) :: s_ii, e_ii, s_jj, e_jj
116 real (kind = real_kind),
dimension(3) :: lat_blk, lon_blk
117 integer :: cell_count
123 print *,
"Creating oro_data_ss file" 127 if ( halo.eq.
"-999" )
then 128 fv3_grid_input_file_name =
"C" // trim(res_indx) //
"_grid.tile" // &
129 trim(tile_num) //
".nc" 131 fv3_grid_input_file_name =
"C" // trim(res_indx) //
"_grid.tile" // &
132 trim(tile_num) //
".halo" // trim(halo) //
".nc" 135 print *,
"Reading from file: ", fv3_grid_input_file_name
139 inquire(file=fv3_grid_input_file_name,exist=fexist)
140 if (.not.fexist)
then 142 print *,
"Fatal error: Input file "//trim(fv3_grid_input_file_name)// &
144 print *,
"Exiting program gsl_oro_data.f90" 152 if ( halo.eq.
"-999" )
then 155 read(halo,*) halo_int
160 err = nf90_open(fv3_grid_input_file_name,nf90_nowrite,ncid_in)
161 call netcdf_err(err,
'opening: '//fv3_grid_input_file_name)
163 err = nf90_inq_dimid(ncid_in,
'nx',dimid)
165 err = nf90_inquire_dimension(ncid_in,dimid,len=temp_int)
167 dimx_fv3 = temp_int/2 - 2*halo_int
169 err = nf90_inq_dimid(ncid_in,
'ny',dimid)
171 err = nf90_inquire_dimension(ncid_in,dimid,len=temp_int)
173 dimy_fv3 = temp_int/2 - 2*halo_int
175 print *,
"dimX_FV3 =", dimx_fv3
176 print *,
"dimY_FV3 =", dimy_fv3
180 allocate (lat_fv3_raw((2*dimx_fv3+1),(2*dimy_fv3+1)))
181 err = nf90_inq_varid(ncid_in,
'y',varid)
183 err = nf90_get_var(ncid_in,varid,lat_fv3_raw, &
184 start=(/1+2*halo_int,1+2*halo_int/), &
185 count=(/2*dimx_fv3+1,2*dimy_fv3+1/))
188 allocate (lon_fv3_raw((2*dimx_fv3+1),(2*dimy_fv3+1)))
189 err = nf90_inq_varid(ncid_in,
'x',varid)
191 err = nf90_get_var(ncid_in,varid,lon_fv3_raw, &
192 start=(/1+2*halo_int,1+2*halo_int/), &
193 count=(/2*dimx_fv3+1,2*dimy_fv3+1/))
197 allocate (area_fv3_qtr((2*dimx_fv3),(2*dimy_fv3)))
198 err = nf90_inq_varid(ncid_in,
'area',varid)
200 err = nf90_get_var(ncid_in,varid,area_fv3_qtr, &
201 start=(/1+2*halo_int,1+2*halo_int/), &
202 count=(/2*dimx_fv3,2*dimy_fv3/))
208 allocate (lat_fv3(dimx_fv3,dimy_fv3))
209 allocate (lon_fv3(dimx_fv3,dimy_fv3))
210 allocate (lat_fv3_deg(dimx_fv3,dimy_fv3))
211 allocate (lon_fv3_deg(dimx_fv3,dimy_fv3))
214 lat_fv3(i,j) = lat_fv3_raw(2*i,2*j)
215 lon_fv3(i,j) = lon_fv3_raw(2*i,2*j)
218 lat_fv3_deg(:,:) = lat_fv3(:,:)
219 lon_fv3_deg(:,:) = lon_fv3(:,:)
220 deallocate(lat_fv3_raw)
221 deallocate(lon_fv3_raw)
224 lat_fv3 = lat_fv3*pi/180._real_kind
225 lon_fv3 = lon_fv3*pi/180._real_kind
229 allocate(area_fv3(dimx_fv3,dimy_fv3))
232 area_fv3(i,j) = area_fv3_qtr(2*i-1,2*j-1) + area_fv3_qtr(2*i-1,2*j) + &
233 area_fv3_qtr(2*i,2*j-1) + area_fv3_qtr(2*i,2*j)
236 deallocate(area_fv3_qtr)
238 err = nf90_close(ncid_in)
243 fine_topo_source_file_name =
"HGT.Beljaars_filtered.lat-lon.30s_res.nc" 245 inquire(file=fine_topo_source_file_name,exist=fexist)
246 if (.not.fexist)
then 248 print *,
"Fatal error: Topo source file "// &
249 trim(fine_topo_source_file_name)//
" does not exist" 250 print *,
"Exiting program gsl_oro_data.f90" 254 err = nf90_open(trim(fine_topo_source_file_name),nf90_nowrite,ncid_in)
255 call netcdf_err(err,
'opening: '//trim(fine_topo_source_file_name))
258 err = nf90_inq_dimid(ncid_in,
'west_east',dimid)
260 err = nf90_inquire_dimension(ncid_in,dimid,len=dimx_fine)
261 call netcdf_err(err,
'reading west_east value')
263 err = nf90_inq_dimid(ncid_in,
'south_north',dimid)
264 call netcdf_err(err,
'reading south_north id')
265 err = nf90_inquire_dimension(ncid_in,dimid,len=dimy_fine)
266 call netcdf_err(err,
'reading south_north value')
268 print *,
"Source file for high-resolution topography: ", &
269 trim(fine_topo_source_file_name)
270 print *,
"dimX_fine =", dimx_fine
271 print *,
"dimY_fine =", dimy_fine
276 allocate(lat1d_fine(dimy_fine))
277 allocate(lon1d_fine(dimx_fine))
278 err = nf90_inq_varid(ncid_in,
'CLAT',varid)
280 err = nf90_get_var(ncid_in,varid,lat1d_fine,start=(/1,1/), &
281 count=(/1,dimy_fine/))
284 err = nf90_inq_varid(ncid_in,
'CLONG',varid)
286 err = nf90_get_var(ncid_in,varid,lon1d_fine,start=(/1,1/), &
287 count=(/dimx_fine,1/))
291 lat1d_fine = lat1d_fine*pi/180._real_kind
292 lon1d_fine = lon1d_fine*pi/180._real_kind
298 if ( lon_fv3(i,j).gt.pi )
then 299 lon_fv3(i,j) = lon_fv3(i,j) - 2*pi
306 allocate(hgt_m_fine(dimx_fine,dimy_fine))
307 err = nf90_inq_varid(ncid_in,
'HGT_M',varid)
309 err = nf90_get_var(ncid_in,varid,hgt_m_fine,start=(/1,1/), &
310 count=(/dimx_fine,dimy_fine/))
314 err = nf90_close(ncid_in)
318 allocate (std_dev(dimx_fv3*dimy_fv3))
319 allocate (convexity(dimx_fv3*dimy_fv3))
320 allocate (oa1(dimx_fv3*dimy_fv3))
321 allocate (oa2(dimx_fv3*dimy_fv3))
322 allocate (oa3(dimx_fv3*dimy_fv3))
323 allocate (oa4(dimx_fv3*dimy_fv3))
324 allocate (ol1(dimx_fv3*dimy_fv3))
325 allocate (ol2(dimx_fv3*dimy_fv3))
326 allocate (ol3(dimx_fv3*dimy_fv3))
327 allocate (ol4(dimx_fv3*dimy_fv3))
330 std_dev(:) = 0._real_kind
331 convexity(:) = 0._real_kind
332 oa1(:) = 0._real_kind
333 oa2(:) = 0._real_kind
334 oa3(:) = 0._real_kind
335 oa4(:) = 0._real_kind
336 ol1(:) = 0._real_kind
337 ol2(:) = 0._real_kind
338 ol3(:) = 0._real_kind
339 ol4(:) = 0._real_kind
344 min_area_fv3 = 1.e+14
347 min_area_fv3 = min(min_area_fv3,area_fv3(i,j))
351 min_dx = sqrt(min_area_fv3)/1000._real_kind
375 dlta_lat = sqrt(area_fv3(i,j))/ae
376 dlta_lon = sqrt(area_fv3(i,j))/(ae*cos(lat_fv3(i,j)))
382 lon_blk(i_blk) = lon_fv3(i,j) + (i_blk-2)*dlta_lon
386 lat_blk(j_blk) = lat_fv3(i,j) + (j_blk-2)*dlta_lat
394 s_ii(i_blk) = nearest_i_east(lon_blk(i_blk)-p5*dlta_lon)
395 e_ii(i_blk) = nearest_i_west(lon_blk(i_blk)+p5*dlta_lon)
398 s_jj(j_blk) = nearest_j_north(lat_blk(j_blk)-p5*dlta_lat)
399 e_jj(j_blk) = nearest_j_south(lat_blk(j_blk)+p5*dlta_lat)
410 if ( (s_jj(j_blk).eq.-999).and.(e_jj(j_blk).ne.-999) )
then 413 lat_blk(j_blk) = p5*(lat1d_fine(1)+lat1d_fine(e_jj(j_blk)))
419 if ( s_jj(j_blk).eq.-999 )
then 422 lat_blk(j_blk) = p5*(lat1d_fine(1)+lat1d_fine(e_jj(j_blk)))
424 if ( e_jj(j_blk).eq.-999 )
then 425 e_jj(j_blk) = dimy_fine
427 lat_blk(j_blk) = p5*(lat1d_fine(s_jj(j_blk))+lat1d_fine(dimy_fine))
432 if ( (e_jj(j_blk).eq.-999).and.(s_jj(j_blk).ne.-999) )
then 433 e_jj(j_blk) = dimy_fine
435 lat_blk(j_blk) = p5*(lat1d_fine(s_jj(j_blk))+lat1d_fine(dimy_fine))
443 if ( s_ii(2).gt.e_ii(2) )
then 444 ii_m = dimx_fine - s_ii(2) + 1 + e_ii(2)
446 ii_m = e_ii(2) - s_ii(2) + 1
448 jj_m = e_jj(2) - s_jj(2) + 1
453 allocate (zs(ii_m,jj_m))
455 do jj = s_jj(2), e_jj(2)
456 jj_loc = jj - s_jj(2) + 1
458 if ( s_ii(2).gt.e_ii(2) )
then 459 do ii = s_ii(2), dimx_fine
460 ii_loc = ii - s_ii(2) + 1
461 zs(ii_loc,jj_loc) = hgt_m_fine(ii,jj)
465 zs(ii_loc,jj_loc) = hgt_m_fine(ii,jj)
468 do ii = s_ii(2), e_ii(2)
469 ii_loc = ii - s_ii(2) + 1
470 zs(ii_loc,jj_loc) = hgt_m_fine(ii,jj)
487 if ( abs(zs(ii,jj)).gt.1.e-1 ) zs_accum = .true.
490 if ( .not.zs_accum )
then 491 std_dev(cell_count) = 0._real_kind
492 convexity(cell_count) = 0._real_kind
493 oa1(cell_count) = 0._real_kind
494 oa2(cell_count) = 0._real_kind
495 oa3(cell_count) = 0._real_kind
496 oa4(cell_count) = 0._real_kind
497 ol1(cell_count) = 0._real_kind
498 ol2(cell_count) = 0._real_kind
499 ol3(cell_count) = 0._real_kind
500 ol4(cell_count) = 0._real_kind
502 cell_count = cell_count + 1
513 nfinepoints = ii_m*jj_m
516 sum2 = sum2 + zs(ii,jj)
519 zs_mean = sum2 /
real(nfinepoints,real_kind)
525 sum2 = sum2 + ( zs(ii,jj) - zs_mean )**2
528 std_dev(cell_count) = sqrt( sum2/
real(nfinepoints,real_kind) )
539 sum2 = sum2 + ( zs(ii,jj) - zs_mean )**2
540 sum4 = sum4 + ( zs(ii,jj) - zs_mean )**4
544 var = sum2 /
real(nfinepoints,real_kind)
545 if ( abs(var) < 1.0e-05_real_kind )
then 546 convexity(cell_count) = 0._real_kind
548 convexity(cell_count) = min( sum4 / ( var**2 * &
549 real(nfinepoints,real_kind) ), max_convexity )
561 if(mod(ii_m,2).eq.0.)
then 563 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
567 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
570 do ii = ii_m/2 + 1, ii_m
571 if ( zs(ii,jj) > zs_mean ) nd = nd + 1
574 if ( nu + nd > 0 )
then 575 oa1(cell_count) =
real((nu - nd),real_kind) / &
576 real((nu + nd),real_kind)
578 oa1(cell_count) = 0._real_kind
584 if(mod(jj_m,2).eq.0.)
then 587 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
593 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
597 do jj = jj_m/2 + 1,jj_m
599 if ( zs(ii,jj) > zs_mean ) nd = nd + 1
602 if ( nu + nd > 0 )
then 603 oa2(cell_count) =
real((nu - nd),real_kind) / &
604 real((nu + nd),real_kind)
606 oa2(cell_count) = 0._real_kind
612 ratio =
real(jj_m,real_kind)/
real(ii_m,real_kind)
615 if ( nint(
real(ii,real_kind)*ratio) <= (jj_m - jj + 1) )
then 617 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
619 if ( nint(
real(ii,real_kind)*ratio) >= (jj_m - jj + 1) )
then 621 if ( zs(ii,jj) > zs_mean ) nd = nd + 1
625 if ( nu + nd > 0 )
then 626 oa3(cell_count) =
real((nu - nd),real_kind) / &
627 real((nu + nd),real_kind)
629 oa3(cell_count) = 0._real_kind
635 ratio =
real(jj_m,real_kind)/
real(ii_m,real_kind)
638 if ( nint(
real(ii,real_kind)*ratio) <= jj )
then 640 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
642 if ( nint(
real(ii,real_kind)*ratio) >= jj )
then 644 if ( zs(ii,jj) > zs_mean ) nd = nd + 1
648 if ( nu + nd > 0 )
then 649 oa4(cell_count) =
real((nu - nd),real_kind) / &
650 real((nu + nd),real_kind)
652 oa4(cell_count) = 0._real_kind
663 do jj = max(jj_m/4,1), 3*jj_m/4
666 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
671 ol1(cell_count) =
real(nw,real_kind) /
real(nt,real_kind)
673 ol1(cell_count) = 0._real_kind
680 do ii = max(ii_m/4,1), 3*ii_m/4
682 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
687 ol2(cell_count) =
real(nw,real_kind) /
real(nt,real_kind)
689 ol2(cell_count) = 0._real_kind
697 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
701 do jj = jj_m/2+1, jj_m
702 do ii = ii_m/2+1, ii_m
703 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
708 ol3(cell_count) =
real(nw,real_kind) /
real(nt,real_kind)
710 ol3(cell_count) = 0._real_kind
716 do jj = jj_m/2+1, jj_m
718 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
723 do ii = ii_m/2+1, ii_m
724 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
729 ol4(cell_count) =
real(nw,real_kind) /
real(nt,real_kind)
731 ol4(cell_count) = 0._real_kind
738 cell_count = cell_count + 1
750 if ( halo.eq.
"-999" )
then 751 oro_data_output_file_name =
"C" // trim(res_indx) //
"_oro_data_ss.tile" &
752 // trim(tile_num) //
".nc" 754 oro_data_output_file_name =
"C" // trim(res_indx) //
"_oro_data_ss.tile" &
755 // trim(tile_num) //
".halo0.nc" 759 err = nf90_create(oro_data_output_file_name, nf90_clobber, ncid_out)
760 call netcdf_err(err,
'creating: '//oro_data_output_file_name)
762 err = nf90_redef(ncid_out)
765 err = nf90_def_dim(ncid_out,
'lon',dimx_fv3,lonid)
766 call netcdf_err(err,
'defining lon dimension')
767 err = nf90_def_dim(ncid_out,
'lat',dimy_fv3,latid)
768 call netcdf_err(err,
'defining lat dimension')
776 err = nf90_def_var(ncid_out,
'geolon',nf90_float,dimids,varid)
778 err = nf90_put_att(ncid_out,varid,
'units',
'degrees')
779 err = nf90_put_att(ncid_out,varid,
'description',
'longitude')
780 err = nf90_def_var(ncid_out,
'geolat',nf90_float,dimids,varid)
782 err = nf90_put_att(ncid_out,varid,
'units',
'degrees')
783 err = nf90_put_att(ncid_out,varid,
'description',
'latitude')
784 err = nf90_def_var(ncid_out,
'stddev',nf90_float,dimids,varid)
786 err = nf90_put_att(ncid_out,varid,
'units',
'meters')
787 err = nf90_put_att(ncid_out,varid,
'description', &
788 'standard deviation of subgrid topography')
789 err = nf90_def_var(ncid_out,
'convexity',nf90_float,dimids,varid)
791 err = nf90_put_att(ncid_out,varid,
'units',
'-')
792 err = nf90_put_att(ncid_out,varid,
'description', &
793 'convexity of subgrid topography')
794 err = nf90_def_var(ncid_out,
'oa1',nf90_float,dimids,varid)
796 err = nf90_put_att(ncid_out,varid,
'units',
'-')
797 err = nf90_put_att(ncid_out,varid,
'description', &
798 'orographic asymmetry in west direction')
799 err = nf90_def_var(ncid_out,
'oa2',nf90_float,dimids,varid)
801 err = nf90_put_att(ncid_out,varid,
'units',
'-')
802 err = nf90_put_att(ncid_out,varid,
'description', &
803 'orographic asymmetry in south direction')
804 err = nf90_def_var(ncid_out,
'oa3',nf90_float,dimids,varid)
806 err = nf90_put_att(ncid_out,varid,
'units',
'-')
807 err = nf90_put_att(ncid_out,varid,
'description', &
808 'orographic asymmetry in south-west direction')
809 err = nf90_def_var(ncid_out,
'oa4',nf90_float,dimids,varid)
811 err = nf90_put_att(ncid_out,varid,
'units',
'-')
812 err = nf90_put_att(ncid_out,varid,
'description', &
813 'orographic asymmetry in north-west direction')
814 err = nf90_def_var(ncid_out,
'ol1',nf90_float,dimids,varid)
816 err = nf90_put_att(ncid_out,varid,
'units',
'-')
817 err = nf90_put_att(ncid_out,varid,
'description', &
818 'orographic effective length for westerly flow')
819 err = nf90_def_var(ncid_out,
'ol2',nf90_float,dimids,varid)
821 err = nf90_put_att(ncid_out,varid,
'units',
'-')
822 err = nf90_put_att(ncid_out,varid,
'description', &
823 'orographic effective length for southerly flow')
824 err = nf90_def_var(ncid_out,
'ol3',nf90_float,dimids,varid)
826 err = nf90_put_att(ncid_out,varid,
'units',
'-')
827 err = nf90_put_att(ncid_out,varid,
'description', &
828 'orographic effective length for south-westerly flow')
829 err = nf90_def_var(ncid_out,
'ol4',nf90_float,dimids,varid)
831 err = nf90_put_att(ncid_out,varid,
'units',
'-')
832 err = nf90_put_att(ncid_out,varid,
'description', &
833 'orographic effective length for north-westerly flow')
836 err = nf90_put_att(ncid_out,nf90_global, &
837 'source_file_for_high-resolution_topography', &
838 trim(fine_topo_source_file_name))
840 err = nf90_enddef(ncid_out)
844 err = nf90_inq_varid(ncid_out,
'geolon',varid)
846 err = nf90_put_var(ncid_out,varid,lon_fv3_deg,start=(/1,1/), &
847 count=(/dimx_fv3,dimy_fv3/))
849 err = nf90_inq_varid(ncid_out,
'geolat',varid)
851 err = nf90_put_var(ncid_out,varid,lat_fv3_deg,start=(/1,1/), &
852 count=(/dimx_fv3,dimy_fv3/))
854 err = nf90_inq_varid(ncid_out,
'stddev',varid)
856 err = nf90_put_var(ncid_out,varid,std_dev,start=(/1,1/), &
857 count=(/dimx_fv3,dimy_fv3/))
859 err = nf90_inq_varid(ncid_out,
'convexity',varid)
861 err = nf90_put_var(ncid_out,varid,convexity,start=(/1,1/), &
862 count=(/dimx_fv3,dimy_fv3/))
864 err = nf90_inq_varid(ncid_out,
'oa1',varid)
866 err = nf90_put_var(ncid_out,varid,oa1,start=(/1,1/), &
867 count=(/dimx_fv3,dimy_fv3/))
869 err = nf90_inq_varid(ncid_out,
'oa2',varid)
871 err = nf90_put_var(ncid_out,varid,oa2,start=(/1,1/), &
872 count=(/dimx_fv3,dimy_fv3/))
874 err = nf90_inq_varid(ncid_out,
'oa3',varid)
876 err = nf90_put_var(ncid_out,varid,oa3,start=(/1,1/), &
877 count=(/dimx_fv3,dimy_fv3/))
879 err = nf90_inq_varid(ncid_out,
'oa4',varid)
881 err = nf90_put_var(ncid_out,varid,oa4,start=(/1,1/), &
882 count=(/dimx_fv3,dimy_fv3/))
884 err = nf90_inq_varid(ncid_out,
'ol1',varid)
886 err = nf90_put_var(ncid_out,varid,ol1,start=(/1,1/), &
887 count=(/dimx_fv3,dimy_fv3/))
889 err = nf90_inq_varid(ncid_out,
'ol2',varid)
891 err = nf90_put_var(ncid_out,varid,ol2,start=(/1,1/), &
892 count=(/dimx_fv3,dimy_fv3/))
894 err = nf90_inq_varid(ncid_out,
'ol3',varid)
896 err = nf90_put_var(ncid_out,varid,ol3,start=(/1,1/), &
897 count=(/dimx_fv3,dimy_fv3/))
899 err = nf90_inq_varid(ncid_out,
'ol4',varid)
901 err = nf90_put_var(ncid_out,varid,ol4,start=(/1,1/), &
902 count=(/dimx_fv3,dimy_fv3/))
905 err = nf90_close(ncid_out)
913 duplicate_oro_data_file = .false.
915 if ( min_dx.le.7.5 )
then 917 duplicate_oro_data_file = .true.
918 print *,
"Creating oro_data_ls file as duplicate of oro_data_ss" 919 print *,
"Minimum grid cell size = ", min_dx,
" km" 923 if ( halo.eq.
"-999" )
then 924 oro_data_output_file_name =
"C" // trim(res_indx) //
"_oro_data_ls.tile" &
925 // trim(tile_num) //
".nc" 927 oro_data_output_file_name =
"C" // trim(res_indx) //
"_oro_data_ls.tile" &
928 // trim(tile_num) //
".halo0.nc" 932 err = nf90_create(oro_data_output_file_name, nf90_clobber, ncid_out)
933 call netcdf_err(err,
'creating: '//oro_data_output_file_name)
935 err = nf90_redef(ncid_out)
938 err = nf90_def_dim(ncid_out,
'lon',dimx_fv3,lonid)
939 call netcdf_err(err,
'defining lon dimension')
940 err = nf90_def_dim(ncid_out,
'lat',dimy_fv3,latid)
941 call netcdf_err(err,
'defining lat dimension')
949 err = nf90_def_var(ncid_out,
'geolon',nf90_float,dimids,varid)
951 err = nf90_put_att(ncid_out,varid,
'units',
'degrees')
952 err = nf90_put_att(ncid_out,varid,
'description',
'longitude')
953 err = nf90_def_var(ncid_out,
'geolat',nf90_float,dimids,varid)
955 err = nf90_put_att(ncid_out,varid,
'units',
'degrees')
956 err = nf90_put_att(ncid_out,varid,
'description',
'latitude')
957 err = nf90_def_var(ncid_out,
'stddev',nf90_float,dimids,varid)
959 err = nf90_put_att(ncid_out,varid,
'units',
'meters')
960 err = nf90_put_att(ncid_out,varid,
'description', &
961 'standard deviation of subgrid topography')
962 err = nf90_def_var(ncid_out,
'convexity',nf90_float,dimids,varid)
964 err = nf90_put_att(ncid_out,varid,
'units',
'-')
965 err = nf90_put_att(ncid_out,varid,
'description', &
966 'convexity of subgrid topography')
967 err = nf90_def_var(ncid_out,
'oa1',nf90_float,dimids,varid)
969 err = nf90_put_att(ncid_out,varid,
'units',
'-')
970 err = nf90_put_att(ncid_out,varid,
'description', &
971 'orographic asymmetry in west direction')
972 err = nf90_def_var(ncid_out,
'oa2',nf90_float,dimids,varid)
974 err = nf90_put_att(ncid_out,varid,
'units',
'-')
975 err = nf90_put_att(ncid_out,varid,
'description', &
976 'orographic asymmetry in south direction')
977 err = nf90_def_var(ncid_out,
'oa3',nf90_float,dimids,varid)
979 err = nf90_put_att(ncid_out,varid,
'units',
'-')
980 err = nf90_put_att(ncid_out,varid,
'description', &
981 'orographic asymmetry in south-west direction')
982 err = nf90_def_var(ncid_out,
'oa4',nf90_float,dimids,varid)
984 err = nf90_put_att(ncid_out,varid,
'units',
'-')
985 err = nf90_put_att(ncid_out,varid,
'description', &
986 'orographic asymmetry in north-west direction')
987 err = nf90_def_var(ncid_out,
'ol1',nf90_float,dimids,varid)
989 err = nf90_put_att(ncid_out,varid,
'units',
'-')
990 err = nf90_put_att(ncid_out,varid,
'description', &
991 'orographic effective length for westerly flow')
992 err = nf90_def_var(ncid_out,
'ol2',nf90_float,dimids,varid)
994 err = nf90_put_att(ncid_out,varid,
'units',
'-')
995 err = nf90_put_att(ncid_out,varid,
'description', &
996 'orographic effective length for southerly flow')
997 err = nf90_def_var(ncid_out,
'ol3',nf90_float,dimids,varid)
999 err = nf90_put_att(ncid_out,varid,
'units',
'-')
1000 err = nf90_put_att(ncid_out,varid,
'description', &
1001 'orographic effective length for south-westerly flow')
1002 err = nf90_def_var(ncid_out,
'ol4',nf90_float,dimids,varid)
1004 err = nf90_put_att(ncid_out,varid,
'units',
'-')
1005 err = nf90_put_att(ncid_out,varid,
'description', &
1006 'orographic effective length for north-westerly flow')
1009 err = nf90_put_att(ncid_out,nf90_global, &
1010 'NOTE',
'This is a duplicate of the oro_data_ss file')
1012 err = nf90_enddef(ncid_out)
1016 err = nf90_inq_varid(ncid_out,
'geolon',varid)
1018 err = nf90_put_var(ncid_out,varid,lon_fv3_deg,start=(/1,1/), &
1019 count=(/dimx_fv3,dimy_fv3/))
1021 err = nf90_inq_varid(ncid_out,
'geolat',varid)
1023 err = nf90_put_var(ncid_out,varid,lat_fv3_deg,start=(/1,1/), &
1024 count=(/dimx_fv3,dimy_fv3/))
1026 err = nf90_inq_varid(ncid_out,
'stddev',varid)
1028 err = nf90_put_var(ncid_out,varid,std_dev,start=(/1,1/), &
1029 count=(/dimx_fv3,dimy_fv3/))
1031 err = nf90_inq_varid(ncid_out,
'convexity',varid)
1033 err = nf90_put_var(ncid_out,varid,convexity,start=(/1,1/), &
1034 count=(/dimx_fv3,dimy_fv3/))
1036 err = nf90_inq_varid(ncid_out,
'oa1',varid)
1038 err = nf90_put_var(ncid_out,varid,oa1,start=(/1,1/), &
1039 count=(/dimx_fv3,dimy_fv3/))
1041 err = nf90_inq_varid(ncid_out,
'oa2',varid)
1043 err = nf90_put_var(ncid_out,varid,oa2,start=(/1,1/), &
1044 count=(/dimx_fv3,dimy_fv3/))
1046 err = nf90_inq_varid(ncid_out,
'oa3',varid)
1048 err = nf90_put_var(ncid_out,varid,oa3,start=(/1,1/), &
1049 count=(/dimx_fv3,dimy_fv3/))
1051 err = nf90_inq_varid(ncid_out,
'oa4',varid)
1053 err = nf90_put_var(ncid_out,varid,oa4,start=(/1,1/), &
1054 count=(/dimx_fv3,dimy_fv3/))
1056 err = nf90_inq_varid(ncid_out,
'ol1',varid)
1058 err = nf90_put_var(ncid_out,varid,ol1,start=(/1,1/), &
1059 count=(/dimx_fv3,dimy_fv3/))
1061 err = nf90_inq_varid(ncid_out,
'ol2',varid)
1063 err = nf90_put_var(ncid_out,varid,ol2,start=(/1,1/), &
1064 count=(/dimx_fv3,dimy_fv3/))
1066 err = nf90_inq_varid(ncid_out,
'ol3',varid)
1068 err = nf90_put_var(ncid_out,varid,ol3,start=(/1,1/), &
1069 count=(/dimx_fv3,dimy_fv3/))
1071 err = nf90_inq_varid(ncid_out,
'ol4',varid)
1073 err = nf90_put_var(ncid_out,varid,ol4,start=(/1,1/), &
1074 count=(/dimx_fv3,dimy_fv3/))
1077 err = nf90_close(ncid_out)
1081 print *,
"Minimum grid cell size = ", min_dx,
" km" 1091 deallocate(lat_fv3_deg)
1092 deallocate(lon_fv3_deg)
1093 deallocate(area_fv3)
1094 deallocate(lat1d_fine)
1095 deallocate(lon1d_fine)
1096 deallocate(hgt_m_fine)
1098 deallocate(convexity)
1109 end subroutine calc_gsl_oro_data_sm_scale
1116 function nearest_i_east(lon_in)
1120 integer :: nearest_i_east
1121 real (kind=real_kind),
intent(in) :: lon_in
1122 real (kind=real_kind) :: lon
1127 do while ( (lon.lt.(-pi)).or.(lon.gt.pi) )
1128 if ( lon.lt.(-pi) ) lon = lon + 2*pi
1129 if ( lon.gt.pi ) lon = lon - 2*pi
1132 if ( lon.gt.lon1d_fine(dimx_fine) )
then 1136 do while ( lon1d_fine(i).lt.lon )
1142 end function nearest_i_east
1149 function nearest_i_west(lon_in)
1153 integer :: nearest_i_west
1154 real (kind=real_kind),
intent(in) :: lon_in
1155 real (kind=real_kind) :: lon
1160 do while ( (lon.lt.(-pi)).or.(lon.gt.pi) )
1161 if ( lon.lt.(-pi) ) lon = lon + 2*pi
1162 if ( lon.gt.pi ) lon = lon - 2*pi
1165 if ( (lon.lt.lon1d_fine(1)).or.(lon.ge.lon1d_fine(dimx_fine)) )
then 1166 nearest_i_west = dimx_fine
1169 do while ( lon1d_fine(i).le.lon )
1172 nearest_i_west = i - 1
1175 end function nearest_i_west
1182 function nearest_j_north(lat_in)
1188 integer :: nearest_j_north
1189 real (kind=real_kind),
intent(in) :: lat_in
1190 real (kind=real_kind) :: lat
1194 if ( abs(lat_in).gt.p5*pi )
then 1195 nearest_j_north = -999
1198 do while ( (lat1d_fine(j).lt.lat).and.(j.lt.dimy_fine) )
1204 end function nearest_j_north
1211 function nearest_j_south(lat_in)
1217 integer :: nearest_j_south
1218 real (kind=real_kind),
intent(in) :: lat_in
1219 real (kind=real_kind) :: lat
1223 if ( abs(lat_in).gt.p5*pi )
then 1224 nearest_j_south = -999
1225 elseif ( lat_in.le.lat1d_fine(1) )
then 1229 do while ( (lat1d_fine(j).le.lat).and.(j.le.dimy_fine) )
1232 nearest_j_south = j - 1
1235 end function nearest_j_south
1246 function interp_1d(x,x1,x2,y1,y2)
1251 real (kind=real_kind) :: interp_1d
1252 real (kind=real_kind),
intent(in) :: x,x1,x2,y1,y2
1253 real (kind=real_kind) :: slope
1256 slope = (y2-y1)/(x2-x1)
1257 interp_1d = y1 + slope*(x-x1)
1259 end function interp_1d
1272 integer,
intent(in) :: err
1273 character(len=*),
intent(in) :: string
1274 character(len=256) :: errmsg
1276 if (err.eq.nf90_noerr )
return 1277 errmsg = nf90_strerror(err)
1279 print *,
"FATAL ERROR: ", trim(string),
": ", trim(errmsg)
1288 end module gsl_oro_data_sm_scale
subroutine netcdf_err(err, string)
Check NetCDF error code and output the error message.