Comments (3)
Agreed. Similar failures can happen under other circumstances. Been a long time since I had to look at this layer - really should not have any hardcoded lengths at all. (Early days allocatable strings were sometimes wonky and I had to use workarounds.)
Just back from a long bit of travel, so might be a week or more before I can dive into this. But if you see a fix already, feel free to submit a PR (onto develop
branch please).
from pfunit.
It's difficult to work out the required length of the allocatable string to represent the real data in advance. There are two slightly hacky workarounds that I can think of immediately:
- Use a local fixed length string of excessive size, write to this and use
len_trim
to determine the actual size required to use to allocate strings. Questionable if there's much advantage to copying out from the excessive size into the allocatable character. - Attempt to allocate the string to a reasonable size, use the
eor
option towrite
to detect if the string is insufficient in size and reallocate to a larger string.
The second would look something like
character(len=:), allocatable :: string
integer :: length
length = 8
10 length = length * 2
if (allocated(string)) deallocate(string)
allocate(character(len=length) :: string)
write(string, '(g0)', eor = 10) e
Edit: My mistake eor
is only applicable to read
, not write
. One can still do something similar, although it's even uglier
use iso_fortran_env, only: iostat_eor
character(len=:), allocatable :: string
integer :: length, iostat
length = 8
iostat = iostat_eor
do while(iostat == iostat_eor)
length = length * 2
if (allocated(string)) deallocate(string)
allocate(character(len=length) :: string)
write(string, '(g0)', iostat = iostat) e
end do
Note this then hides/ignores any other error condition which arises and one may need additional handling of iostat
to check success or otherwise.
from pfunit.
Yeah. I've done something similar to this in my logging package where one really has no idea in advance of the size of the strings, as even the format is a run-time entity.
from pfunit.
Related Issues (20)
- Feature Request: Misnamed Test Module Diagnostic HOT 3
- CMake Feature Request: Recompile *_driver.F90 when new TEST_SOURCES added HOT 3
- Feature Request: @assertEquals for string arrays HOT 3
- Error installing pFUnit on WSL(Ubuntu-20.04.5) HOT 11
- compiling on NAS HOT 9
- Fortran compilation error
- Error in opening compiled module files HOT 4
- Incorrect CMake logic for MPIEXEC
- Memory leak when using the @disable macro HOT 5
- CMake error when "-- Performing Test _LOGICAL_DEFAULT_KIND" during setup; missing ./cmake/Trial_sources directory under ./extern/fArgParse/extern/gFTL-shared/extern/gFTL HOT 3
- pFUnit silently fails on Actions HOT 8
- Relative TEST_SOURCES paths in `add_pfunit_ctest` HOT 2
- bug in ctest macro HOT 1
- Intel LLVM 2023.2.x msan issue
- Typo in release v4.7.4 HOT 2
- Using `funitproc` with `MpiTestCase` - Can this work? HOT 4
- Remove outdated documentation HOT 1
- Missing implementation of assertIsFinite_real80 in src/funit/asserts/AssertBasic.F90 HOT 6
- Fails to build with cmake>=3.27 + Ninja HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pfunit.