Skip to content

Commit 5eec526

Browse files
committed
Don't write to SubDyn output file if no outputs requested.
1 parent 216a72e commit 5eec526

File tree

1 file changed

+51
-48
lines changed

1 file changed

+51
-48
lines changed

modules/subdyn/src/SubDyn_Output.f90

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -604,59 +604,67 @@ SUBROUTINE SDOut_OpenOutput( ProgVer, OutRootName, p, InitOut, ErrStat, ErrMsg
604604
CHARACTER(1024) :: OutFileName ! The name of the output file including the full path.
605605
CHARACTER(200) :: Frmt ! a string to hold a format statement
606606
INTEGER :: ErrStat2
607+
607608
ErrStat = ErrID_None
608609
ErrMsg = ""
609-
! Open the output file, if necessary, and write the header
610-
IF ( ALLOCATED( p%OutParam ) .AND. p%NumOuts > 0 ) THEN ! Output has been requested so let's open an output file
611-
! Open the file for output
612-
OutFileName = TRIM(OutRootName)//'.out'
613-
CALL GetNewUnit( p%UnJckF )
610+
611+
! Initialize to -1 to indicate that the output file unit is not valid
612+
p%UnJckF = -1
613+
614+
! No outputs requested, so just return
615+
if ((.not. allocated(p%OutParam)) .or. (p%NumOuts == 0)) then
616+
call WrScr('SubDyn: no outputs were requested, so separate output file will not be generated.')
617+
return
618+
end if
614619

615-
CALL OpenFOutFile ( p%UnJckF, OutFileName, ErrStat, ErrMsg )
616-
IF ( ErrStat >= AbortErrLev ) THEN
617-
ErrMsg = ' Error opening SubDyn-level output file: '//TRIM(ErrMsg)
618-
RETURN
619-
END IF
620-
621-
! Write the output file header
622-
WRITE (p%UnJckF,'(/,A/)', IOSTAT=ErrStat2) 'These predictions were generated by '//TRIM(GETNVD(ProgVer))//&
623-
' on '//CurDate()//' at '//CurTime()//'.'
624-
625-
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]
626-
627-
! Write the names of the output parameters:
628-
Frmt = '(A8,'//TRIM(Int2LStr(p%NumOuts+p%OutAllInt*p%OutAllDims))//'(:,A,'//TRIM( p%OutSFmt )//'))'
629-
WRITE(p%UnJckF,Frmt, IOSTAT=ErrStat2) TRIM( 'Time' ), ( p%Delim, TRIM( InitOut%WriteOutputHdr(I) ), I=1,p%NumOuts+p%OutAllInt*p%OutAllDims )
620+
! Open the file for output
621+
OutFileName = TRIM(OutRootName)//'.out'
622+
call GetNewUnit( p%UnJckF )
623+
624+
call OpenFOutFile ( p%UnJckF, OutFileName, ErrStat, ErrMsg )
625+
if (ErrStat >= AbortErrLev) then
626+
ErrMsg = ' Error opening SubDyn-level output file: '//TRIM(ErrMsg)
627+
return
628+
end if
630629

631-
! Write the units of the output parameters:
632-
WRITE(p%UnJckF,Frmt, IOSTAT=ErrStat2) TRIM( 's'), ( p%Delim, TRIM( InitOut%WriteOutputUnt(I) ), I=1,p%NumOuts+p%OutAllInt*p%OutAllDims )
633-
END IF ! there are any requested outputs
630+
! Write the output file header
631+
write(p%UnJckF,'(/,A/)', IOSTAT=ErrStat2) 'These predictions were generated by '//TRIM(GETNVD(ProgVer))//&
632+
' on '//CurDate()//' at '//CurTime()//'.'
633+
634+
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]
635+
636+
! Write the names of the output parameters:
637+
Frmt = '(A8,'//TRIM(Int2LStr(p%NumOuts+p%OutAllInt*p%OutAllDims))//'(:,A,'//TRIM( p%OutSFmt )//'))'
638+
write(p%UnJckF,Frmt, IOSTAT=ErrStat2) TRIM( 'Time' ), ( p%Delim, TRIM( InitOut%WriteOutputHdr(I) ), I=1,p%NumOuts+p%OutAllInt*p%OutAllDims )
639+
640+
! Write the units of the output parameters:
641+
write(p%UnJckF,Frmt, IOSTAT=ErrStat2) TRIM( 's'), ( p%Delim, TRIM( InitOut%WriteOutputUnt(I) ), I=1,p%NumOuts+p%OutAllInt*p%OutAllDims )
634642
END SUBROUTINE SDOut_OpenOutput
635643

636644
!====================================================================================================
637645

638646

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

649-
ErrStat = 0
656+
ErrStat = ErrID_None
650657
ErrMsg = ""
651-
Err = .FALSE.
658+
659+
! If file is not open, return
660+
if (p%UnJckF == -1) return
652661

653662
! Close our output file
654-
CLOSE( p%UnJckF, IOSTAT = ErrStat )
655-
IF ( ErrStat /= 0 ) Err = .TRUE.
656-
657-
! Make sure ErrStat is non-zero if an error occurred
658-
IF ( Err ) ErrStat = ErrID_Fatal
659-
RETURN
663+
close(p%UnJckF, iostat=Stat)
664+
if (Stat /= 0) then
665+
ErrStat = ErrID_Fatal
666+
ErrMsg = ' Problem closing SubDyn output file.'
667+
end if
660668

661669
END SUBROUTINE SDOut_CloseOutput
662670
!====================================================================================================
@@ -712,19 +720,14 @@ SUBROUTINE SDOut_WriteOutputs( UnJckF, Time, SDWrOutput, p, ErrStat, ErrMsg )
712720
! Local variables
713721
INTEGER :: I ! Generic loop counter
714722
CHARACTER(200) :: Frmt ! a string to hold a format statement
723+
715724
ErrStat = ErrID_None
716725
ErrMsg = ""
717-
718-
! Initialize ErrStat and determine if it makes any sense to write output
719-
IF ( .NOT. ALLOCATED( p%OutParam ) .OR. UnJckF < 0 ) THEN
720-
ErrStat = ErrID_Fatal
721-
ErrMsg = ' To write outputs for SubDyn there must be a valid file ID and OutParam must be allocated.'
722-
RETURN
723-
ELSE
724-
ErrStat = ErrID_None
725-
END IF
726726

727-
! Write the output parameters to the file
727+
! If output file is not open, return
728+
if (p%UnJckF == -1) return
729+
730+
! Write the output parameters to the file
728731
Frmt = '(F10.4,'//TRIM(Int2LStr(p%NumOuts+p%OutAllInt*p%OutAllDims))//'(:,A,'//TRIM( p%OutFmt )//'))'
729732

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

0 commit comments

Comments
 (0)