Skip to content
Snippets Groups Projects
Commit d4866128 authored by Debolskiy Andrey's avatar Debolskiy Andrey :bicyclist_tone5:
Browse files

added plt io prototype

parent fcabb130
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 3.15)
project(scm_io)
set(CMAKE_CXX_STANDARD 14)
include_directories(src)
enable_language(Fortran)
set(dialect " -free -fimplicit-none ")
set(bounds "-free -fimplicit-none ")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds} -g -fbacktrace -O0 -fcheck=all")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}")
set(plt_io
src/scm_io_plt.f90
src/test_io_plt.f90)
add_executable(test_plt ${plt_io})
! Created by Andrey Debolskiy on 21.05.2024.
module scm_io_plt
implicit none
!type declaration
type io_struct
character(len = 160) :: fname
integer :: status ! 0 - closed, 1 - opened
integer :: unit_id
end type io_struct
character(len = 160) tmp_str
integer, public :: nunits_max
public
contains
subroutine set_file( f, fname )
implicit none
type(io_struct), intent(inout):: f
character(*), intent(in):: fname
if (f%status == 0) then
f%unit_id = get_file_unit()
open(f%unit_id, FILE=trim(fname))
f%status = 1
f%fname = trim(fname)
end if
end subroutine set_file
subroutine write_series(stamp, vals, nlength, f)
implicit none
type(io_struct), intent(inout):: f
integer, intent(in):: nlength
real, intent(in), dimension(nlength)::vals
real, intent(in):: stamp
write(f%unit_id,*) stamp, vals(:)
end subroutine write_series
subroutine write_profile(profs, nprof, z, nz, f)
implicit none
type(io_struct), intent(inout):: f
integer, intent(in):: nprof, nz
real, intent(in), dimension(nz, nprof):: profs
real, intent(in), dimension(nz):: z
integer k, n
if (f%status==1) then
do k = 1,nz
write(f%unit_id,*) z(k), profs(k,:)
end do
else
write(*,*) "Error in writing file:"
write(*,*) " ", f%fname
stop
end if
end subroutine write_profile
subroutine close_file(f)
implicit none
type(io_struct), intent(inout):: f
close(f%unit_id)
f%status = 0
end subroutine close_file
! get_file_unit returns a unit number that is not in use
integer function get_file_unit ()
integer lu, iostat
integer, save:: m
logical, save:: initialized = .true.
logical opened
if (initialized) then
m = nunits_max
initialized = .false.
end if
if (m < 8 ) then
m = 2 * nunits_max
end if
do lu = m,7,-1
inquire (unit=lu, opened=opened, iostat=iostat)
if (iostat.ne.0) cycle
if (.not.opened) exit
end do
!
get_file_unit = lu
return
end function get_file_unit
end module scm_io_plt
\ No newline at end of file
! Created by Andrey Debolskiy on 21.05.2024.
program test_io_plt
use scm_io_plt
implicit none
integer, parameter :: nvar=5, nlength=10
!io variables
real, dimension (nvar):: series_val
type (io_struct) :: series_f
!local vars
integer nt, n
real t
!set output filenames
series_f%fname = 'test_io.plt'
call set_file(series_f, series_f%fname)
do nt=1,nlength
t = nt/100.0
do n=1,nvar
series_val(n)= 0.1 * n
end do
call write_series(t, series_val, nvar, series_f)
end do
call close_file(series_f)
end program test_io_plt
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment