-
Notifications
You must be signed in to change notification settings - Fork 5
/
io.f90
67 lines (53 loc) · 2.1 KB
/
io.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
!
! Copyright (C) 2013, Northwestern University
! See COPYRIGHT notice in top-level directory.
!
!----< write_savefile >------------------------------------------
subroutine write_savefile
! writes data file for post-processing and restarting
use mpi
use runtime_m, only: time, time_ref, run_title
use io_profiling_m, only: dir_path
use pnetcdf_m, only: pnetcdf_write
implicit none
! local variables
character*10 time_ext
character*256 filename
! set file extension string
write(time_ext,'(1pe10.3)') time*time_ref
! set file name
filename = trim(dir_path)//'/'//trim(run_title)//'.'// &
trim(adjustl(time_ext))//'.field.nc'
! call PnetCDF APIs to write data to file
call pnetcdf_write(filename)
end subroutine write_savefile
!----< read_savefile >-------------------------------------------
subroutine read_savefile
! reads restart file
use mpi
use runtime_m, only: time, time_ref, run_title
use io_profiling_m, only: dir_path
use pnetcdf_m, only: pnetcdf_read
use topology_m, only : myid
implicit none
! local variables
character*10 time_ext
character*256 filename
logical exist
! set file extension strings
write(time_ext,'(1pe10.3)') time*time_ref
! set file name
filename = trim(dir_path)//'/'//trim(run_title)//'.'// &
trim(adjustl(time_ext))//'.field.nc'
! inquire about file existence
inquire(file=trim(filename),exist=exist)
if (.NOT. exist) then
if (myid .EQ. 0) then
print*, 'restart file does not exist ', trim(filename)
print*, 'skip reading restart files'
endif
return
endif
! call PnetCDF APIs to read data from file
call pnetcdf_read(filename)
end subroutine read_savefile