Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions main/FatesInventoryInitMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ subroutine initialize_sites_by_inventory(nsites,sites,bc_in)

real(r8), allocatable :: inv_lat_list(:) ! list of lat coords
real(r8), allocatable :: inv_lon_list(:) ! list of lon coords
real(r8), allocatable :: delta_lon_list(:) ! list of lon cord difference between model grid and inventory sites [0-180]
real(r8), allocatable :: dist_list(:) ! list of distance between model grid and inventory sites
integer :: invsite ! index of inventory site
! closest to actual site
integer :: el ! loop counter for number of elements
Expand Down Expand Up @@ -231,13 +233,14 @@ subroutine initialize_sites_by_inventory(nsites,sites,bc_in)
! For each site, identify the most proximal PSS/CSS couplet, read-in the data
! allocate linked lists and assign to memory
do s = 1, nsites
invsite = &
minloc( (sites(s)%lat-inv_lat_list(:))**2.0_r8 + &
(sites(s)%lon-inv_lon_list(:))**2.0_r8 , dim=1)
delta_lon_list = abs(modulo((sites(s)%lon - inv_lon_list(:)) + &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tempted to create a little unit test for this...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rgknox Go ahead! it's always good to have one.

180.0_r8, 360.0_r8)-180.0_r8)
dist_list = (sites(s)%lat - inv_lat_list(:))**2.0_r8 + &
delta_lon_list**2.0_r8
invsite = minloc(dist_list(:), dim=1)

! Do a sanity check on the distance separation between physical site and model site
if ( sqrt( (sites(s)%lat-inv_lat_list(invsite))**2.0_r8 + &
(sites(s)%lon-inv_lon_list(invsite))**2.0_r8 ) > max_site_adjacency_deg ) then
if ( sqrt(dist_list(invsite)) ) > max_site_adjacency_deg ) then
write(fates_log(), *) 'Model site at lat:',sites(s)%lat,' lon:',sites(s)%lon
write(fates_log(), *) 'has no reasonably proximal site in the inventory site list.'
write(fates_log(), *) 'Closest is at lat:',inv_lat_list(invsite),' lon:',inv_lon_list(invsite)
Expand Down