Skip to content

Commit

Permalink
Merge pull request #1435 from DLR-AMR/feature_conditioned-compilation
Browse files Browse the repository at this point in the history
Feature conditioned compilation for netcdf
  • Loading branch information
Davknapp authored Feb 27, 2025
2 parents 544c32f + 4bef227 commit 97adaf7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
9 changes: 6 additions & 3 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ add_t8_example( NAME t8_example_geometries SOURCES geometry/t8_exam
add_t8_example( NAME t8_cmesh_load_save SOURCES IO/cmesh/t8_cmesh_load_save.cxx )
add_t8_example( NAME t8_read_msh_file SOURCES IO/cmesh/gmsh/t8_read_msh_file.cxx )
add_t8_example( NAME t8_load_and_refine_square_w_hole SOURCES IO/cmesh/gmsh/t8_load_and_refine_square_w_hole.cxx )
add_t8_example( NAME t8_write_cmesh_netcdf SOURCES IO/cmesh/netcdf/t8_write_cmesh_netcdf.cxx )
add_t8_example( NAME t8_read_tetgen SOURCES IO/cmesh/tetgen/t8_read_tetgen_file.cxx )
add_t8_example( NAME t8_time_tetgen SOURCES IO/cmesh/tetgen/t8_time_tetgen_file.cxx )
add_t8_example( NAME t8_forest_tetgen SOURCES IO/cmesh/tetgen/t8_forest_from_tetgen.cxx )
add_t8_example( NAME t8_read_triangle SOURCES IO/cmesh/triangle/t8_read_triangle_file.cxx )
add_t8_example( NAME t8_cmesh_read_from_vtk SOURCES IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx )

add_t8_example( NAME t8_netcdf_compilation_status SOURCES IO/forest/netcdf/t8_netcdf_status.c )
add_t8_example( NAME t8_write_forest_netcdf SOURCES IO/forest/netcdf/t8_write_forest_netcdf.cxx )
if(T8CODE_ENABLE_NETCDF)
add_t8_example( NAME t8_write_cmesh_netcdf SOURCES IO/cmesh/netcdf/t8_write_cmesh_netcdf.cxx )
add_t8_example( NAME t8_netcdf_compilation_status SOURCES IO/forest/netcdf/t8_netcdf_status.c )
add_t8_example( NAME t8_write_forest_netcdf SOURCES IO/forest/netcdf/t8_write_forest_netcdf.cxx )
endif()

add_t8_example( NAME t8_gmsh_to_vtk SOURCES IO/forest/gmsh/t8_gmsh_to_vtk.cxx )

add_t8_example( NAME t8_example_spheres SOURCES remove/t8_example_spheres.cxx )
Expand Down
16 changes: 10 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ if( T8CODE_ENABLE_NETCDF )
target_compile_definitions(T8 PUBLIC
T8_WITH_NETCDF
$<$<AND:$<BOOL:${NETCDF_HAVE_NETCDF_PAR}>,$<BOOL:${T8CODE_ENABLE_MPI}>>:T8_WITH_NETCDF_PAR> )
target_sources( T8 PRIVATE
t8_netcdf.c
t8_cmesh/t8_cmesh_netcdf.c
t8_forest/t8_forest_netcdf.cxx
)
install( FILES
t8_cmesh_netcdf.h
t8_forest_netcdf.h
t8_netcdf.h
DESTINATION include)
endif()

set_target_properties( T8 PROPERTIES OUTPUT_NAME t8 )
Expand Down Expand Up @@ -88,7 +98,6 @@ target_sources( T8 PRIVATE
t8_eclass.c
t8_element_shape.c
t8_element.cxx
t8_netcdf.c
t8_refcount.c
t8_version.c
t8_vtk.c
Expand All @@ -98,7 +107,6 @@ target_sources( T8 PRIVATE
t8_cmesh/t8_cmesh_stash.c
t8_cmesh/t8_cmesh_vtk_reader.cxx
t8_cmesh/t8_cmesh_save.cxx
t8_cmesh/t8_cmesh_netcdf.c
t8_cmesh/t8_cmesh_trees.cxx
t8_cmesh/t8_cmesh_commit.cxx
t8_cmesh/t8_cmesh_partition.cxx
Expand All @@ -117,7 +125,6 @@ target_sources( T8 PRIVATE
t8_forest/t8_forest_ghost.cxx
t8_forest/t8_forest_iterate.cxx
t8_forest/t8_forest_balance.cxx
t8_forest/t8_forest_netcdf.cxx
t8_forest/t8_forest_search/t8_forest_search.cxx
t8_geometry/t8_geometry.cxx
t8_geometry/t8_geometry_helpers.c
Expand Down Expand Up @@ -184,17 +191,14 @@ install( FILES
t8.h
t8_cmesh.h
t8_cmesh.hxx
t8_cmesh_netcdf.h
t8_cmesh_readmshfile.h
t8_cmesh_tetgen.h
t8_cmesh_triangle.h
t8_cmesh_vtk_reader.hxx
t8_eclass.h
t8_element.h
t8_element_shape.h
t8_forest_netcdf.h
t8_mat.h
t8_netcdf.h
t8_refcount.h
t8_types/t8_vec.hxx
t8_version.h
Expand Down
16 changes: 1 addition & 15 deletions src/t8_netcdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ t8_netcdf_variable_t *
t8_netcdf_create_var (t8_netcdf_variable_type_t var_type, const char *var_name, const char *var_long_name,
const char *var_unit, sc_array_t *var_data)
{
#if T8_WITH_NETCDF
T8_ASSERT ((var_type == T8_NETCDF_INT && var_data->elem_size == 4)
|| (var_type == T8_NETCDF_INT64 && var_data->elem_size == 8)
|| (var_type == T8_NETCDF_DOUBLE && var_data->elem_size == 8));
Expand All @@ -39,39 +38,26 @@ t8_netcdf_create_var (t8_netcdf_variable_type_t var_type, const char *var_name,
netcdf_variable->variable_units = var_unit;
netcdf_variable->var_user_data = var_data;
return netcdf_variable;
#else
t8_global_errorf ("This version of t8code is not compiled with netCDF support.\n");
return NULL;
#endif
}

/* Create an extern NetCDF integer variable */
t8_netcdf_variable_t *
t8_netcdf_create_integer_var (const char *var_name, const char *var_long_name, const char *var_unit,
sc_array_t *var_data)
{
#if T8_WITH_NETCDF
t8_netcdf_variable_type_t var_type;
/* Check whether 32-bit (4-byte) integer or 64-bit integer data sholud be written */
var_type = (var_data->elem_size > 4) ? T8_NETCDF_INT64 : T8_NETCDF_INT;
return t8_netcdf_create_var (var_type, var_name, var_long_name, var_unit, var_data);
#else
t8_global_errorf ("This version of t8code is not compiled with netCDF support.\n");
return NULL;
#endif
}

/* Create an extern NetCDF double variable */
t8_netcdf_variable_t *
t8_netcdf_create_double_var (const char *var_name, const char *var_long_name, const char *var_unit,
sc_array_t *var_data)
{
#if T8_WITH_NETCDF

return t8_netcdf_create_var (T8_NETCDF_DOUBLE, var_name, var_long_name, var_unit, var_data);
#else
t8_global_errorf ("This version of t8code is not compiled with netCDF support.\n");
return NULL;
#endif
}

/* Free the memory of the allocated NetCDF variable */
Expand Down

0 comments on commit 97adaf7

Please sign in to comment.