Commit 82dbbfe6 authored by ronesy's avatar ronesy
Browse files

Added writing and reading of correl.txt file for spatial correlations

parent 00ba3750
......@@ -26,18 +26,20 @@
!! Interface:
!!
!! Inputs
!! files - file data structure
!! config - configuration settings data structure
!! corr - correlation matrix (zero matrix on input)
!!
!---------------------------------------------------------------------------------------
subroutine correl(config, corr)
subroutine correl(files, config, corr)
use mod_var
use mod_settings
implicit none
type (files_t), intent (in) :: files
type (config_t), intent (in) :: config
real, dimension(nbox,nbox), intent(in out) :: corr
......@@ -47,6 +49,8 @@ subroutine correl(config, corr)
real :: pih, cor, dd, ddx, num
real :: lat1, lat2, lon1, lon2
real :: sigma1, sigma2
character(len=max_path_len) :: rowfmt
integer :: ierr
pih = pi/180.
......@@ -114,6 +118,14 @@ subroutine correl(config, corr)
end do ! ind2
end do ! ind1
! save correlations to file
open(100,file=trim(files%path_output)//'correl.txt',action='write',status='replace',iostat=ierr)
write(rowfmt,'(A,I6,A)') '(',nbox,'(E11.4,1X))'
print*, rowfmt
do ix = 1, nbox
write(100,fmt=rowfmt) corr(ix,:)
end do
close(100)
end subroutine correl
......@@ -604,7 +604,19 @@ subroutine init_co2(files, config, fluxes, obs, states, covar)
corr(:,:) = 0.
if ( config%spa_corr ) then
write(logid,*) 'Using spatial correlation in B'
call correl(config, corr)
! check if file already exists (in case of rerun)
inquire(file=trim(files%path_output)//'correl.txt',exist=lexist)
if ( lexist ) then
write(logid,*) 'Reading spatial correlation from correl.txt'
open(100,file=trim(files%path_output)//'correl.txt',action='read',status='old',iostat=ierr)
write(rowfmt,'(A,I6,A)') '(',nbox,'(E11.4,1X))'
do nb = 1, nbox
read(100,rowfmt) corr(nb,:)
end do
close(100)
else
call correl(files, config, corr)
endif
else
do n = 1, nbox
corr(n,n) = 1.
......
......@@ -337,7 +337,21 @@ subroutine init_ghg(files, config, fluxes, obs, states, covar)
corr(:,:) = 0.
if ( config%spa_corr ) then
write(logid,*) 'Using spatial correlation in B'
call correl(config, corr)
! check if file already exists (in case of rerun)
inquire(file=trim(files%path_output)//'correl.txt',exist=lexist)
if ( lexist ) then
write(logid,*) 'Reading spatial correlation from correl.txt'
open(100,file=trim(files%path_output)//'correl.txt',action='read',status='old',iostat=ierr)
write(rowfmt,'(A,I6,A)') '(',nbox,'(E11.4,1X))'
print*, rowfmt
do nb = 1, nbox
read(100,fmt=rowfmt) corr(nb,:)
print*, corr(nb,:)
end do
close(100)
else
call correl(files, config, corr)
endif
else
do n = 1, nbox
corr(n,n) = 1.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment