Skip to content

Commit a9192ba

Browse files
authored
Merge pull request #2186 from deslaughter/b/chkp_file_close
[Bug] Writing checkpoint files created empty fort.# files
2 parents a72eb62 + 6d307bf commit a9192ba

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

.github/workflows/automated-dev-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ jobs:
774774
- name: Run 5MW tests
775775
working-directory: ${{runner.workspace}}/openfast/build
776776
run: |
777-
ctest -VV -L openfast -LE "cpp|linear|python" -R 5MW_OC3Mnpl_DLL_WTurb_WavesIrr
777+
ctest -VV -L openfast -LE "cpp|linear|python" -R 5MW_OC3Mnpl_DLL_WTurb_WavesIrr -j1
778778
- name: Failing test artifacts
779779
uses: actions/upload-artifact@v4
780780
if: failure()

modules/nwtc-library/src/ModReg.f90

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,24 @@ subroutine CloseRegFile(RF, ErrStat, ErrMsg)
190190
ErrStat = ErrID_None
191191
ErrMsg = ""
192192

193+
! If registry has already been closed, return
194+
if (RF%Unit < 0) return
195+
193196
! Check if there have been any errors while writing to the file
194197
if (RF%ErrStat /= ErrID_None) then
195198
call SetErrStat(RF%ErrStat, RF%ErrMsg, ErrStat, ErrMsg, RoutineName)
196-
return
197199
end if
198200

199201
! Write the actual number of pointers
200202
write (RF%Unit, POS=RF%Offset, iostat=stat) RF%NumPointers
201203
if (stat /= 0) then
202-
ErrStat = ErrID_Fatal
203-
write (ErrMsg, *) 'CloseRegFile: Unable to write offset at beginning of file'
204-
return
204+
call SetErrStat(ErrID_Fatal, 'CloseRegFile: Unable to write offset at beginning of file', &
205+
ErrStat, ErrMsg, RoutineName)
205206
end if
206207

207-
! Close the file
208+
! Close the file and set unit to -1 so file won't be closed again
208209
close (RF%Unit)
210+
RF%Unit = -1
209211

210212
! Deallocate pointer array
211213
if (allocated(RF%Pointers)) deallocate (RF%Pointers)

modules/openfast-library/src/FAST_Subs.f90

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9962,16 +9962,14 @@ SUBROUTINE FAST_CreateCheckpoint_T(t_initial, n_t_global, NumTurbines, Turbine,
99629962

99639963
IF ( unOut < 0 ) THEN
99649964

9965-
CALL GetNewUnit( unOut, ErrStat2, ErrMsg2 )
9966-
CALL OpenBOutFile ( unOut, FileName, ErrStat2, ErrMsg2)
9967-
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
9968-
if (ErrStat >= AbortErrLev ) then
9969-
9965+
CALL GetNewUnit(unOut, ErrStat2, ErrMsg2)
9966+
CALL OpenBOutFile (unOut, FileName, ErrStat2, ErrMsg2)
9967+
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
9968+
if (ErrStat >= AbortErrLev) then
99709969
IF (.NOT. PRESENT(Unit)) THEN
99719970
CLOSE(unOut)
99729971
unOut = -1
99739972
end if
9974-
call cleanup()
99759973
return
99769974
end if
99779975

@@ -9985,20 +9983,15 @@ SUBROUTINE FAST_CreateCheckpoint_T(t_initial, n_t_global, NumTurbines, Turbine,
99859983

99869984
! Initialize the registry file
99879985
call InitRegFile(RF, unOut, ErrStat2, ErrMsg2)
9988-
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
9986+
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
99899987
if (ErrStat >= AbortErrLev) return
99909988

99919989
! Pack data into the registry file
99929990
call FAST_PackTurbineType(RF, Turbine)
9993-
call SetErrStat(RF%ErrStat, RF%ErrMsg, ErrStat, ErrMsg, RoutineName )
9994-
if (ErrStat >= AbortErrLev ) then
9995-
call cleanup()
9996-
return
9997-
end if
99989991

9999-
! Close registry file
9992+
! Close registry file and get any errors that occurred while writing
100009993
call CloseRegFile(RF, ErrStat2, ErrMsg2)
10001-
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
9994+
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
100029995
if (ErrStat >= AbortErrLev) return
100039996

100049997
! If last turbine or no unit, close output unit
@@ -10030,13 +10023,6 @@ SUBROUTINE FAST_CreateCheckpoint_T(t_initial, n_t_global, NumTurbines, Turbine,
1003010023
Turbine%SrvD%m%dll_data%SimStatus = Turbine%SrvD%m%dll_data%avrSWAP( 1)
1003110024
end if
1003210025
END IF
10033-
10034-
call cleanup()
10035-
10036-
contains
10037-
subroutine cleanup()
10038-
call CloseRegFile(RF, ErrStat2, ErrMsg2)
10039-
end subroutine cleanup
1004010026

1004110027
END SUBROUTINE FAST_CreateCheckpoint_T
1004210028
!----------------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)