Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,15 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
"MinSizeRel" "RelWithDebInfo")
endif()

# Treat warnings as errors if not on Windows
if(NOT ERT_WINDOWS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Wno-unknown-pragmas ")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wfatal-errors -Wall -Wno-unknown-pragmas -Wno-unused-result -Wno-unused-parameter"
)
# Treat warnings as errors if gcc
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif()
endif()

if(MSVC)
Expand Down
2 changes: 1 addition & 1 deletion applications/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(resdata-applications)

function(target_link_resdata target)
target_link_libraries(${target} resdata)
target_link_libraries(${target} resdata fmt::fmt)
if(SKBUILD)
set_target_properties(${target} PROPERTIES INSTALL_RPATH "$ORIGIN/../.libs")
endif()
Expand Down
9 changes: 4 additions & 5 deletions applications/resdata/rd_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ int main(int argc, char **argv) {
std::vector<std::string> filelist(argv + 1, argv + argc);
std::sort(filelist.begin(), filelist.end(), fname_cmp);

rd_kw_ptr seqnum_kw(nullptr, &rd_kw_free);
std::unique_ptr<rd::KW> seqnum_kw{nullptr};
ERT::FortIO target(target_file, std::ios_base::out, fmt_file);

if (target_type == FileType::UNIFIED_RESTART) {
int dummy;
seqnum_kw.reset(rd_kw_alloc_new("SEQNUM", 1, RD_INT, &dummy));
seqnum_kw = std::make_unique<rd::KW>("SEQNUM", 1, RD_INT);
}

int prev_report_step = -1;
Expand All @@ -97,8 +96,8 @@ int main(int argc, char **argv) {
rd::File::open(filelist.at(i));
if (target_type == FileType::UNIFIED_RESTART) {
/* Must insert the SEQNUM keyword first. */
rd_kw_iset_int(seqnum_kw.get(), 0, report_step);
rd_kw_fwrite(seqnum_kw.get(), target);
seqnum_kw->at<int>(0) = report_step;
seqnum_kw->fwrite(target);
}
src_file->write(target, 0);
} /* Else skipping file of incorrect type. */
Expand Down
4 changes: 2 additions & 2 deletions applications/resdata/rd_unpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ static void unpack_file(const fs::path &filepath) {
report_step += 1;
offset = 0;
} else {
rd_kw_type *seqnum_kw;
rd::KW *seqnum_kw;
active_view = src_file->blockview(SEQNUM_KW, block_index);
seqnum_kw = active_view->get_kw(SEQNUM_KW, 0);
report_step = rd_kw_iget_int(seqnum_kw, 0);
report_step = seqnum_kw->at<int>(0);
offset = 1;
}

Expand Down
12 changes: 5 additions & 7 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ add_executable(
target_compile_features(rd_test_suite PUBLIC cxx_std_17)
target_include_directories(rd_test_suite
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include)
target_link_libraries(rd_test_suite resdata Catch2::Catch2)
target_link_libraries(rd_test_suite resdata fmt::fmt Catch2::Catch2)
add_test(NAME rd_test_suite COMMAND rd_test_suite)

foreach(
Expand Down Expand Up @@ -317,8 +317,6 @@ foreach(
rd_grid_init_fwrite
rd_grid_reset_actnum
rd_kw_space_pad
rd_kw_cmp_string
rd_kw_equal
rd_kw_fread
rd_kw_init
rd_layer
Expand All @@ -336,7 +334,7 @@ foreach(
well_segment_collection
test_rd_file)
add_executable(${name} resdata/tests/${name}.cpp util/test_util.cpp)
target_link_libraries(${name} resdata)
target_link_libraries(${name} resdata fmt::fmt)
target_include_directories(
${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include)
add_test(NAME ${name} COMMAND ${name})
Expand All @@ -361,9 +359,9 @@ add_test(
${CMAKE_CURRENT_SOURCE_DIR}/resdata/tests/data/num_cpu4
${CMAKE_CURRENT_SOURCE_DIR}/resdata/tests/data/num_cpu5)

foreach(test rdxx_kw rdxx_types)
foreach(test rdxx_types)
add_executable(${test} resdata/tests/${test}.cpp util/test_util.cpp)
target_link_libraries(${test} resdata)
target_link_libraries(${test} resdata fmt::fmt)
add_test(NAME ${test} COMMAND ${test})
endforeach()

Expand Down Expand Up @@ -395,7 +393,7 @@ foreach(
well_lgr_load)

add_executable(${name} resdata/tests/${name}.cpp util/test_util.cpp)
target_link_libraries(${name} resdata)
target_link_libraries(${name} resdata fmt::fmt)
target_include_directories(
${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include)
endforeach()
Expand Down
1 change: 0 additions & 1 deletion lib/include/ert/util/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ bool util_copy_file__(const char *src_file, const char *target_file,
char *util_alloc_cwd(void);
char *util_alloc_realpath(const char *);
char *util_alloc_realpath__(const char *input_path);
bool util_ftruncate(FILE *stream, long size);

int util_roundf(float x);
int util_round(double x);
Expand Down
21 changes: 12 additions & 9 deletions lib/include/resdata/FortIO.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

#include <cstdint>
#include <ios>
#include <istream>
#include <ostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cstdio>
Expand Down Expand Up @@ -46,8 +50,6 @@ class FortIO {
FortIO() = delete;
FortIO(const std::string &filename, std::ios_base::openmode mode,
bool fmt_file = false, bool endian_flip_header = RD_ENDIAN_FLIP);
FortIO(const std::string &filename, bool fmt_file, bool writable,
FILE *stream, bool endian_flip_header = RD_ENDIAN_FLIP);
~FortIO();

FortIO(FortIO &&other) noexcept;
Expand All @@ -67,18 +69,20 @@ class FortIO {
int fskip_record();
bool fread_buffer(char *buffer, int buffer_size);
void fwrite_record(const char *buffer, int buffer_size);
[[nodiscard]] FILE *get_FILE() const;
[[nodiscard]] std::istream &get_istream();
[[nodiscard]] std::ostream &get_ostream();
void fflush() const;
void rewind() const;
[[nodiscard]] const char *filename_ref() const;
[[nodiscard]] const std::string &filename() const { return m_filename; };
[[nodiscard]] bool fmt_file() const;
[[nodiscard]] offset_type ftell() const;
bool fseek(offset_type offset, int whence);
bool data_fskip(int element_size, int element_count, int block_count);
bool data_fskip(size_t element_size, size_t element_count,
size_t block_count);
void data_fseek(offset_type data_offset, size_t data_element,
size_t element_size, int element_count, int block_size);
bool ftruncate(offset_type size);
size_t element_size, int element_count, size_t block_size);
bool ftruncate(std::uintmax_t size);
int fclean();
bool fclose_stream();
bool fopen_stream();
Expand All @@ -90,12 +94,11 @@ class FortIO {
private:
bool fseek_(offset_type offset, int whence);

FILE *m_stream = nullptr;
mutable std::fstream m_stream;
std::string m_filename;
bool m_endian_flip_header = false;
bool m_fmt_file = false;
const char *m_fopen_mode = nullptr;
bool m_stream_owner = false;
std::ios_base::openmode m_open_mode = std::ios_base::openmode{};

/*
The internal variable m_read_size is used in the functions fseek() and
Expand Down
Loading
Loading