From 9576d714e19a8a2dccd073f395af3e3ff94e9347 Mon Sep 17 00:00:00 2001 From: Miles Curry <2590700+MiCurry@users.noreply.github.com> Date: Tue, 22 Sep 2026 11:00:48 -0600 Subject: [PATCH] Fix -J by correctly using orient and fixing read/write vec This commit fixes an error in -J where NaN's would be found in b. This was because the orientation (orient) was being used incorrectly and was uninitialized. This caused NaN's to form in b, which was then detected later by the solver. Furthermore, the sensitvity matrix was not correctly being written out as the modelParam readvec/writevec were left empty. This commit makes those routine call the binary versions when called. Later, these can be updated to write out different file types. This issue was reported by Xiaolei (@xltu) in issue #87 and reported the fix. --- f90/3D_MT/modelParam/modelParamIO.f90 | 33 +++++++++++++++++++++++---- f90/MPI/Main_MPI.f90 | 4 ++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/f90/3D_MT/modelParam/modelParamIO.f90 b/f90/3D_MT/modelParam/modelParamIO.f90 index 1220989f..5b3b688a 100644 --- a/f90/3D_MT/modelParam/modelParamIO.f90 +++ b/f90/3D_MT/modelParam/modelParamIO.f90 @@ -83,6 +83,27 @@ end subroutine read_modelParam_HDF5 #endif end interface + ! Read/write ModelParam Vec for Sensitivity Matrix + interface + module subroutine readVec_modelParam_binary(grid,nSigma,m,header,cfile) + implicit none + type(grid_t), target, intent(inout) :: grid + integer, intent(in) :: nSigma + type(modelParam_t), intent(inout) :: m(nSigma) + character(*), intent(in) :: cfile + character(80), intent(out) :: header + end subroutine readVec_modelParam_binary + end interface + + interface + module subroutine writeVec_modelParam_binary(nSigma,m,header,cfile) + implicit none + integer, intent(in) :: nSigma + character(*), intent(in) :: cfile, header + type(modelParam_t), intent(in) :: m(nSigma) + end subroutine writeVec_modelParam_binary + end interface + contains subroutine unsupported_modelParamIO_error(ftype_choice, input_or_output) @@ -209,15 +230,19 @@ module subroutine readVec_modelParam(grid,nSigma,sigma,header,cfile) character(*), intent(out) :: header character(*), intent(in) :: cfile + call readVec_modelParam_binary(grid, nSigma, sigma, header, Cfile) + end subroutine readVec_modelParam module subroutine writeVec_modelParam(nSigma,sigma,header,cfile) - implicit none + implicit none + + integer, intent(in) :: nSigma + character(*), intent(in) :: header, cfile + type(modelParam_t), intent(in) :: sigma(nSigma) - integer, intent(in) :: nSigma - character(*), intent(in) :: header, cfile - type(modelParam_t), intent(in) :: sigma(nSigma) + call writeVec_modelParam_binary(nSigma, sigma, header, cfile) end subroutine writeVec_modelParam diff --git a/f90/MPI/Main_MPI.f90 b/f90/MPI/Main_MPI.f90 index 08e01e66..7f48d1c2 100644 --- a/f90/MPI/Main_MPI.f90 +++ b/f90/MPI/Main_MPI.f90 @@ -2489,9 +2489,9 @@ Subroutine Worker_job(sigma,d) ! compute linearized data functional(s) : L !call Lrows(e0,sigma,dt,stn_index,L) ! 2022.10.06, Liu Zhongyin, Add Azimuth - call Lrows(e0,sigma,dt,stn_index,orient,L) + call Lrows(e0,sigma,dt,stn_index,d%d(per_index)%data(dt_index)%orient(stn_index),L) ! compute linearized data functional(s) : Q - call Qrows(e0,sigma,dt,stn_index,Qzero,Qreal,Qimag) + call Qrows(e0,sigma,dt,d%d(per_index)%data(dt_index)%rx(stn_index),Qzero,Qreal,Qimag) ! clean up the grid elements stored in GridCalc on the ! leader node call deall_rvector(l_E)