diff --git a/CHANGELOG.md b/CHANGELOG.md index f78f9db1..a2735045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `.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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c664032..a67f6b8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/app/cabledyn.f90 b/app/cabledyn.f90 index 3e2b9fb5..bac2d593 100644 --- a/app/cabledyn.f90 +++ b/app/cabledyn.f90 @@ -19,6 +19,7 @@ PROGRAM cabledyn !! exit code " (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 @@ -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 diff --git a/doc/outputs.rst b/doc/outputs.rst index 2bc94bca..3eac9688 100644 --- a/doc/outputs.rst +++ b/doc/outputs.rst @@ -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 @@ -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, ``(-)`` ``RodSub``; -* 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`` diff --git a/doc/tutorial_openfast.rst b/doc/tutorial_openfast.rst index 5345b99f..50c2e217 100644 --- a/doc/tutorial_openfast.rst +++ b/doc/tutorial_openfast.rst @@ -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: diff --git a/src/CableDyn_Conventions.f90 b/src/CableDyn_Conventions.f90 index 96102790..84778a80 100644 --- a/src/CableDyn_Conventions.f90 +++ b/src/CableDyn_Conventions.f90 @@ -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 @@ -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 .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 diff --git a/src/CableDyn_Driver.f90 b/src/CableDyn_Driver.f90 index 000c6fa8..a68c39a8 100644 --- a/src/CableDyn_Driver.f90 +++ b/src/CableDyn_Driver.f90 @@ -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) diff --git a/src/CableDyn_Modal.f90 b/src/CableDyn_Modal.f90 index 358870f3..2f1f0ac8 100644 --- a/src/CableDyn_Modal.f90 +++ b/src/CableDyn_Modal.f90 @@ -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 @@ -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 diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index c963a00b..e9a89d60 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -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, & @@ -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) @@ -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) diff --git a/src/openfast/CableDyn_OF_Driver.f90 b/src/openfast/CableDyn_OF_Driver.f90 index 9574b743..97ee9a91 100644 --- a/src/openfast/CableDyn_OF_Driver.f90 +++ b/src/openfast/CableDyn_OF_Driver.f90 @@ -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 @@ -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 diff --git a/tests/test_output_formats.f90 b/tests/test_output_formats.f90 new file mode 100644 index 00000000..d3466008 --- /dev/null +++ b/tests/test_output_formats.f90 @@ -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 .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