Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add keyname option for model rotation #37

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.10)

# set the project name
set(CMAKE_PROJECT_NAME "SurfATT")
project(${CMAKE_PROJECT_NAME} VERSION 1.5.0 LANGUAGES Fortran CXX)
project(${CMAKE_PROJECT_NAME} VERSION 1.5.1 LANGUAGES Fortran CXX)

# set the version number and git commit hash
execute_process(
Expand All @@ -12,8 +12,6 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)

message(${GIT_COMMIT_HASH})

configure_file(
${PROJECT_SOURCE_DIR}/include/version.h.in
${PROJECT_SOURCE_DIR}/include/version.h
Expand Down
3 changes: 3 additions & 0 deletions examples/04_hawaii_topo/run_this_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ gmt grdcut @earth_relief_01m -R-157/-152/18/21 -Ghawaii.nc
# inversion
mpirun -np $NPROC ../../bin/surfatt_tomo -i input_params.yml

# rotate initial model
../../bin/surfatt_rotate_model -i OUTPUT_FILES/model_iter.h5 -a `echo $angle | awk '{print -$1}'` -c $pos_str -o OUTPUT_FILES/initial_model.csv -k vs_000

# rotate back to original position
../../bin/surfatt_rotate_model -i OUTPUT_FILES/final_model.h5 -a `echo $angle | awk '{print -$1}'` -c $pos_str -o OUTPUT_FILES/final_model.csv
10 changes: 8 additions & 2 deletions src/shared/argparse.f90
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,15 @@ subroutine argparse_rotate_topo(fname, xrange, yrange, angle, center, outfname)

end subroutine argparse_rotate_topo

subroutine argparse_rotate_model(fname, angle, center, outfname)
subroutine argparse_rotate_model(fname, angle, center, outfname, keyname)
use ieee_arithmetic
character(len=MAX_STRING_LEN),dimension(:), allocatable :: args
character(len=MAX_STRING_LEN) :: arg, value
character(len=MAX_STRING_LEN),intent(out) :: fname, outfname
character(len=MAX_NAME_LEN),intent(out) :: keyname
real(kind=dp), intent(out) :: angle, center(2)
real(kind=dp) :: nan
integer :: i,nargs,m,ier,nopt=4
integer :: i,nargs,m,ier,nopt=5

nargs = command_argument_count()
allocate(args(nargs))
Expand All @@ -266,6 +267,7 @@ subroutine argparse_rotate_model(fname, angle, center, outfname)
angle = 0.
nan = ieee_value(nan, ieee_quiet_nan)
center = [nan, nan]
keyname = 'vs'
if (nargs==0 .or. any(args == '-h')) then
write(*,*)'Usage: surfatt_rotate_model -i model_file -a angle -c clat/clon -o out_model_file' // &
' [-h]'
Expand All @@ -282,6 +284,7 @@ subroutine argparse_rotate_model(fname, angle, center, outfname)
write(*,*)' -a angle Angle in degree to rotate model'
write(*,*)' -c clat/clon Center of rotation in latitude and longitude'
write(*,*)' -h Print help message'
write(*,*)' -k keyname Key name of the variable to rotate, defaults to "vs"'
endif
m = 0
do i = 1, nargs
Expand All @@ -301,6 +304,9 @@ subroutine argparse_rotate_model(fname, angle, center, outfname)
elseif (arg(1:2) == '-o') then
m = m+1
outfname = args(i+1)
elseif (arg(1:2) == '-k') then
m = m+1
keyname = args(i+1)
endif
enddo
if (m<1) then
Expand Down
5 changes: 3 additions & 2 deletions src/surfatt_rotate_model.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ program rotate_model
implicit none

character(len=MAX_STRING_LEN) :: input_file, output_file
character(len=MAX_NAME_LEN) :: keyname
real(kind=dp) :: angle, center(2)
real(kind=dp), dimension(:), allocatable :: lon, lat, dep, new_lat, new_lon
real(kind=dp), dimension(:,:,:), allocatable :: vs3d
Expand All @@ -31,14 +32,14 @@ program rotate_model
logical :: status_ok
integer :: i, j, k, nx, ny, nz

call argparse_rotate_model(input_file, angle, center, output_file)
call argparse_rotate_model(input_file, angle, center, output_file, keyname)

! Read the input file
call hf%open(input_file)
call hf%get('/lon', lon)
call hf%get('/lat', lat)
call hf%get('/dep', dep)
call hf%get('/vs', vs3d)
call hf%get('/'//trim(keyname), vs3d)
call hf%close()
vs3d = transpose_3(vs3d)

Expand Down