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

Write TPW variables into a new file every timestep #9

Merged
merged 1 commit into from
Feb 7, 2024
Merged
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
55 changes: 23 additions & 32 deletions sl_model_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ subroutine sl_solver_init(itersl, starttime, mali_iceload, mali_bedrock, mali_ma
lambda(:,:) = 0.0

! write the values (0.0) for the first timestep
open(unit = 201, file = trim(outputfolder)//'TPW', form = 'formatted', access = 'sequential', &
open(unit = 201, file = trim(outputfolder)//'TPW'//trim(numstr), form = 'formatted', access = 'sequential', &
& status = 'replace')
write(201,'(9ES19.8E2/,3ES19.8E2/,18ES19.8E2)') il(:,:), mm(:), lambda(:,:)
! write(unit_num,'(9ES19.8E2/,3ES19.8E2/,18ES19.8E2)') dil(:,:,1), dm(:,1), dlambda(:,:,1)
Expand Down Expand Up @@ -761,28 +761,19 @@ subroutine sl_solver(itersl, iter, dtime, starttime, mali_iceload, mali_mask, sl
call read_sl(beta0(:,:), 'beta', outputfolder, suffix=numstr)

if (tpw) then
! read in variables for the rotation signal
open(unit = 201, file = trim(outputfolder)//'TPW', form = 'formatted', access = 'sequential', &
& status = 'old')

! initialize empty arrays
oldlambda(:,:) = (0.0,0.0)
oldil(:,:) = 0.0
oldm(:) = 0.0

do n = 1, nfiles-1
! find the number of lines to skip to read in appropriate TPW components
if (n == 1) then
j = TIMEWINDOW(n)
else
j = TIMEWINDOW(n) - TIMEWINDOW(n-1) - 1
endif

!skip lines to read in the rotational components corresponding to timesteps within the TW
do m = 1, j
read(201,*) !skip line for il
read(201,*) !skip reading in mm
read(201,*) !skip reading in lambda
enddo
j = TIMEWINDOW(n)
write(numstr,'(I4)') j
numstr = trim(adjustl(numstr))
! read in variables for the rotation signal
open(unit = 201, file = trim(outputfolder)//'TPW'//trim(numstr), &
& form = 'formatted', access = 'sequential', status = 'old')

!read in TPW components - total rotational change from the beginning of simulation
read(201,'(9ES19.8E2)') ((il(i,j), i = 1,3), j = 1, 3)
Expand All @@ -802,8 +793,8 @@ subroutine sl_solver(itersl, iter, dtime, starttime, mali_iceload, mali_mask, sl
if (n == nfiles-1) then
deltalambda(:,:,nfiles-1) = lambda(:,:)
endif
close(201)
enddo
close(201)
endif !endif (TPW)

! find index of the previous timestep
Expand Down Expand Up @@ -1226,20 +1217,6 @@ subroutine sl_solver(itersl, iter, dtime, starttime, mali_iceload, mali_mask, sl
!-----------------------------------------------------------
write(unit_num,'(A,I4,A)') ' ', ninner, ' inner-loop iterations'

!HH: print out the number of iteration it takes for the inner convergence
open(unit = 201, file = trim(outputfolder)//'numiter', form = 'formatted', access ='sequential', &
& status = 'old', position='append')
write(201,'(I5)') ninner
close(201)

! Write out the converged rotation-related quantities
if (tpw) then
open(unit = 201, file = trim(outputfolder)//'TPW', form = 'formatted', access = 'sequential', &
& status = 'old', position='append')
write(201,'(9ES19.8E2/,3ES19.8E2/,18ES19.8E2)') il(:,:), mm(:), lambda(:,:)
close(201)
endif

if (calcRG) then ! For R calculations
if (nmelt == 0) then
rrlm(:,:) = (0.0,0.0)! No change on first timestep
Expand Down Expand Up @@ -1296,6 +1273,20 @@ subroutine sl_solver(itersl, iter, dtime, starttime, mali_iceload, mali_mask, sl
write(201,'(I4)') nmelt
close(201)

! number of iteration it takes for the inner convergence
open(unit = 201, file = trim(outputfolder)//'numiter', form = 'formatted', access ='sequential', &
& status = 'old', position='append')

Choose a reason for hiding this comment

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

Will this file have the same issue - that if a restart causes some time steps to be rerun there will be multiple copies of those lines? Maybe that doesn't matter much for this file but wanted to point it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@matthewhoffman
Yes - this file will have the same issue, along with other files like times as well. These two files won't affect the SLM calculation itself but affect post-processing if used. But those files are rarely used nor looked at. So maybe I can either just stop writing those into a file in the first place, or we just keep it as is for now and address this issue in a new PR. The new PR could be even on making all the I/O to happen in the netcdf-format (because it's been proven that the text-formatted files take up way too much space (as we've recently seen in my project directory on Chicoma), and the remaining issue will be automatically taken care of. What do you think?

Choose a reason for hiding this comment

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

I'm fine with that limitation with this file for now if you are. I don't imagine I will be looking at them, so if you don't think they are critical, that's ok with me.

write(201,'(I5)') ninner
close(201)

! converged rotation-related quantities
if (tpw) then
open(unit = 201, file = trim(outputfolder)//'TPW'//trim(numstr), form = 'formatted', &
& access = 'sequential', status = 'replace')
write(201,'(9ES19.8E2/,3ES19.8E2/,18ES19.8E2)') il(:,:), mm(:), lambda(:,:)
close(201)
endif

! topography at the current timestep
call write_sl(topoxy, 'tgrid', outputfolder, suffix=numstr)

Expand Down