-
Notifications
You must be signed in to change notification settings - Fork 53
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
Adding datetime in rpointer file with backward compatibility #486
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -811,29 +811,41 @@ SUBROUTINE restFile_read_pfile( pnamer ) | |
USE RtmFileUtils, ONLY: relavu, getavu, opnfil | ||
USE RtmVar, ONLY: inst_suffix | ||
USE public_var, ONLY: rpntfil | ||
USE globalData, ONLY: simDatetime | ||
|
||
implicit none | ||
! Arguments: | ||
character(len=*), intent(out) :: pnamer ! full path of restart file | ||
! Local variables: | ||
integer :: i ! indices | ||
integer :: nio ! restart unit | ||
integer :: status ! substring check status | ||
character(len=256) :: locfn ! Restart pointer file name | ||
integer :: i ! indices | ||
integer :: nio ! restart unit | ||
integer :: sec_in_day ! time in second | ||
character(len=17) :: timestamp ! datetime string in yyyy-mm-dd-sssss | ||
integer :: status ! substring check status | ||
character(len=256) :: locfn ! Restart pointer file name | ||
!-------------------------------------------------------- | ||
|
||
if (masterproc) then | ||
write(iulog,*) 'Reading restart pointer file....' | ||
endif | ||
|
||
nio = getavu() | ||
locfn = './'// trim(rpntfil)//trim(inst_suffix) | ||
nio = getavu() ! get available unit number | ||
|
||
! construct rpoint file name with datetime - simDatetime has three datetime at previous(0), current(1) and next(2) time stamp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change rpoint to rpointer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
sec_in_day = simDatetime(1)%hour()*60*60+simDatetime(1)%minute()*60+nint(simDatetime(1)%sec()) | ||
write(timestamp,'(".",I4.4,"-",I2.2,"-",I2.2,"-",I5.5)') & | ||
simDatetime(1)%year(),simDatetime(1)%month(),simDatetime(1)%day(),sec_in_day | ||
locfn = './'// trim(rpntfil)//trim(inst_suffix)//timestamp | ||
inquire (file=locfn,exist=lexist) | ||
if (.not. lexist) then ! backward compatibility - rpointer file w/o datetime | ||
locfn = './'// trim(rpntfil)//trim(inst_suffix) | ||
end if | ||
call opnfil (locfn, nio, 'f') | ||
read (nio,'(a256)') pnamer | ||
call relavu (nio) | ||
|
||
if (masterproc) then | ||
write(iulog,*) 'Reading restart data.....' | ||
write(iulog,*) 'Reading restart data: ', trim(pnamer) | ||
write(iulog,'(72a1)') ("-",i=1,60) | ||
end if | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ MODULE io_rpointfile | |
USE globalData, ONLY: masterproc | ||
USE globalData, ONLY: hfileout, hfileout_gage | ||
USE globalData, ONLY: rfileout | ||
USE datetime_data, ONLY: datetime ! datetime data class | ||
|
||
implicit none | ||
|
||
|
@@ -18,20 +19,33 @@ MODULE io_rpointfile | |
! ********************************************************************* | ||
! public subroutine: main routine to define new output file | ||
! ********************************************************************* | ||
SUBROUTINE io_rpfile(mode, ierr, message) | ||
SUBROUTINE io_rpfile(mode, ierr, message, curDatetime) | ||
|
||
implicit none | ||
! argument variables | ||
character(1), intent(in) :: mode ! io mode: 'r' or 'w' | ||
integer(i4b), intent(out) :: ierr ! error code | ||
character(*), intent(out) :: message ! error message | ||
character(1), intent(in) :: mode ! io mode: 'r' or 'w' | ||
integer(i4b), intent(out) :: ierr ! error code | ||
character(*), intent(out) :: message ! error message | ||
type(datetime), intent(in), optional :: curDatetime ! current datetime | ||
integer :: sec_in_day ! time in second | ||
character(len=17) :: timestamp ! datetime string in yyyy-mm-dd-sssss | ||
character(len=strLen) :: rpntfil_path ! rpointer file path | ||
|
||
ierr=0; message='io_rpfile/' | ||
|
||
if (present(curDatetime)) then | ||
sec_in_day = curDatetime%hour()*60*60+curDatetime%minute()*60+nint(curDatetime%sec()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change 60*60 to nint(secphour) and 60 to nint(secpmin) in public_vars There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
write(timestamp,'(".",I4.4,"-",I2.2,"-",I2.2,"-",I5.5)') & | ||
curDatetime%year(),curDatetime%month(),curDatetime%day(),sec_in_day | ||
rpntfil_path = trim(restart_dir)//trim(rpntfil)//timestamp | ||
else | ||
rpntfil_path = trim(restart_dir)//trim(rpntfil) | ||
end if | ||
|
||
select case(mode) | ||
case("w") | ||
if (masterproc) then | ||
open(1, file = trim(restart_dir)//trim(rpntfil), status='replace', action='write') | ||
open(1, file = trim(rpntfil_path), status='replace', action='write') | ||
write(1,'(a)') trim(rfileout) | ||
write(1,'(a)') trim(hfileout) | ||
if (outputAtGage) then | ||
|
@@ -40,7 +54,7 @@ SUBROUTINE io_rpfile(mode, ierr, message) | |
close(1) | ||
end if | ||
case("r") | ||
open(1, file = trim(restart_dir)//trim(rpntfil), status='old', action='read') | ||
open(1, file = trim(rpntfil_path), status='old', action='read') | ||
read(1, '(A)') rfileout | ||
read(1, '(A)') hfileout | ||
if (outputAtGage) then | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, that new FORTRAN constructs allow you to NOT need getavu() anymore. There's a way to open a file with an available unit.
This would be a good modernization effort to do. But, not completely required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only thing in RtmFileUtils that is maybe useful is opnfil, but the use of getavu and relavu could be removed and handled within opnfil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for suggestions on ascii file handling (#490). I will clean this up with another PR. This RtmFileUtils and ascii_utils could be merged and several routines (getavu and relavu, getSpareUnit) can be removed.