Skip to content
Merged
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
99 changes: 51 additions & 48 deletions modules/subdyn/src/SubDyn_Output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -604,59 +604,67 @@ SUBROUTINE SDOut_OpenOutput( ProgVer, OutRootName, p, InitOut, ErrStat, ErrMsg
CHARACTER(1024) :: OutFileName ! The name of the output file including the full path.
CHARACTER(200) :: Frmt ! a string to hold a format statement
INTEGER :: ErrStat2

ErrStat = ErrID_None
ErrMsg = ""
! Open the output file, if necessary, and write the header
IF ( ALLOCATED( p%OutParam ) .AND. p%NumOuts > 0 ) THEN ! Output has been requested so let's open an output file
! Open the file for output
OutFileName = TRIM(OutRootName)//'.out'
CALL GetNewUnit( p%UnJckF )

! Initialize to -1 to indicate that the output file unit is not valid
p%UnJckF = -1

! No outputs requested, so just return
if ((.not. allocated(p%OutParam)) .or. (p%NumOuts == 0)) then
call WrScr('SubDyn: no outputs were requested, so separate output file will not be generated.')
return
end if

CALL OpenFOutFile ( p%UnJckF, OutFileName, ErrStat, ErrMsg )
IF ( ErrStat >= AbortErrLev ) THEN
ErrMsg = ' Error opening SubDyn-level output file: '//TRIM(ErrMsg)
RETURN
END IF

! Write the output file header
WRITE (p%UnJckF,'(/,A/)', IOSTAT=ErrStat2) 'These predictions were generated by '//TRIM(GETNVD(ProgVer))//&
' on '//CurDate()//' at '//CurTime()//'.'

WRITE(p%UnJckF, '(//)') ! add 3 lines to make file format consistant with FAST v8 (headers on line 7; units on line 8) [this allows easier post-processing]

! Write the names of the output parameters:
Frmt = '(A8,'//TRIM(Int2LStr(p%NumOuts+p%OutAllInt*p%OutAllDims))//'(:,A,'//TRIM( p%OutSFmt )//'))'
WRITE(p%UnJckF,Frmt, IOSTAT=ErrStat2) TRIM( 'Time' ), ( p%Delim, TRIM( InitOut%WriteOutputHdr(I) ), I=1,p%NumOuts+p%OutAllInt*p%OutAllDims )
! Open the file for output
OutFileName = TRIM(OutRootName)//'.out'
call GetNewUnit( p%UnJckF )

call OpenFOutFile ( p%UnJckF, OutFileName, ErrStat, ErrMsg )
if (ErrStat >= AbortErrLev) then
ErrMsg = ' Error opening SubDyn-level output file: '//TRIM(ErrMsg)
return
end if

! Write the units of the output parameters:
WRITE(p%UnJckF,Frmt, IOSTAT=ErrStat2) TRIM( 's'), ( p%Delim, TRIM( InitOut%WriteOutputUnt(I) ), I=1,p%NumOuts+p%OutAllInt*p%OutAllDims )
END IF ! there are any requested outputs
! Write the output file header
write(p%UnJckF,'(/,A/)', IOSTAT=ErrStat2) 'These predictions were generated by '//TRIM(GETNVD(ProgVer))//&
' on '//CurDate()//' at '//CurTime()//'.'

write(p%UnJckF, '(//)') ! add 3 lines to make file format consistant with FAST v8 (headers on line 7; units on line 8) [this allows easier post-processing]

! Write the names of the output parameters:
Frmt = '(A8,'//TRIM(Int2LStr(p%NumOuts+p%OutAllInt*p%OutAllDims))//'(:,A,'//TRIM( p%OutSFmt )//'))'
write(p%UnJckF,Frmt, IOSTAT=ErrStat2) TRIM( 'Time' ), ( p%Delim, TRIM( InitOut%WriteOutputHdr(I) ), I=1,p%NumOuts+p%OutAllInt*p%OutAllDims )

! Write the units of the output parameters:
write(p%UnJckF,Frmt, IOSTAT=ErrStat2) TRIM( 's'), ( p%Delim, TRIM( InitOut%WriteOutputUnt(I) ), I=1,p%NumOuts+p%OutAllInt*p%OutAllDims )
END SUBROUTINE SDOut_OpenOutput

!====================================================================================================


!====================================================================================================
SUBROUTINE SDOut_CloseOutput ( p, ErrStat, ErrMsg )
! This function cleans up after running the SubDyn output module. It closes the output file,
! releases memory, and resets the number of outputs requested to 0.
! SDOut_CloseOutput closes the output file, if open, after running the SubDyn output module.
!----------------------------------------------------------------------------------------------------
TYPE(SD_ParameterType), INTENT( INOUT ) :: p ! data for this instance of the floating platform module
INTEGER, INTENT( OUT ) :: ErrStat ! a non-zero value indicates an error occurred
CHARACTER(*), INTENT( OUT ) :: ErrMsg ! Error message if ErrStat /= ErrID_None
LOGICAL :: Err
SUBROUTINE SDOut_CloseOutput ( p, ErrStat, ErrMsg )
type(SD_ParameterType), INTENT( INOUT ) :: p ! data for this instance of the floating platform module
integer(IntKi), INTENT( OUT ) :: ErrStat ! a non-zero value indicates an error occurred
character(*), INTENT( OUT ) :: ErrMsg ! Error message if ErrStat /= ErrID_None
integer(IntKi) :: Stat

ErrStat = 0
ErrStat = ErrID_None
ErrMsg = ""
Err = .FALSE.

! If file is not open, return
if (p%UnJckF == -1) return

! Close our output file
CLOSE( p%UnJckF, IOSTAT = ErrStat )
IF ( ErrStat /= 0 ) Err = .TRUE.

! Make sure ErrStat is non-zero if an error occurred
IF ( Err ) ErrStat = ErrID_Fatal
RETURN
close(p%UnJckF, iostat=Stat)
if (Stat /= 0) then
ErrStat = ErrID_Fatal
ErrMsg = ' Problem closing SubDyn output file.'
end if

END SUBROUTINE SDOut_CloseOutput
!====================================================================================================
Expand Down Expand Up @@ -712,19 +720,14 @@ SUBROUTINE SDOut_WriteOutputs( UnJckF, Time, SDWrOutput, p, ErrStat, ErrMsg )
! Local variables
INTEGER :: I ! Generic loop counter
CHARACTER(200) :: Frmt ! a string to hold a format statement

ErrStat = ErrID_None
ErrMsg = ""

! Initialize ErrStat and determine if it makes any sense to write output
IF ( .NOT. ALLOCATED( p%OutParam ) .OR. UnJckF < 0 ) THEN
ErrStat = ErrID_Fatal
ErrMsg = ' To write outputs for SubDyn there must be a valid file ID and OutParam must be allocated.'
RETURN
ELSE
ErrStat = ErrID_None
END IF

! Write the output parameters to the file
! If output file is not open, return
if (p%UnJckF == -1) return

! Write the output parameters to the file
Frmt = '(F10.4,'//TRIM(Int2LStr(p%NumOuts+p%OutAllInt*p%OutAllDims))//'(:,A,'//TRIM( p%OutFmt )//'))'

WRITE(UnJckF,Frmt) Time, ( p%Delim, SDWrOutput(I), I=1,p%NumOuts+p%OutAllInt*p%OutAllDims )
Expand Down