Skip to content

Commit

Permalink
Merge branch 'develop' - v0.4.2 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
GPMueller committed Oct 8, 2019
2 parents 70ccca3 + d3beda7 commit 1ff49d9
Show file tree
Hide file tree
Showing 200 changed files with 3,079 additions and 1,648 deletions.
15 changes: 5 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
sudo: required
dist: xenial
language: cpp


Expand All @@ -21,24 +20,20 @@ matrix:
include:
# OSX, xcode 8
- os: osx
osx_image: xcode8
osx_image: xcode10
env: CMAKE_OPTIONS="-DOVF_BUILD_FORTRAN_BINDINGS=OFF" PYPI=true
# Linux, GCC 7
- os: linux
env: COMPILER_C=gcc-7 COMPILER_CXX=g++-7 COMPILER_FORTRAN=gfortran-7 CMAKE_OPTIONS="" PYPI=true
dist: bionic
env: COMPILER_C=gcc COMPILER_CXX=g++ COMPILER_FORTRAN=gfortran CMAKE_OPTIONS="" PYPI=true
compiler: g++
addons:
apt:
packages:
- g++-7
- gfortran-7
- ca-certificates
- python2.7
sources:
- sourceline: 'ppa:ubuntu-toolchain-r/test'
- sourceline: 'ppa:jonathonf/python-2.7'
- gfortran
# Linux, GCC 5
- os: linux
dist: xenial
env: COMPILER_C=gcc-5 COMPILER_CXX=g++-5 CMAKE_OPTIONS="-DOVF_BUILD_FORTRAN_BINDINGS=OFF" PYPI=false
compiler: g++
addons:
Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set( META_AUTHOR_MAINTAINER "Gideon Mueller" )
set( META_AUTHOR_EMAIL "g.mueller@fz-juelich.de" )
set( META_VERSION_MAJOR "0" )
set( META_VERSION_MINOR "4" )
set( META_VERSION_PATCH "1" )
set( META_VERSION_PATCH "2" )
set( META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}" )
#############################################

Expand Down Expand Up @@ -211,4 +211,5 @@ if( OVF_BUILD_TEST AND OVF_BUILD_FORTRAN_BINDINGS )
endif()


set(OVF_LIBRARIES ${PROJECT_NAME} PARENT_SCOPE)
set( OVF_LIBRARIES ${PROJECT_NAME} PARENT_SCOPE )
set( OVF_LIBRARIES ${PROJECT_NAME}_static PARENT_SCOPE )
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ which should tell you what the problem was
(`const char * ovf_latest_message(struct ovf_file *)` in the C API).

In C/C++ and Fortran, before writing a segment, make sure the `ovf_segment` you pass in is
initialized, i.e. you already called either `ovf_read_segment_header` or `ovf_segment_initialize`.
initialized, i.e. you already called either `ovf_read_segment_header` or `ovf_segment_create`.

### C/C++

Expand All @@ -36,14 +36,15 @@ Opening and closing:

Reading from a file:

- `struct ovf_segment *segment = ovf_segment_initialize()` to initialize a segment and get the pointer
- `struct ovf_segment *segment = ovf_segment_create()` to initialize a new segment and get the pointer
- `ovf_read_segment_header(myfile, index, segment)` to read the header into the segment struct
- create float data array of appropriate size...
- `ovf_read_segment_data_4(myfile, index, segment, data)` to read the segment data into your float array
- setting `segment->N` before reading allows partial reading of large data segments

Writing and appending to a file:

- `struct ovf_segment *segment = ovf_segment_initialize()` to initialize a segment and get the pointer
- `struct ovf_segment *segment = ovf_segment_create()` to initialize a new segment and get the pointer
- `segment->n_cells[0] = ...` etc to set data dimensions, title and description, etc.
- `ovf_write_segment_4(myfile, segment, data, OVF_FORMAT_TEXT)` to write a file containing the segment header and data
- `ovf_append_segment_4(myfile, segment, data, OVF_FORMAT_TEXT)` to append the segment header and data to the file
Expand Down Expand Up @@ -116,10 +117,21 @@ endif
For more information on how to generate modern Fortran bindings,
see also https://github.com/MRedies/Interfacing-Fortran


How to embed it into your project
---------------------------------

TODO...
If you are using CMake, it is as simple as cloning this into a subdirectory,
e.g. `thirdparty/ovf` and using it with `add_subdirectory`:

```
add_subdirectory( ${PROJECT_SOURCE_DIR}/thirdparty/ovf )
set( OVF_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/thirdparty/ovf/include )
target_include_directories( myproject PRIVATE ${OVF_INCLUDE_DIRS} )
target_link_libraries( myproject PUBLIC ${OVF_LIBRARIES_STATIC} )
```

If you're not using CMake, you may need to put in some manual work.


Build
Expand Down
18 changes: 9 additions & 9 deletions fortran/ovf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module ovf
integer, parameter :: OVF_ERROR = -2
integer, parameter :: OVF_INVALID = -3

integer, parameter :: OVF_FORMAT_BIN = -55
integer, parameter :: OVF_FORMAT_TEXT = -56
integer, parameter :: OVF_FORMAT_CSV = -57
integer, parameter :: OVF_FORMAT_BIN = 0
integer, parameter :: OVF_FORMAT_TEXT = 3
integer, parameter :: OVF_FORMAT_CSV = 4

type, bind(c) :: c_ovf_file
type(c_ptr) :: filename
Expand Down Expand Up @@ -275,18 +275,18 @@ subroutine initialize_segment(self)
implicit none
class(ovf_segment) :: self

type(c_ovf_segment), pointer :: c_segment
type(c_ovf_segment), pointer :: c_segment
type(c_ptr) :: c_segment_ptr

interface
function ovf_segment_initialize() &
bind ( C, name = "ovf_segment_initialize" )
function ovf_segment_create() &
bind ( C, name = "ovf_segment_create" )
use, intrinsic :: iso_c_binding
type(c_ptr) :: ovf_segment_initialize
end function ovf_segment_initialize
type(c_ptr) :: ovf_segment_create
end function ovf_segment_create
end interface

c_segment_ptr = ovf_segment_initialize()
c_segment_ptr = ovf_segment_create()
call c_f_pointer(c_segment_ptr, c_segment)

call fill_ovf_segment(c_segment, self)
Expand Down
4 changes: 2 additions & 2 deletions fortran/test/simple.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ program main
STOP 1
endif


! Write a file
call file%open_file("testfile_f.ovf")
segment%ValueDim = 3
segment%N_Cells = [ 2, 2, 1 ]
segment%N = product(segment%N_Cells)
segment%ValueDim = 3

allocate( array_4(3, segment%N) )
array_4 = 0
Expand All @@ -55,6 +54,7 @@ program main
! Append to a file
array_4(:,:) = 3*array_4(:,:)

segment%Title = "fortran append test"
success = file%append_segment(segment, array_4, OVF_FORMAT_TEXT)
if ( success == OVF_OK) then
write (*,*) "test append_segment succeeded."
Expand Down
16 changes: 13 additions & 3 deletions include/detail/parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ namespace parse
{
pegtl::memory_input<> in( file._state->file_contents[index], "" );
const auto p = err.positions.front();
std::string line = in.line_as_string(p);
std::string line = in.line_at(p);
file._state->message_latest = fmt::format(
"libovf segment_header: Expected an empty line or a line containing a keyword and a value!"
"Found the following line instead:\n\"{}\"", line);
Expand Down Expand Up @@ -232,6 +232,7 @@ namespace parse

if( file.version == 2 )
{
file._state->max_data_index = segment.N*segment.valuedim;
success = pegtl::parse< v2::segment_data, v2::ovf_segment_data_action >( in, file, segment, data );
file._state->current_line = 0;
file._state->current_column = 0;
Expand Down Expand Up @@ -276,8 +277,17 @@ namespace parse
}
catch( ... )
{
file._state->message_latest = "libovf segment_data: unknown exception";
return OVF_ERROR;
// Make sure it really never crashes
try
{
file._state->message_latest = "libovf segment_data: unknown exception";
return OVF_ERROR;
}
catch( ... )
{
std::cerr << "libovf segment_data: unrecoverable error" << '\n';
return OVF_ERROR;
}
}
}
}
Expand Down
Loading

0 comments on commit 1ff49d9

Please sign in to comment.