Skip to content
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ All notable changes to CableDyn are recorded in this file. The format follows
read 0. The floor now takes only the part pressing into it along its normal, and on a
frictional seabed the along-floor part of the end node's weight up to the friction it can
hold; flat seabeds are unchanged.
- OpenFAST's native `<root>.CD.out` wrote a channel value below 1e-99 or from 1e100 on as a
field of asterisks (`ES15.6E2`): the round-off noise of a zero component, such as the y
position or tangent azimuth of a line in the x-z plane, broke every reader. Channel values now
have a three-digit exponent (`ES15.6E3`, same width). The mixed `EI = 0` + finite-EI `.out`,
the modal results, the static driver's mesh file and the OpenFAST module driver, which wrote
such values without the exponent letter, do too.

## [0.3.0] - 2026-10-23

Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,11 @@ target_link_libraries(test_hfmf_mirror PRIVATE cabledyn_core)
add_test(NAME hfmf_mirror COMMAND test_hfmf_mirror WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_tests_properties(hfmf_mirror PROPERTIES LABELS "fortran;unit;dynamic;openfast")

add_executable(test_output_formats tests/test_output_formats.f90)
target_link_libraries(test_output_formats PRIVATE cabledyn_core)
add_test(NAME output_formats COMMAND test_output_formats)
set_tests_properties(output_formats PROPERTIES LABELS "fortran;unit;output")

add_executable(test_c_api tests/test_c_api.f90)
target_link_libraries(test_c_api PRIVATE cabledyn_core)
add_test(NAME c_api COMMAND test_c_api)
Expand Down
3 changes: 2 additions & 1 deletion app/cabledyn.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ PROGRAM cabledyn
!! exit code <n>" (stop_run); an interrupt or a fatal fault is reported by
!! CableDyn_FatalReport with the simulated time reached.
USE CableDyn_Precision, ONLY: wp, CD_ZERO
USE CableDyn_Conventions, ONLY: CD_CHANNEL_FMT
USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_Deck_Query_dtM, &
CD_Classify_Dynamic_Completion, CD_DECKDRV_OK, &
CD_DECKDRV_BADINPUT, CD_DECKDRV_SOLVEFAIL, CD_DECK_PATHLEN
Expand Down Expand Up @@ -803,7 +804,7 @@ SUBROUTINE write_mixed_row(unit, time, aggregate, stat, msg)
DO i = 1, CD_AGG_NumChannels(aggregate)
CALL CD_AGG_EvalChannel(aggregate, i, value, stat, msg)
IF (stat /= CD_AGG_OK) RETURN
WRITE (unit, '(A,ES15.7)', ADVANCE='NO', IOSTAT=ios) CHAR(9), value
WRITE (unit, CD_CHANNEL_FMT, ADVANCE='NO', IOSTAT=ios) CHAR(9), value
IF (ios /= 0) THEN
stat = CD_AGG_BADINPUT; msg = 'cannot write mixed output row'; RETURN
END IF
Expand Down
8 changes: 4 additions & 4 deletions doc/outputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ All standalone files are plain ASCII tables:
three-digit exponent, e.g. `` 1.2500000000000000E+001``) so that time stamps survive long
runs with small ``dtM`` without rounding;
* every other real value is Fortran ``ES15.7E3`` (15 characters, 8 significant digits, e.g.
`` 5.0988032E+005``, three-digit exponent). The one exception is the channel columns of the
mixed ``EI = 0`` + finite-EI route's ``.out``, written as ``ES15.7`` (the same 8 significant
digits with a two-digit exponent, e.g. `` 5.0988032E+05``);
`` 5.0988032E+005``, three-digit exponent, so round-off noise below 1e-99 in a component that
is zero still prints as a number);
* integer key columns (``LineID``, ``Node``, ``Element``, ``Segment``) are written without
padding (``I0``);
* a non-finite channel value is never written: a dynamic row that would contain ``NaN`` or
Expand Down Expand Up @@ -946,7 +945,8 @@ output root:
``(deg)`` angles, ``(m)`` positions, ``(m/s)`` velocities, ``(m/s2)`` accelerations,
``(deg/s)`` / ``(deg/s2)`` body and rod angular rates, ``(1/m)`` curvature, ``(N.m)`` bend
moment and body/rod moments, ``(-)`` ``Rod<N>Sub``;
* data rows: time as ``ES25.16E3`` (full double precision), values as ``ES15.6E2``, TAB-separated.
* data rows: time as ``ES25.16E3`` (full double precision), values as ``ES15.6E3`` (7 significant
digits, three-digit exponent), TAB-separated.

The first data row is the static initialisation at ``t = 0``; every further row is written after
each committed CableDyn step, at every ``dtM`` boundary. It is independent of OpenFAST's ``DT_Out``
Expand Down
8 changes: 4 additions & 4 deletions doc/tutorial_openfast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ Check, in order:

.. code-block:: text

Time FairTen1 AnchTen1 FairIncl1 AnchIncl1 FairTen2 ...
(s) (N) (N) (deg) (deg) (N) ...
0.0000000E+00 2.437520E+06 1.351636E+06 5.568478E+01 -1.961023E-02 2.436576E+06 ...
2.5000000E-02 2.438082E+06 1.351645E+06 5.568463E+01 -1.961023E-02 2.435530E+06 ...
Time FairTen1 AnchTen1 FairIncl1 AnchIncl1 FairTen2 ...
(s) (N) (N) (deg) (deg) (N) ...
0.0000000000000000E+000 2.437520E+006 1.351636E+006 5.568478E+001 -1.961023E-002 2.436576E+006 ...
2.5000000000000001E-002 2.438082E+006 1.351645E+006 5.568463E+001 -1.961023E-002 2.435530E+006 ...

CableDyn channels are chosen in the deck's ``OUTPUTS`` section (keep its closing ``END``), not in
the ``.fst`` ``OutList``. Channel names and units: :doc:`outputs`; sign and angle conventions:
Expand Down
11 changes: 11 additions & 0 deletions src/CableDyn_Conventions.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ MODULE CableDyn_Conventions
!! (azimuth / declination / gamma) [deg] -> R in SO(3).
!! - CD_Body_Rotation : 6D-body attitude, intrinsic x-y'-z''
!! (rotation1 / 2 / 3) [deg] -> R in SO(3).
!! - CD_CHANNEL_FMT, CD_NATIVE_CHANNEL_FMT : the channel-value formats of the
!! time-series files (three-digit exponent).
!!
!! These are the OrcaFlex 11.5 conventions (frames right-handed, GZ up; azimuth
!! +GX->+GY; declination from +GZ). The two Euler sequences are deliberately
Expand All @@ -24,6 +26,15 @@ MODULE CableDyn_Conventions
PRIVATE
PUBLIC :: CD_Direction_Vector, CD_LineEnd_Rotation, CD_Body_Rotation
PUBLIC :: CD_Deg2Rad, CD_Rad2Deg
PUBLIC :: CD_CHANNEL_FMT, CD_NATIVE_CHANNEL_FMT

! One TAB-separated channel value of a time-series row: the standalone .out files (8
! significant digits) and OpenFAST's native <root>.CD.out (7). The exponent field has three
! digits: with two, a magnitude below 1e-99 or at 1e100 and above (the round-off noise of a
! component that is zero, such as the y position of a line in the x-z plane) fills the field
! with asterisks, and without a stated width the exponent letter is dropped.
CHARACTER(*), PARAMETER :: CD_CHANNEL_FMT = '(A,ES15.7E3)'
CHARACTER(*), PARAMETER :: CD_NATIVE_CHANNEL_FMT = '(A,ES15.6E3)'

REAL(wp), PARAMETER :: CD_PI = 3.14159265358979323846_wp
REAL(wp), PARAMETER :: CD_RAD_PER_DEG = CD_PI/180.0_wp
Expand Down
4 changes: 2 additions & 2 deletions src/CableDyn_Driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -756,11 +756,11 @@ SUBROUTINE write_csv(path, q, conn, tension, converged, stalled, at_floor, n_ite
' stalled=', stalled, ' at_floor=', at_floor
WRITE (unit, '(A)') 'section,node,x,y,z'
DO i = 1, n_nodes
WRITE (unit, '(A,I0,3(A,ES23.15))') 'node,', i, ',', q(3*i - 2), ',', q(3*i - 1), ',', q(3*i)
WRITE (unit, '(A,I0,3(A,ES23.15E3))') 'node,', i, ',', q(3*i - 2), ',', q(3*i - 1), ',', q(3*i)
END DO
WRITE (unit, '(A)') 'section,elem,node_a,node_b,tension_N'
DO i = 1, n_elem
WRITE (unit, '(A,I0,2(A,I0),A,ES23.15)') 'elem,', i, ',', conn(1, i), ',', conn(2, i), &
WRITE (unit, '(A,I0,2(A,I0),A,ES23.15E3)') 'elem,', i, ',', conn(1, i), ',', conn(2, i), &
',', tension(i)
END DO
CLOSE (unit)
Expand Down
4 changes: 2 additions & 2 deletions src/CableDyn_Modal.f90
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ SUBROUTINE CD_Modal_Write_Line(unit, line_id, q, dof_per_node, omega2, shapes, n
fr = om/TWO_PI
per = CD_ZERO
IF (om > CD_ZERO) per = CD_ONE/fr
WRITE (unit, '(I0,A,I0,3(A,ES16.8))') line_id, TB, j, TB, fr, TB, per, TB, om
WRITE (unit, '(I0,A,I0,3(A,ES16.8E3))') line_id, TB, j, TB, fr, TB, per, TB, om
ELSE
dmax = CD_ZERO
DO i = 1, nn
Expand All @@ -770,7 +770,7 @@ SUBROUTINE CD_Modal_Write_Line(unit, line_id, q, dof_per_node, omega2, shapes, n
IF (dmax > CD_ZERO) scl = CD_ONE/dmax
DO i = 1, nn
i0 = dof_per_node*(i - 1)
WRITE (unit, '(I0,A,I0,A,I0,6(A,ES16.8))') line_id, TB, j, TB, i, TB, q(i0 + 1), TB, q(i0 + 2), TB, &
WRITE (unit, '(I0,A,I0,A,I0,6(A,ES16.8E3))') line_id, TB, j, TB, i, TB, q(i0 + 1), TB, q(i0 + 2), TB, &
q(i0 + 3), TB, scl*shapes(i0 + 1, j), TB, scl*shapes(i0 + 2, j), TB, scl*shapes(i0 + 3, j)
END DO
END IF
Expand Down
5 changes: 3 additions & 2 deletions src/openfast/CableDyn_OF.f90
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ MODULE CableDyn
USE CableDyn_Types
USE NWTC_Library
USE CableDyn_Precision, ONLY: wp
USE CableDyn_Conventions, ONLY: CD_NATIVE_CHANNEL_FMT
USE CableDyn_Hydro, ONLY: CD_Current_Profile_Velocity, CD_SeaState_Steady_Current, CD_HYDRO_OK
USE CableDyn_DeckDriver, ONLY: CD_Deck_Query_dtM, CD_DECKDRV_OK
USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_UpdateStates_Moving, &
Expand Down Expand Up @@ -362,7 +363,7 @@ SUBROUTINE open_native_outputs( id, root, t_start, ErrStat, ErrMsg, write_profil
ErrStat, ErrMsg, RoutineName )
RETURN
END IF
WRITE (un, '(A,ES15.6E2)', ADVANCE='NO') CHAR(9), value
WRITE (un, CD_NATIVE_CHANNEL_FMT, ADVANCE='NO') CHAR(9), value
END DO
WRITE (un, '(A)') ''
FLUSH (un)
Expand Down Expand Up @@ -2425,7 +2426,7 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg )
CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: committed-step channel record: '//TRIM(em), &
ErrStat, ErrMsg, RoutineName ); RETURN
END IF
WRITE (Inst(id)%native_un, '(A,ES15.6E2)', ADVANCE='NO') CHAR(9), cval
WRITE (Inst(id)%native_un, CD_NATIVE_CHANNEL_FMT, ADVANCE='NO') CHAR(9), cval
END DO
WRITE (Inst(id)%native_un, '(A)') ''
! keep the record readable during the run (and intact after a crash)
Expand Down
3 changes: 2 additions & 1 deletion src/openfast/CableDyn_OF_Driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ PROGRAM CableDyn_OF_Driver
USE NWTC_Library
USE CableDyn_Types
USE CableDyn, ONLY: CD_Init, CD_UpdateStates, CD_CalcOutput, CD_End
USE CableDyn_Conventions, ONLY: CD_NATIVE_CHANNEL_FMT
USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_IS_FINITE
IMPLICIT NONE

Expand Down Expand Up @@ -165,7 +166,7 @@ PROGRAM CableDyn_OF_Driver
IF (.NOT. ALL(IEEE_IS_FINITE(y%CoupledLoads(1)%Moment))) CALL fail_out('non-finite coupled moment')
WRITE (un_out, '(F12.4)', ADVANCE='NO') t + dtc
DO ic = 1, nch
WRITE (un_out, '(A,ES15.6)', ADVANCE='NO') TAB, y%WriteOutput(ic)
WRITE (un_out, CD_NATIVE_CHANNEL_FMT, ADVANCE='NO') TAB, y%WriteOutput(ic)
END DO
WRITE (un_out, '()')
END DO
Expand Down
84 changes: 84 additions & 0 deletions tests/test_output_formats.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
! File: tests/test_output_formats.f90
! SPDX-License-Identifier: Apache-2.0
! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University
PROGRAM test_output_formats
!! Gate for the channel-value formats of the time-series files (CD_CHANNEL_FMT, the
!! standalone .out files; CD_NATIVE_CHANNEL_FMT, OpenFAST's native <root>.CD.out). Every
!! value a channel can carry must print as a number any reader parses: no field of
!! asterisks (a two-digit exponent overflows below 1e-99 and from 1e100, the round-off
!! noise of a zero component such as the y position of a line in the x-z plane), and the
!! exponent letter kept (an unstated exponent width drops it at three digits, which
!! Python's float() rejects). Each field is TAB plus mantissa, 'E', sign and three
!! digits, and reads back to its printed precision (zero exactly).
USE CableDyn_Precision, ONLY: wp
USE CableDyn_Conventions, ONLY: CD_CHANNEL_FMT, CD_NATIVE_CHANNEL_FMT
IMPLICIT NONE
REAL(wp), PARAMETER :: VALUES(13) = [0.0_wp, 1.0e-120_wp, -3.0e150_wp, 9.99999949e-100_wp, -1.0e-99_wp, &
1.0e100_wp, -9.9999999e99_wp, 1.0e-310_wp, 5.0988032e5_wp, &
-1.961023e-2_wp, 1.0_wp, HUGE(1.0_wp), -TINY(1.0_wp)]
INTEGER :: nfail, i

nfail = 0
DO i = 1, SIZE(VALUES)
CALL check(CD_CHANNEL_FMT, 'standalone', VALUES(i), 15, 5.0e-8_wp)
CALL check(CD_NATIVE_CHANNEL_FMT, 'native', VALUES(i), 15, 5.0e-7_wp)
END DO
IF (nfail > 0) THEN
WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed'
ERROR STOP 1
END IF
WRITE (*, '(A)') 'PASS: channel-value formats print every magnitude as a parseable number'

CONTAINS

SUBROUTINE check(fmt, label, x, width, rel)
!! Write TAB + x with fmt, then check the field's shape and its read-back value.
CHARACTER(*), INTENT(IN) :: fmt, label
REAL(wp), INTENT(IN) :: x, rel
INTEGER, INTENT(IN) :: width
CHARACTER(64) :: buf
CHARACTER(:), ALLOCATABLE :: field
REAL(wp) :: y
INTEGER :: ios, ie, n
CHARACTER(32) :: shown

WRITE (shown, '(ES24.16E3)') x
WRITE (buf, fmt, IOSTAT=ios) CHAR(9), x
IF (ios /= 0) THEN
CALL fail(label//' write failed for '//TRIM(shown)); RETURN
END IF
n = LEN_TRIM(buf)
IF (buf(1:1) /= CHAR(9) .OR. n /= width + 1) THEN
CALL fail(label//' field is not TAB plus a fixed width for '//TRIM(shown)//': "'//TRIM(buf)//'"'); RETURN
END IF
field = TRIM(ADJUSTL(buf(2:n)))
IF (INDEX(field, '*') > 0) THEN
CALL fail(label//' field overflows for '//TRIM(shown)//': "'//field//'"'); RETURN
END IF
! mantissa, then E, a sign and exactly three exponent digits at the end of the field
ie = INDEX(field, 'E', BACK=.TRUE.)
IF (ie == 0 .OR. ie /= LEN(field) - 4) THEN
CALL fail(label//' field lacks a three-digit E exponent for '//TRIM(shown)//': "'//field//'"'); RETURN
END IF
IF (VERIFY(field(ie + 1:ie + 1), '+-') /= 0 .OR. VERIFY(field(ie + 2:), '0123456789') /= 0) THEN
CALL fail(label//' exponent is not a sign and three digits for '//TRIM(shown)//': "'//field//'"'); RETURN
END IF
READ (field, *, IOSTAT=ios) y
IF (ios /= 0) THEN
CALL fail(label//' field does not read back for '//TRIM(shown)//': "'//field//'"'); RETURN
END IF
! ABS(.) >= 0, so "not > 0" tests an exact zero without a REAL equality compare
IF (.NOT. (ABS(x) > 0.0_wp)) THEN
IF (ABS(y) > 0.0_wp) CALL fail(label//' zero does not read back as zero: "'//field//'"')
ELSE IF (ABS(y - x) > rel*ABS(x)) THEN
CALL fail(label//' value does not round-trip for '//TRIM(shown)//': "'//field//'"')
END IF
END SUBROUTINE check

SUBROUTINE fail(msg)
CHARACTER(*), INTENT(IN) :: msg
WRITE (*, '(A)') 'MISMATCH: '//msg
nfail = nfail + 1
END SUBROUTINE fail

END PROGRAM test_output_formats
Loading