22 module gsl_oro_data_lg_scale
26 integer,
parameter :: real_kind = selected_real_kind(6)
27 integer,
parameter :: dbl_kind = selected_real_kind(13)
29 real,
parameter :: pi = 3.1415926535897_real_kind
33 real (kind = real_kind),
allocatable :: lat1d_fine(:)
34 real (kind = real_kind),
allocatable :: lon1d_fine(:)
36 real (kind = real_kind),
parameter :: p5 = 0.5_real_kind
38 real (kind = real_kind),
allocatable :: hgt_m_fine(:,:)
39 real (kind = real_kind),
parameter :: hgt_missing = 1.e+10
50 subroutine calc_gsl_oro_data_lg_scale(tile_num,res_indx,halo)
56 character(len=2),
intent(in) :: tile_num
57 character(len=7),
intent(in) :: res_indx
58 character(len=4),
intent(in) :: halo
62 integer :: ncid_in,ncid_out,err
64 integer :: dimid,latid,lonid
65 integer,
dimension (2) :: dimids
67 integer :: nfinepoints
69 real (kind = real_kind) :: sum2, sum4, var
72 real (kind = real_kind),
allocatable :: &
77 real (kind = real_kind) :: zs_mean
78 real (kind = real_kind),
allocatable :: &
79 std_dev(:),convexity(:), &
80 OA1(:),OA2(:),OA3(:),OA4(:), &
81 OL1(:),OL2(:),OL3(:),OL4(:)
83 real (kind = real_kind),
parameter :: max_convexity = 10._real_kind
85 integer :: nu, nd, nw, nt
86 real (kind = real_kind) :: ratio
89 real,
parameter :: ae = 6371200._real_kind
91 character(len=35) :: FV3_grid_input_file_name
92 character(len=150) :: fine_topo_source_file_name
93 character(len=35) :: oro_data_output_file_name
95 integer :: temp_int, dimX_FV3, dimY_FV3
96 real (kind = dbl_kind),
allocatable :: lat_FV3_raw(:,:), lon_FV3_raw(:,:)
97 real (kind = real_kind),
allocatable :: lat_FV3(:,:), lon_FV3(:,:)
98 real (kind = real_kind),
allocatable :: lat_FV3_deg(:,:)
99 real (kind = real_kind),
allocatable :: lon_FV3_deg(:,:)
100 real (kind = dbl_kind),
allocatable :: area_FV3_qtr(:,:)
101 real (kind = real_kind),
allocatable :: area_FV3(:,:)
102 real (kind = real_kind) :: dlta_lat, dlta_lon
104 integer :: i_blk, j_blk
105 integer :: ii_loc, jj_loc, ii_m, jj_m
106 integer,
dimension(3) :: s_ii, e_ii, s_jj, e_jj
107 real (kind = real_kind),
dimension(3) :: lat_blk, lon_blk
108 real (kind = real_kind),
dimension(3,3) :: HGT_M_coarse
109 real (kind = real_kind),
allocatable :: HGT_M_coarse_on_fine(:,:)
110 integer :: cell_count
115 logical,
parameter :: detrend_topography = .true.
120 print *,
"Creating oro_data_ls file" 124 if ( halo.eq.
"-999" )
then 125 fv3_grid_input_file_name =
"C" // trim(res_indx) //
"_grid.tile" // &
126 trim(tile_num) //
".nc" 128 fv3_grid_input_file_name =
"C" // trim(res_indx) //
"_grid.tile" // &
129 trim(tile_num) //
".halo" // trim(halo) //
".nc" 132 print *,
"Reading from file: ", fv3_grid_input_file_name
135 inquire(file=fv3_grid_input_file_name,exist=fexist)
136 if (.not.fexist)
then 138 print *,
"Fatal error: Input file "//trim(fv3_grid_input_file_name)// &
140 print *,
"Exiting program gsl_oro_data.f90" 148 if ( halo.eq.
"-999" )
then 151 read(halo,*) halo_int
156 err = nf90_open(fv3_grid_input_file_name,nf90_nowrite,ncid_in)
157 call netcdf_err(err,
'opening: '//fv3_grid_input_file_name)
159 err = nf90_inq_dimid(ncid_in,
'nx',dimid)
161 err = nf90_inquire_dimension(ncid_in,dimid,len=temp_int)
163 dimx_fv3 = temp_int/2 - 2*halo_int
165 err = nf90_inq_dimid(ncid_in,
'ny',dimid)
167 err = nf90_inquire_dimension(ncid_in,dimid,len=temp_int)
169 dimy_fv3 = temp_int/2 - 2*halo_int
171 print *,
"dimX_FV3 =", dimx_fv3
172 print *,
"dimY_FV3 =", dimy_fv3
176 allocate (lat_fv3_raw((2*dimx_fv3+1),(2*dimy_fv3+1)))
177 err = nf90_inq_varid(ncid_in,
'y',varid)
179 err = nf90_get_var(ncid_in,varid,lat_fv3_raw, &
180 start=(/1+2*halo_int,1+2*halo_int/), &
181 count=(/2*dimx_fv3+1,2*dimy_fv3+1/))
184 allocate (lon_fv3_raw((2*dimx_fv3+1),(2*dimy_fv3+1)))
185 err = nf90_inq_varid(ncid_in,
'x',varid)
187 err = nf90_get_var(ncid_in,varid,lon_fv3_raw, &
188 start=(/1+2*halo_int,1+2*halo_int/), &
189 count=(/2*dimx_fv3+1,2*dimy_fv3+1/))
193 allocate (area_fv3_qtr((2*dimx_fv3),(2*dimy_fv3)))
194 err = nf90_inq_varid(ncid_in,
'area',varid)
196 err = nf90_get_var(ncid_in,varid,area_fv3_qtr, &
197 start=(/1+2*halo_int,1+2*halo_int/), &
198 count=(/2*dimx_fv3,2*dimy_fv3/))
204 allocate (lat_fv3(dimx_fv3,dimy_fv3))
205 allocate (lon_fv3(dimx_fv3,dimy_fv3))
206 allocate (lat_fv3_deg(dimx_fv3,dimy_fv3))
207 allocate (lon_fv3_deg(dimx_fv3,dimy_fv3))
210 lat_fv3(i,j) = lat_fv3_raw(2*i,2*j)
211 lon_fv3(i,j) = lon_fv3_raw(2*i,2*j)
214 lat_fv3_deg(:,:) = lat_fv3(:,:)
215 lon_fv3_deg(:,:) = lon_fv3(:,:)
216 deallocate(lat_fv3_raw)
217 deallocate(lon_fv3_raw)
220 lat_fv3 = lat_fv3*pi/180._real_kind
221 lon_fv3 = lon_fv3*pi/180._real_kind
225 allocate(area_fv3(dimx_fv3,dimy_fv3))
228 area_fv3(i,j) = area_fv3_qtr(2*i-1,2*j-1) + area_fv3_qtr(2*i-1,2*j) + &
229 area_fv3_qtr(2*i,2*j-1) + area_fv3_qtr(2*i,2*j)
232 deallocate(area_fv3_qtr)
234 err = nf90_close(ncid_in)
239 fine_topo_source_file_name =
"geo_em.d01.lat-lon.2.5m.HGT_M.nc" 241 inquire(file=fine_topo_source_file_name,exist=fexist)
242 if (.not.fexist)
then 244 print *,
"Fatal error: Topo source file "// &
245 trim(fine_topo_source_file_name)//
" does not exist" 246 print *,
"Exiting program gsl_oro_data.f90" 250 err = nf90_open(trim(fine_topo_source_file_name),nf90_nowrite,ncid_in)
251 call netcdf_err(err,
'opening: '//trim(fine_topo_source_file_name))
254 err = nf90_inq_dimid(ncid_in,
'west_east',dimid)
256 err = nf90_inquire_dimension(ncid_in,dimid,len=dimx_fine)
257 call netcdf_err(err,
'reading west_east value')
259 err = nf90_inq_dimid(ncid_in,
'south_north',dimid)
260 call netcdf_err(err,
'reading south_north id')
261 err = nf90_inquire_dimension(ncid_in,dimid,len=dimy_fine)
262 call netcdf_err(err,
'reading south_north value')
264 print *,
"Source file for high-resolution topography: ", &
265 trim(fine_topo_source_file_name)
266 print *,
"dimX_fine =", dimx_fine
267 print *,
"dimY_fine =", dimy_fine
272 allocate(lat1d_fine(dimy_fine))
273 allocate(lon1d_fine(dimx_fine))
274 err = nf90_inq_varid(ncid_in,
'CLAT',varid)
276 err = nf90_get_var(ncid_in,varid,lat1d_fine,start=(/1,1/), &
277 count=(/1,dimy_fine/))
280 err = nf90_inq_varid(ncid_in,
'CLONG',varid)
282 err = nf90_get_var(ncid_in,varid,lon1d_fine,start=(/1,1/), &
283 count=(/dimx_fine,1/))
287 lat1d_fine = lat1d_fine*pi/180._real_kind
288 lon1d_fine = lon1d_fine*pi/180._real_kind
294 if ( lon_fv3(i,j).gt.pi )
then 295 lon_fv3(i,j) = lon_fv3(i,j) - 2*pi
302 allocate(hgt_m_fine(dimx_fine,dimy_fine))
303 err = nf90_inq_varid(ncid_in,
'HGT_M',varid)
305 err = nf90_get_var(ncid_in,varid,hgt_m_fine,start=(/1,1/), &
306 count=(/dimx_fine,dimy_fine/))
310 err = nf90_close(ncid_in)
314 allocate (std_dev(dimx_fv3*dimy_fv3))
315 allocate (convexity(dimx_fv3*dimy_fv3))
316 allocate (oa1(dimx_fv3*dimy_fv3))
317 allocate (oa2(dimx_fv3*dimy_fv3))
318 allocate (oa3(dimx_fv3*dimy_fv3))
319 allocate (oa4(dimx_fv3*dimy_fv3))
320 allocate (ol1(dimx_fv3*dimy_fv3))
321 allocate (ol2(dimx_fv3*dimy_fv3))
322 allocate (ol3(dimx_fv3*dimy_fv3))
323 allocate (ol4(dimx_fv3*dimy_fv3))
326 std_dev(:) = 0._real_kind
327 convexity(:) = 0._real_kind
328 oa1(:) = 0._real_kind
329 oa2(:) = 0._real_kind
330 oa3(:) = 0._real_kind
331 oa4(:) = 0._real_kind
332 ol1(:) = 0._real_kind
333 ol2(:) = 0._real_kind
334 ol3(:) = 0._real_kind
335 ol4(:) = 0._real_kind
359 dlta_lat = sqrt(area_fv3(i,j))/ae
360 dlta_lon = sqrt(area_fv3(i,j))/(ae*cos(lat_fv3(i,j)))
366 lon_blk(i_blk) = lon_fv3(i,j) + (i_blk-2)*dlta_lon
370 lat_blk(j_blk) = lat_fv3(i,j) + (j_blk-2)*dlta_lat
378 s_ii(i_blk) = nearest_i_east(lon_blk(i_blk)-p5*dlta_lon)
379 e_ii(i_blk) = nearest_i_west(lon_blk(i_blk)+p5*dlta_lon)
382 s_jj(j_blk) = nearest_j_north(lat_blk(j_blk)-p5*dlta_lat)
383 e_jj(j_blk) = nearest_j_south(lat_blk(j_blk)+p5*dlta_lat)
397 if ( (s_jj(j_blk).eq.-999).and.(e_jj(j_blk).ne.-999) )
then 400 lat_blk(j_blk) = p5*(lat1d_fine(1)+lat1d_fine(e_jj(j_blk)))
406 if ( s_jj(j_blk).eq.-999 )
then 409 lat_blk(j_blk) = p5*(lat1d_fine(1)+lat1d_fine(e_jj(j_blk)))
411 if ( e_jj(j_blk).eq.-999 )
then 412 e_jj(j_blk) = dimy_fine
414 lat_blk(j_blk) = p5*(lat1d_fine(s_jj(j_blk))+lat1d_fine(dimy_fine))
419 if ( (e_jj(j_blk).eq.-999).and.(s_jj(j_blk).ne.-999) )
then 420 e_jj(j_blk) = dimy_fine
422 lat_blk(j_blk) = p5*(lat1d_fine(s_jj(j_blk))+lat1d_fine(dimy_fine))
425 if ( detrend_topography )
then 427 call calc_mean_hgt(s_ii(i_blk),e_ii(i_blk), &
428 s_jj(j_blk),e_jj(j_blk),hgt_m_coarse(i_blk,j_blk))
440 if ( s_ii(2).gt.e_ii(2) )
then 441 ii_m = dimx_fine - s_ii(2) + 1 + e_ii(2)
443 ii_m = e_ii(2) - s_ii(2) + 1
445 jj_m = e_jj(2) - s_jj(2) + 1
452 if ( detrend_topography )
then 456 allocate (hgt_m_coarse_on_fine(ii_m,jj_m))
458 do jj = s_jj(2), e_jj(2)
459 jj_loc = jj - s_jj(2) + 1
461 if ( s_ii(2).gt.e_ii(2) )
then 462 do ii = s_ii(2), dimx_fine
463 ii_loc = ii - s_ii(2) + 1
464 call hgt_interpolate(lat1d_fine(jj),lon1d_fine(ii), &
465 lat_blk(:),lon_blk(:),hgt_m_coarse(:,:), &
466 hgt_m_coarse_on_fine(ii_loc,jj_loc))
470 call hgt_interpolate(lat1d_fine(jj),lon1d_fine(ii), &
471 lat_blk(:),lon_blk(:),hgt_m_coarse(:,:), &
472 hgt_m_coarse_on_fine(ii_loc,jj_loc))
475 do ii = s_ii(2), e_ii(2)
476 ii_loc = ii - s_ii(2) + 1
477 call hgt_interpolate(lat1d_fine(jj),lon1d_fine(ii), &
478 lat_blk(:),lon_blk(:),hgt_m_coarse(:,:), &
479 hgt_m_coarse_on_fine(ii_loc,jj_loc))
491 allocate (zs(ii_m,jj_m))
493 do jj = s_jj(2), e_jj(2)
494 jj_loc = jj - s_jj(2) + 1
496 if ( s_ii(2).gt.e_ii(2) )
then 497 do ii = s_ii(2), dimx_fine
498 ii_loc = ii - s_ii(2) + 1
499 if ( detrend_topography )
then 500 zs(ii_loc,jj_loc) = hgt_m_fine(ii,jj) - &
501 hgt_m_coarse_on_fine(ii_loc,jj_loc)
503 zs(ii_loc,jj_loc) = hgt_m_fine(ii,jj)
508 if ( detrend_topography )
then 509 zs(ii_loc,jj_loc) = hgt_m_fine(ii,jj) - &
510 hgt_m_coarse_on_fine(ii_loc,jj_loc)
512 zs(ii_loc,jj_loc) = hgt_m_fine(ii,jj)
516 do ii = s_ii(2), e_ii(2)
517 ii_loc = ii - s_ii(2) + 1
518 if ( detrend_topography )
then 519 zs(ii_loc,jj_loc) = hgt_m_fine(ii,jj) - &
520 hgt_m_coarse_on_fine(ii_loc,jj_loc)
522 zs(ii_loc,jj_loc) = hgt_m_fine(ii,jj)
539 if ( abs(zs(ii,jj)).gt.1.e-3 ) zs_accum = .true.
542 if ( .not.zs_accum )
then 543 std_dev(cell_count) = 0._real_kind
544 convexity(cell_count) = 0._real_kind
545 oa1(cell_count) = 0._real_kind
546 oa2(cell_count) = 0._real_kind
547 oa3(cell_count) = 0._real_kind
548 oa4(cell_count) = 0._real_kind
549 ol1(cell_count) = 0._real_kind
550 ol2(cell_count) = 0._real_kind
551 ol3(cell_count) = 0._real_kind
552 ol4(cell_count) = 0._real_kind
553 if ( detrend_topography )
deallocate (hgt_m_coarse_on_fine)
555 cell_count = cell_count + 1
566 nfinepoints = ii_m*jj_m
569 sum2 = sum2 + zs(ii,jj)
572 zs_mean = sum2 /
real(nfinepoints,real_kind)
578 sum2 = sum2 + ( zs(ii,jj) - zs_mean )**2
581 std_dev(cell_count) = sqrt( sum2/
real(nfinepoints,real_kind) )
592 sum2 = sum2 + ( zs(ii,jj) - zs_mean )**2
593 sum4 = sum4 + ( zs(ii,jj) - zs_mean )**4
597 var = sum2 /
real(nfinepoints,real_kind)
598 if ( abs(var) < 1.0e-05_real_kind )
then 599 convexity(cell_count) = 0._real_kind
601 convexity(cell_count) = min( sum4 / ( var**2 * &
602 real(nfinepoints,real_kind) ), max_convexity )
614 if(mod(ii_m,2).eq.0.)
then 616 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
620 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
623 do ii = ii_m/2 + 1, ii_m
624 if ( zs(ii,jj) > zs_mean ) nd = nd + 1
627 if ( nu + nd > 0 )
then 628 oa1(cell_count) =
real((nu - nd),real_kind) / &
629 real((nu + nd),real_kind)
631 oa1(cell_count) = 0._real_kind
637 if(mod(jj_m,2).eq.0.)
then 640 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
646 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
650 do jj = jj_m/2 + 1,jj_m
652 if ( zs(ii,jj) > zs_mean ) nd = nd + 1
655 if ( nu + nd > 0 )
then 656 oa2(cell_count) =
real((nu - nd),real_kind) / &
657 real((nu + nd),real_kind)
659 oa2(cell_count) = 0._real_kind
665 ratio =
real(jj_m,real_kind)/
real(ii_m,real_kind)
668 if ( nint(
real(ii,real_kind)*ratio) <= (jj_m - jj + 1) )
then 670 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
672 if ( nint(
real(ii,real_kind)*ratio) >= (jj_m - jj + 1) )
then 674 if ( zs(ii,jj) > zs_mean ) nd = nd + 1
678 if ( nu + nd > 0 )
then 679 oa3(cell_count) =
real((nu - nd),real_kind) / &
680 real((nu + nd),real_kind)
682 oa3(cell_count) = 0._real_kind
688 ratio =
real(jj_m,real_kind)/
real(ii_m,real_kind)
691 if ( nint(
real(ii,real_kind)*ratio) <= jj )
then 693 if ( zs(ii,jj) > zs_mean ) nu = nu + 1
695 if ( nint(
real(ii,real_kind)*ratio) >= jj )
then 697 if ( zs(ii,jj) > zs_mean ) nd = nd + 1
701 if ( nu + nd > 0 )
then 702 oa4(cell_count) =
real((nu - nd),real_kind) / &
703 real((nu + nd),real_kind)
705 oa4(cell_count) = 0._real_kind
716 do jj = max(jj_m/4,1), 3*jj_m/4
719 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
724 ol1(cell_count) =
real(nw,real_kind) /
real(nt,real_kind)
726 ol1(cell_count) = 0._real_kind
733 do ii = max(ii_m/4,1), 3*ii_m/4
735 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
740 ol2(cell_count) =
real(nw,real_kind) /
real(nt,real_kind)
742 ol2(cell_count) = 0._real_kind
750 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
754 do jj = jj_m/2+1, jj_m
755 do ii = ii_m/2+1, ii_m
756 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
761 ol3(cell_count) =
real(nw,real_kind) /
real(nt,real_kind)
763 ol3(cell_count) = 0._real_kind
769 do jj = jj_m/2+1, jj_m
771 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
776 do ii = ii_m/2+1, ii_m
777 if ( zs(ii,jj) > zs_mean ) nw = nw + 1
782 ol4(cell_count) =
real(nw,real_kind) /
real(nt,real_kind)
784 ol4(cell_count) = 0._real_kind
789 if ( detrend_topography )
deallocate (hgt_m_coarse_on_fine)
792 cell_count = cell_count + 1
804 if ( halo.eq.
"-999" )
then 805 oro_data_output_file_name =
"C" // trim(res_indx) //
"_oro_data_ls.tile" &
806 // trim(tile_num) //
".nc" 808 oro_data_output_file_name =
"C" // trim(res_indx) //
"_oro_data_ls.tile" &
809 // trim(tile_num) //
".halo0.nc" 813 err = nf90_create(oro_data_output_file_name, nf90_clobber, ncid_out)
814 call netcdf_err(err,
'creating: '//oro_data_output_file_name)
816 err = nf90_redef(ncid_out)
819 err = nf90_def_dim(ncid_out,
'lon',dimx_fv3,lonid)
820 call netcdf_err(err,
'defining lon dimension')
821 err = nf90_def_dim(ncid_out,
'lat',dimy_fv3,latid)
822 call netcdf_err(err,
'defining lat dimension')
830 err = nf90_def_var(ncid_out,
'geolon',nf90_float,dimids,varid)
832 err = nf90_put_att(ncid_out,varid,
'units',
'degrees')
833 err = nf90_put_att(ncid_out,varid,
'description',
'longitude')
834 err = nf90_def_var(ncid_out,
'geolat',nf90_float,dimids,varid)
836 err = nf90_put_att(ncid_out,varid,
'units',
'degrees')
837 err = nf90_put_att(ncid_out,varid,
'description',
'latitude')
838 err = nf90_def_var(ncid_out,
'stddev',nf90_float,dimids,varid)
840 err = nf90_put_att(ncid_out,varid,
'units',
'meters')
841 err = nf90_put_att(ncid_out,varid,
'description', &
842 'standard deviation of subgrid topography')
843 err = nf90_def_var(ncid_out,
'convexity',nf90_float,dimids,varid)
845 err = nf90_put_att(ncid_out,varid,
'units',
'-')
846 err = nf90_put_att(ncid_out,varid,
'description', &
847 'convexity of subgrid topography')
848 err = nf90_def_var(ncid_out,
'oa1',nf90_float,dimids,varid)
850 err = nf90_put_att(ncid_out,varid,
'units',
'-')
851 err = nf90_put_att(ncid_out,varid,
'description', &
852 'orographic asymmetry in west direction')
853 err = nf90_def_var(ncid_out,
'oa2',nf90_float,dimids,varid)
855 err = nf90_put_att(ncid_out,varid,
'units',
'-')
856 err = nf90_put_att(ncid_out,varid,
'description', &
857 'orographic asymmetry in south direction')
858 err = nf90_def_var(ncid_out,
'oa3',nf90_float,dimids,varid)
860 err = nf90_put_att(ncid_out,varid,
'units',
'-')
861 err = nf90_put_att(ncid_out,varid,
'description', &
862 'orographic asymmetry in south-west direction')
863 err = nf90_def_var(ncid_out,
'oa4',nf90_float,dimids,varid)
865 err = nf90_put_att(ncid_out,varid,
'units',
'-')
866 err = nf90_put_att(ncid_out,varid,
'description', &
867 'orographic asymmetry in north-west direction')
868 err = nf90_def_var(ncid_out,
'ol1',nf90_float,dimids,varid)
870 err = nf90_put_att(ncid_out,varid,
'units',
'-')
871 err = nf90_put_att(ncid_out,varid,
'description', &
872 'orographic effective length for westerly flow')
873 err = nf90_def_var(ncid_out,
'ol2',nf90_float,dimids,varid)
875 err = nf90_put_att(ncid_out,varid,
'units',
'-')
876 err = nf90_put_att(ncid_out,varid,
'description', &
877 'orographic effective length for southerly flow')
878 err = nf90_def_var(ncid_out,
'ol3',nf90_float,dimids,varid)
880 err = nf90_put_att(ncid_out,varid,
'units',
'-')
881 err = nf90_put_att(ncid_out,varid,
'description', &
882 'orographic effective length for south-westerly flow')
883 err = nf90_def_var(ncid_out,
'ol4',nf90_float,dimids,varid)
885 err = nf90_put_att(ncid_out,varid,
'units',
'-')
886 err = nf90_put_att(ncid_out,varid,
'description', &
887 'orographic effective length for north-westerly flow')
890 err = nf90_put_att(ncid_out,nf90_global, &
891 'source_file_for_high-resolution_topography', &
892 trim(fine_topo_source_file_name))
893 if ( detrend_topography )
then 894 err = nf90_put_att(ncid_out,nf90_global, &
895 'high-res_topography_detrended',
'.TRUE.')
897 err = nf90_put_att(ncid_out,nf90_global, &
898 'high-res_topography_detrended',
'.FALSE.')
901 err = nf90_enddef(ncid_out)
905 err = nf90_inq_varid(ncid_out,
'geolon',varid)
907 err = nf90_put_var(ncid_out,varid,lon_fv3_deg,start=(/1,1/), &
908 count=(/dimx_fv3,dimy_fv3/))
910 err = nf90_inq_varid(ncid_out,
'geolat',varid)
912 err = nf90_put_var(ncid_out,varid,lat_fv3_deg,start=(/1,1/), &
913 count=(/dimx_fv3,dimy_fv3/))
915 err = nf90_inq_varid(ncid_out,
'stddev',varid)
917 err = nf90_put_var(ncid_out,varid,std_dev,start=(/1,1/), &
918 count=(/dimx_fv3,dimy_fv3/))
920 err = nf90_inq_varid(ncid_out,
'convexity',varid)
922 err = nf90_put_var(ncid_out,varid,convexity,start=(/1,1/), &
923 count=(/dimx_fv3,dimy_fv3/))
925 err = nf90_inq_varid(ncid_out,
'oa1',varid)
927 err = nf90_put_var(ncid_out,varid,oa1,start=(/1,1/), &
928 count=(/dimx_fv3,dimy_fv3/))
930 err = nf90_inq_varid(ncid_out,
'oa2',varid)
932 err = nf90_put_var(ncid_out,varid,oa2,start=(/1,1/), &
933 count=(/dimx_fv3,dimy_fv3/))
935 err = nf90_inq_varid(ncid_out,
'oa3',varid)
937 err = nf90_put_var(ncid_out,varid,oa3,start=(/1,1/), &
938 count=(/dimx_fv3,dimy_fv3/))
940 err = nf90_inq_varid(ncid_out,
'oa4',varid)
942 err = nf90_put_var(ncid_out,varid,oa4,start=(/1,1/), &
943 count=(/dimx_fv3,dimy_fv3/))
945 err = nf90_inq_varid(ncid_out,
'ol1',varid)
947 err = nf90_put_var(ncid_out,varid,ol1,start=(/1,1/), &
948 count=(/dimx_fv3,dimy_fv3/))
950 err = nf90_inq_varid(ncid_out,
'ol2',varid)
952 err = nf90_put_var(ncid_out,varid,ol2,start=(/1,1/), &
953 count=(/dimx_fv3,dimy_fv3/))
955 err = nf90_inq_varid(ncid_out,
'ol3',varid)
957 err = nf90_put_var(ncid_out,varid,ol3,start=(/1,1/), &
958 count=(/dimx_fv3,dimy_fv3/))
960 err = nf90_inq_varid(ncid_out,
'ol4',varid)
962 err = nf90_put_var(ncid_out,varid,ol4,start=(/1,1/), &
963 count=(/dimx_fv3,dimy_fv3/))
966 err = nf90_close(ncid_out)
973 deallocate(lat_fv3_deg)
974 deallocate(lon_fv3_deg)
976 deallocate(lat1d_fine)
977 deallocate(lon1d_fine)
978 deallocate(hgt_m_fine)
980 deallocate(convexity)
990 end subroutine calc_gsl_oro_data_lg_scale
1000 subroutine calc_mean_hgt(s_ii,e_ii,s_jj,e_jj,HGT)
1011 real (kind=real_kind),
intent(out) :: HGT
1014 integer :: i,j,grid_pt_count
1015 real (kind=real_kind) :: HGT_sum
1022 if ( (s_jj.eq.-999).and.(e_jj.eq.-999) )
then 1028 hgt_sum = 0._real_kind
1032 if ( s_ii.gt.e_ii )
then 1033 do i = s_ii, dimx_fine
1034 hgt_sum = hgt_sum + hgt_m_fine(i,j)
1035 grid_pt_count = grid_pt_count + 1
1038 hgt_sum = hgt_sum + hgt_m_fine(i,j)
1039 grid_pt_count = grid_pt_count + 1
1043 hgt_sum = hgt_sum + hgt_m_fine(i,j)
1044 grid_pt_count = grid_pt_count + 1
1048 hgt = hgt_sum/grid_pt_count
1050 end subroutine calc_mean_hgt
1061 subroutine hgt_interpolate(lat,lon_in,lat_blk,lon_blk,HGT_coarse, &
1072 real (kind = real_kind),
intent(in) :: &
1075 real (kind = real_kind),
dimension(3),
intent(in) :: &
1078 real (kind = real_kind),
dimension(3,3),
intent(in) :: HGT_coarse
1079 real (kind = real_kind),
intent(out) :: HGT_coarse_on_fine
1080 real (kind = real_kind) :: lon
1088 if ( abs(lon_in-lon_blk(2)).gt.pi )
then 1089 if ( lon_in.gt.0. ) lon = lon - 2*pi
1090 if ( lon_in.lt.0. ) lon = lon + 2*pi
1098 if ( (hgt_coarse(1,3).eq.hgt_missing).or.(hgt_coarse(2,3).eq.hgt_missing) &
1099 .or.(hgt_coarse(3,3).eq.hgt_missing) )
then 1102 if ( (lat.ge.lat_blk(2)).and.(lon.ge.lon_blk(2)) )
then 1104 hgt_coarse_on_fine = interp_1d( &
1105 lon,lon_blk(2),lon_blk(3), &
1106 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(2,1),hgt_coarse(2,2)), &
1107 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(3,1),hgt_coarse(3,2)) )
1108 elseif ( (lat.ge.lat_blk(2)).and.(lon.lt.lon_blk(2)) )
then 1110 hgt_coarse_on_fine = interp_1d( &
1111 lon,lon_blk(1),lon_blk(2), &
1112 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(1,1),hgt_coarse(1,2)), &
1113 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(2,1),hgt_coarse(2,2)) )
1114 elseif ( (lat.lt.lat_blk(2)).and.(lon.lt.lon_blk(2)) )
then 1115 hgt_coarse_on_fine = interp_1d( &
1116 lon,lon_blk(1),lon_blk(2), &
1117 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(1,1),hgt_coarse(1,2)), &
1118 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(2,1),hgt_coarse(2,2)) )
1119 elseif ( (lat.lt.lat_blk(2)).and.(lon.ge.lon_blk(2)) )
then 1120 hgt_coarse_on_fine = interp_1d( &
1121 lon,lon_blk(2),lon_blk(3), &
1122 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(2,1),hgt_coarse(2,2)), &
1123 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(3,1),hgt_coarse(3,2)) )
1130 if ( (hgt_coarse(1,1).eq.hgt_missing).or.(hgt_coarse(2,1).eq.hgt_missing) &
1131 .or.(hgt_coarse(3,1).eq.hgt_missing) )
then 1134 if ( (lat.ge.lat_blk(2)).and.(lon.ge.lon_blk(2)) )
then 1135 hgt_coarse_on_fine = interp_1d( &
1136 lon,lon_blk(2),lon_blk(3), &
1137 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(2,2),hgt_coarse(2,3)), &
1138 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(3,2),hgt_coarse(3,3)) )
1139 elseif ( (lat.ge.lat_blk(2)).and.(lon.lt.lon_blk(2)) )
then 1140 hgt_coarse_on_fine = interp_1d( &
1141 lon,lon_blk(1),lon_blk(2), &
1142 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(1,2),hgt_coarse(1,3)), &
1143 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(2,2),hgt_coarse(2,3)) )
1144 elseif ( (lat.lt.lat_blk(2)).and.(lon.lt.lon_blk(2)) )
then 1146 hgt_coarse_on_fine = interp_1d( &
1147 lon,lon_blk(1),lon_blk(2), &
1148 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(1,2),hgt_coarse(1,3)), &
1149 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(2,2),hgt_coarse(2,3)) )
1150 elseif ( (lat.lt.lat_blk(2)).and.(lon.ge.lon_blk(2)) )
then 1152 hgt_coarse_on_fine = interp_1d( &
1153 lon,lon_blk(2),lon_blk(3), &
1154 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(2,2),hgt_coarse(2,3)), &
1155 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(3,2),hgt_coarse(3,3)) )
1163 if ( (lat.ge.lat_blk(2)).and.(lon.ge.lon_blk(2)) )
then 1164 hgt_coarse_on_fine = interp_1d( &
1165 lon,lon_blk(2),lon_blk(3), &
1166 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(2,2),hgt_coarse(2,3)), &
1167 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(3,2),hgt_coarse(3,3)) )
1168 elseif ( (lat.ge.lat_blk(2)).and.(lon.lt.lon_blk(2)) )
then 1169 hgt_coarse_on_fine = interp_1d( &
1170 lon,lon_blk(1),lon_blk(2), &
1171 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(1,2),hgt_coarse(1,3)), &
1172 interp_1d(lat,lat_blk(2),lat_blk(3),hgt_coarse(2,2),hgt_coarse(2,3)) )
1173 elseif ( (lat.lt.lat_blk(2)).and.(lon.lt.lon_blk(2)) )
then 1174 hgt_coarse_on_fine = interp_1d( &
1175 lon,lon_blk(1),lon_blk(2), &
1176 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(1,1),hgt_coarse(1,2)), &
1177 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(2,1),hgt_coarse(2,2)) )
1178 elseif ( (lat.lt.lat_blk(2)).and.(lon.ge.lon_blk(2)) )
then 1179 hgt_coarse_on_fine = interp_1d( &
1180 lon,lon_blk(2),lon_blk(3), &
1181 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(2,1),hgt_coarse(2,2)), &
1182 interp_1d(lat,lat_blk(1),lat_blk(2),hgt_coarse(3,1),hgt_coarse(3,2)) )
1185 end subroutine hgt_interpolate
1192 function nearest_i_east(lon_in)
1196 integer :: nearest_i_east
1197 real (kind=real_kind),
intent(in) :: lon_in
1198 real (kind=real_kind) :: lon
1203 do while ( (lon.lt.(-pi)).or.(lon.gt.pi) )
1204 if ( lon.lt.(-pi) ) lon = lon + 2*pi
1205 if ( lon.gt.pi ) lon = lon - 2*pi
1208 if ( lon.gt.lon1d_fine(dimx_fine) )
then 1212 do while ( lon1d_fine(i).lt.lon )
1218 end function nearest_i_east
1225 function nearest_i_west(lon_in)
1229 integer :: nearest_i_west
1230 real (kind=real_kind),
intent(in) :: lon_in
1231 real (kind=real_kind) :: lon
1236 do while ( (lon.lt.(-pi)).or.(lon.gt.pi) )
1237 if ( lon.lt.(-pi) ) lon = lon + 2*pi
1238 if ( lon.gt.pi ) lon = lon - 2*pi
1241 if ( (lon.lt.lon1d_fine(1)).or.(lon.ge.lon1d_fine(dimx_fine)) )
then 1242 nearest_i_west = dimx_fine
1245 do while ( lon1d_fine(i).le.lon )
1248 nearest_i_west = i - 1
1251 end function nearest_i_west
1258 function nearest_j_north(lat_in)
1264 integer :: nearest_j_north
1265 real (kind=real_kind),
intent(in) :: lat_in
1266 real (kind=real_kind) :: lat
1270 if ( abs(lat_in).gt.p5*pi )
then 1271 nearest_j_north = -999
1274 do while ( (lat1d_fine(j).lt.lat).and.(j.lt.dimy_fine) )
1280 end function nearest_j_north
1287 function nearest_j_south(lat_in)
1293 integer :: nearest_j_south
1294 real (kind=real_kind),
intent(in) :: lat_in
1295 real (kind=real_kind) :: lat
1299 if ( abs(lat_in).gt.p5*pi )
then 1300 nearest_j_south = -999
1301 elseif ( lat_in.le.lat1d_fine(1) )
then 1305 do while ( (lat1d_fine(j).le.lat).and.(j.le.dimy_fine) )
1308 nearest_j_south = j - 1
1311 end function nearest_j_south
1322 function interp_1d(x,x1,x2,y1,y2)
1327 real (kind=real_kind) :: interp_1d
1328 real (kind=real_kind),
intent(in) :: x,x1,x2,y1,y2
1329 real (kind=real_kind) :: slope
1332 slope = (y2-y1)/(x2-x1)
1333 interp_1d = y1 + slope*(x-x1)
1335 end function interp_1d
1348 integer,
intent(in) :: err
1349 character(len=*),
intent(in) :: string
1350 character(len=256) :: errmsg
1352 if (err.eq.nf90_noerr )
return 1353 errmsg = nf90_strerror(err)
1355 print *,
"FATAL ERROR: ", trim(string),
": ", trim(errmsg)
1362 end module gsl_oro_data_lg_scale
subroutine netcdf_err(err, string)
Check NetCDF error code and output the error message.