Skip to content

Commit

Permalink
C and Fortran string variable values
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfgc committed Feb 1, 2019
1 parent baaaf89 commit abc822a
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 69 deletions.
41 changes: 37 additions & 4 deletions bindings/C/c/adios2_c_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ adios2_error adios2_put(adios2_engine *engine, adios2_variable *variable,
{
// not supported
}
else if (type == "string")
{
const std::string dataStr(reinterpret_cast<const char *>(data));
adios2::core::Engine &engineCpp =
*reinterpret_cast<adios2::core::Engine *>(engine);

engineCpp.Put(*dynamic_cast<adios2::core::Variable<std::string> *>(
variableBase),
dataStr);
}
#define declare_template_instantiation(T) \
else if (type == adios2::helper::GetType<T>()) \
{ \
Expand All @@ -168,7 +178,7 @@ adios2_error adios2_put(adios2_engine *engine, adios2_variable *variable,
*dynamic_cast<adios2::core::Variable<T> *>(variableBase), \
reinterpret_cast<const T *>(data), modeCpp); \
}
ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation

return adios2_error_none;
Expand Down Expand Up @@ -205,13 +215,18 @@ adios2_error adios2_put_by_name(adios2_engine *engine,
{
// not supported
}
else if (type == "string")
{
const std::string dataStr(reinterpret_cast<const char *>(data));
engineCpp.Put(variable_name, dataStr);
}
#define declare_template_instantiation(T) \
else if (type == adios2::helper::GetType<T>()) \
{ \
engineCpp.Put(variable_name, reinterpret_cast<const T *>(data), \
modeCpp); \
}
ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
return adios2_error_none;
}
Expand Down Expand Up @@ -252,12 +267,24 @@ adios2_error adios2_get(adios2_engine *engine, adios2_variable *variable,

adios2::core::VariableBase *variableBase =
reinterpret_cast<adios2::core::VariableBase *>(variable);

const std::string type(variableBase->m_Type);

if (type == "compound")
{
// not supported
}
else if (type == "string")
{
adios2::core::Engine &engineCpp =
*reinterpret_cast<adios2::core::Engine *>(engine);

std::string dataStr;
engineCpp.Get(*dynamic_cast<adios2::core::Variable<std::string> *>(
variableBase),
dataStr);
dataStr.copy(reinterpret_cast<char *>(values), dataStr.size());
}
#define declare_template_instantiation(T) \
else if (type == adios2::helper::GetType<T>()) \
{ \
Expand All @@ -270,7 +297,7 @@ adios2_error adios2_get(adios2_engine *engine, adios2_variable *variable,
*dynamic_cast<adios2::core::Variable<T> *>(variableBase), \
reinterpret_cast<T *>(values), modeCpp); \
}
ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
return adios2_error_none;
}
Expand Down Expand Up @@ -304,12 +331,18 @@ adios2_error adios2_get_by_name(adios2_engine *engine,
{
// not supported
}
else if (type == "string")
{
std::string dataStr;
engineCpp.Get(variable_name, dataStr);
dataStr.copy(reinterpret_cast<char *>(data), dataStr.size());
}
#define declare_template_instantiation(T) \
else if (type == adios2::helper::GetType<T>()) \
{ \
engineCpp.Get(variable_name, reinterpret_cast<T *>(data), modeCpp); \
}
ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
return adios2_error_none;
}
Expand Down
4 changes: 4 additions & 0 deletions bindings/Fortran/modules/adios2_engine_get_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module adios2_engine_get_mod
interface adios2_get

! Single Value
module procedure adios2_get_string
module procedure adios2_get_real
module procedure adios2_get_dp
module procedure adios2_get_complex
Expand Down Expand Up @@ -87,6 +88,7 @@ module adios2_engine_get_mod
module procedure adios2_get_integer8_6d

! Single Value
module procedure adios2_get_by_name_string
module procedure adios2_get_by_name_real
module procedure adios2_get_by_name_dp
module procedure adios2_get_by_name_complex
Expand Down Expand Up @@ -157,6 +159,7 @@ module adios2_engine_get_mod
module procedure adios2_get_by_name_integer8_6d

! Single Value
module procedure adios2_get_deferred_string
module procedure adios2_get_deferred_real
module procedure adios2_get_deferred_dp
module procedure adios2_get_deferred_complex
Expand Down Expand Up @@ -228,6 +231,7 @@ module adios2_engine_get_mod

! Deferred Signature
! Single Value
module procedure adios2_get_deferred_by_name_string
module procedure adios2_get_deferred_by_name_real
module procedure adios2_get_deferred_by_name_dp
module procedure adios2_get_deferred_by_name_complex
Expand Down
4 changes: 4 additions & 0 deletions bindings/Fortran/modules/adios2_engine_put_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module adios2_engine_put_mod
interface adios2_put

! Single Value
module procedure adios2_put_string
module procedure adios2_put_real
module procedure adios2_put_dp
module procedure adios2_put_complex
Expand Down Expand Up @@ -87,6 +88,7 @@ module adios2_engine_put_mod
module procedure adios2_put_integer8_6d

! Single Value
module procedure adios2_put_by_name_string
module procedure adios2_put_by_name_real
module procedure adios2_put_by_name_dp
module procedure adios2_put_by_name_complex
Expand Down Expand Up @@ -157,6 +159,7 @@ module adios2_engine_put_mod
module procedure adios2_put_by_name_integer8_6d

! Single Value
module procedure adios2_put_deferred_string
module procedure adios2_put_deferred_real
module procedure adios2_put_deferred_dp
module procedure adios2_put_deferred_complex
Expand Down Expand Up @@ -228,6 +231,7 @@ module adios2_engine_put_mod

! Deferred Signature
! Single Value
module procedure adios2_put_deferred_by_name_string
module procedure adios2_put_deferred_by_name_real
module procedure adios2_put_deferred_by_name_dp
module procedure adios2_put_deferred_by_name_complex
Expand Down
15 changes: 15 additions & 0 deletions bindings/Fortran/modules/contains/adios2_engine_get.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
!

! Single data
subroutine adios2_get_string(engine, variable, data, launch, ierr)
type(adios2_engine), intent(in):: engine
type(adios2_variable), intent(in):: variable
character*(*), intent(out):: data
integer, intent(in):: launch
integer, intent(out):: ierr

call adios2_variable_check_type(variable, adios2_type_string, &
'get string', ierr)
if (ierr == 0) then
call adios2_get_f2c(engine%f2c, variable%f2c, data, launch, ierr)
end if

end subroutine

subroutine adios2_get_real(engine, variable, data, launch, ierr)
type(adios2_engine), intent(in):: engine
type(adios2_variable), intent(in):: variable
Expand Down
15 changes: 13 additions & 2 deletions bindings/Fortran/modules/contains/adios2_engine_get_by_name.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@
!

! Single values
subroutine adios2_get_by_name_real(engine, name, data, &
launch, ierr)
subroutine adios2_get_by_name_string(engine, name, data, launch, ierr)
type(adios2_engine), intent(in):: engine
character*(*), intent(in) :: name
character*(*), intent(out):: data
integer, intent(in):: launch
integer, intent(out):: ierr

call adios2_get_by_name_f2c(engine%f2c, TRIM(ADJUSTL(name))//char(0), &
data, launch, ierr)

end subroutine

subroutine adios2_get_by_name_real(engine, name, data, launch, ierr)
type(adios2_engine), intent(in):: engine
character*(*), intent(in) :: name
real, intent(out):: data
Expand Down
15 changes: 15 additions & 0 deletions bindings/Fortran/modules/contains/adios2_engine_get_deferred.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
!

! Single data
subroutine adios2_get_deferred_string(engine, variable, data, ierr)
type(adios2_engine), intent(in):: engine
type(adios2_variable), intent(in):: variable
character*(*), intent(out):: data
integer, intent(out):: ierr

call adios2_variable_check_type(variable, adios2_type_string, &
'get string', ierr)
if (ierr == 0) then
call adios2_get_f2c(engine%f2c, variable%f2c, data, adios2_mode_sync, &
ierr)
end if

end subroutine

subroutine adios2_get_deferred_real(engine, variable, data, ierr)
type(adios2_engine), intent(in):: engine
type(adios2_variable), intent(in):: variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
!

! Single Value
subroutine adios2_get_deferred_by_name_string(engine, name, data, ierr)
type(adios2_engine), intent(in):: engine
character*(*), intent(in) :: name
character*(*), intent(out):: data
integer, intent(out):: ierr

call adios2_get_by_name_f2c(engine%f2c, TRIM(ADJUSTL(name))//char(0), &
data, adios2_mode_sync, ierr)

end subroutine

subroutine adios2_get_deferred_by_name_real(engine, name, data, ierr)
type(adios2_engine), intent(in):: engine
character*(*), intent(in) :: name
Expand Down
16 changes: 16 additions & 0 deletions bindings/Fortran/modules/contains/adios2_engine_put.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
!

! Single data
subroutine adios2_put_string(engine, variable, data, launch, ierr)
type(adios2_engine), intent(in):: engine
type(adios2_variable), intent(in):: variable
character*(*), intent(in):: data
integer, intent(in):: launch
integer, intent(out):: ierr

call adios2_variable_check_type(variable, adios2_type_string, &
'put string', ierr)
if (ierr == 0) then
call adios2_put_f2c(engine%f2c, variable%f2c, &
TRIM(ADJUSTL(data))//char(0), launch, ierr)
end if

end subroutine

subroutine adios2_put_real(engine, variable, data, launch, ierr)
type(adios2_engine), intent(in):: engine
type(adios2_variable), intent(in):: variable
Expand Down
18 changes: 14 additions & 4 deletions bindings/Fortran/modules/contains/adios2_engine_put_by_name.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@
!

! Single values
subroutine adios2_put_by_name_real(engine, name, data, &
launch, ierr)
subroutine adios2_put_by_name_string(engine, name, data, launch, ierr)
type(adios2_engine), intent(in):: engine
character*(*), intent(in) :: name
character*(*), intent(in) :: data
integer, intent(in):: launch
integer, intent(out):: ierr

call adios2_put_by_name_f2c(engine%f2c, TRIM(ADJUSTL(name))//char(0), &
TRIM(ADJUSTL(data))//char(0), launch, ierr)

end subroutine

subroutine adios2_put_by_name_real(engine, name, data, launch, ierr)
type(adios2_engine), intent(in):: engine
character*(*), intent(in) :: name
real, intent(in):: data
integer, intent(in):: launch
integer, intent(out):: ierr

call adios2_put_by_name_f2c(engine%f2c, &
TRIM(ADJUSTL(name))//char(0), &
call adios2_put_by_name_f2c(engine%f2c, TRIM(ADJUSTL(name))//char(0), &
data, launch, ierr)

end subroutine
Expand Down
16 changes: 16 additions & 0 deletions bindings/Fortran/modules/contains/adios2_engine_put_deferred.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
!

! Single data
subroutine adios2_put_deferred_string(engine, variable, data, ierr)
type(adios2_engine), intent(in):: engine
type(adios2_variable), intent(in):: variable
character*(*), intent(in):: data
integer, intent(out):: ierr

call adios2_variable_check_type(variable, adios2_type_string, &
'put string', ierr)
if (ierr == 0) then
call adios2_put_f2c(engine%f2c, variable%f2c, &
TRIM(ADJUSTL(data))//char(0), adios2_mode_sync, &
ierr)
end if

end subroutine

subroutine adios2_put_deferred_real(engine, variable, data, ierr)
type(adios2_engine), intent(in):: engine
type(adios2_variable), intent(in):: variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
!

! Single Value
subroutine adios2_put_deferred_by_name_string(engine, name, data, ierr)
type(adios2_engine), intent(in):: engine
character*(*), intent(in) :: name
character*(*), intent(in):: data
integer, intent(out):: ierr

call adios2_put_by_name_f2c(engine%f2c, TRIM(ADJUSTL(name))//char(0), &
TRIM(ADJUSTL(data))//char(0), &
adios2_mode_deferred, ierr)

end subroutine


subroutine adios2_put_deferred_by_name_real(engine, name, data, ierr)
type(adios2_engine), intent(in):: engine
character*(*), intent(in) :: name
Expand Down
2 changes: 2 additions & 0 deletions testing/adios2/bindings/C/SmallTestData_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <stdint.h>

const char dataStr[] = "A string variable";

size_t data_Nx = 10;

int8_t data_I8[10] = {0, 1, -2, 3, -4, 5, -6, 7, -8, 9};
Expand Down
Loading

0 comments on commit abc822a

Please sign in to comment.