Skip to content

Commit

Permalink
writer.f90: writer_template
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jul 29, 2020
1 parent aef5bf7 commit 6b758dd
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 261 deletions.
33 changes: 31 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,40 @@ if (check_error(ier, dname)) then
error stop
endif
")

configure_file(reader.in.f90 reader.f90)

set(writer_template "
integer :: varid, dimids(rank(value)), ier
call self%def_dims(dname, dims, shape(value), dimids, ier)
select type (value)
type is (real(real64))
if(ier == NF90_NOERR) ier = nf90_def_var(self%ncid, dname, NF90_DOUBLE, dimids=dimids, varid=varid)
if(ier == NF90_NOERR) ier = nf90_put_var(self%ncid, varid, value)
type is (real(real32))
if(ier == NF90_NOERR) ier = nf90_def_var(self%ncid, dname, NF90_FLOAT, dimids=dimids, varid=varid)
if(ier == NF90_NOERR) ier = nf90_put_var(self%ncid, varid, value)
type is (integer(int64))
if(ier == NF90_NOERR) ier = nf90_def_var(self%ncid, dname, NF90_INT64, dimids=dimids, varid=varid)
if(ier == NF90_NOERR) ier = nf90_put_var(self%ncid, varid, value)
type is (integer(int32))
if(ier == NF90_NOERR) ier = nf90_def_var(self%ncid, dname, NF90_INT, dimids=dimids, varid=varid)
if(ier == NF90_NOERR) ier = nf90_put_var(self%ncid, varid, value)
class default
ierr = NF90_EBADTYPE
end select
if (present(ierr)) ierr = ier
if (check_error(ier, dname)) then
if (present(ierr)) return
error stop
endif
")
configure_file(writer.in.f90 writer.f90)

target_sources(nc4fortran PRIVATE
interface.f90
read.f90 ${CMAKE_CURRENT_BINARY_DIR}/reader.f90
write.f90 writer.f90
write.f90 ${CMAKE_CURRENT_BINARY_DIR}/writer.f90
string_utils.f90 ${CMAKE_CURRENT_BINARY_DIR}/pathlib.f90)
41 changes: 38 additions & 3 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,50 @@ if (check_error(ier, dname)) then
if (present(ierr)) return
error stop
endif
'''
)
''')
configure_file(
input : 'reader.in.f90',
output : 'reader.f90',
configuration : reader_template
)

writer_template = configuration_data()
writer_template.set('writer_template',
'''
integer :: varid, dimids(rank(value)), ier
call self%def_dims(dname, dims, shape(value), dimids, ier)
select type (value)
type is (real(real64))
if(ier == NF90_NOERR) ier = nf90_def_var(self%ncid, dname, NF90_DOUBLE, dimids=dimids, varid=varid)
if(ier == NF90_NOERR) ier = nf90_put_var(self%ncid, varid, value)
type is (real(real32))
if(ier == NF90_NOERR) ier = nf90_def_var(self%ncid, dname, NF90_FLOAT, dimids=dimids, varid=varid)
if(ier == NF90_NOERR) ier = nf90_put_var(self%ncid, varid, value)
type is (integer(int64))
if(ier == NF90_NOERR) ier = nf90_def_var(self%ncid, dname, NF90_INT64, dimids=dimids, varid=varid)
if(ier == NF90_NOERR) ier = nf90_put_var(self%ncid, varid, value)
type is (integer(int32))
if(ier == NF90_NOERR) ier = nf90_def_var(self%ncid, dname, NF90_INT, dimids=dimids, varid=varid)
if(ier == NF90_NOERR) ier = nf90_put_var(self%ncid, varid, value)
class default
ierr = NF90_EBADTYPE
end select
if (present(ierr)) ierr = ier
if (check_error(ier, dname)) then
if (present(ierr)) return
error stop
endif
''')
configure_file(
input : 'writer.in.f90',
output : 'writer.f90',
configuration : writer_template
)

nc4_src = files('interface.f90',
'read.f90', meson.current_build_dir() / 'reader.f90',
'write.f90', 'writer.f90',
'write.f90', meson.current_build_dir() / 'writer.f90',
'string_utils.f90', meson.current_build_dir() / 'pathlib.f90')
256 changes: 0 additions & 256 deletions src/writer.f90

This file was deleted.

Loading

0 comments on commit 6b758dd

Please sign in to comment.