Skip to content

Commit

Permalink
Update print message, output file header (NREL#35)
Browse files Browse the repository at this point in the history
* Update print message, output file header,
Add CurTime and CurDate functions

* ignore vim and ifort temp files

* add cmake files

* Add git query function

* Update print statement with git versioning

* update for git version printing

* Use git version for debug file

* Trim version in initial print statement

Co-authored-by: Nikhar Abbas <nikhar.abbas@colorado.edu>
  • Loading branch information
dzalkind and nikhar-abbas authored Feb 5, 2021
1 parent b64ba17 commit f98e887
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Scripts/CompileDISCONHereCopyRun\.cmd
*~
.DS_Store
*.u2d
*.swp
*.i90
*.swp

# vs code
.vscode
19 changes: 16 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ message(STATUS "CMAKE_Fortran_COMPILER_ID = ${CMAKE_Fortran_COMPILER_ID}")
if(APPLE OR UNIX)
# Enable .dll export
if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DIMPLICIT_DLLEXPORT -r8 -double_size 64")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DIMPLICIT_DLLEXPORT -r8 -double_size 64 -cpp")
else()
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DIMPLICIT_DLLEXPORT -ffree-line-length-0 -fdefault-real-8 -fdefault-double-8")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DIMPLICIT_DLLEXPORT -ffree-line-length-0 -fdefault-real-8 -fdefault-double-8 -cpp")
endif()
elseif(WIN32 AND MINGW)
# Ensure static linking to avoid requiring Fortran runtime dependencies
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-0 -static-libgcc -static-libgfortran -static -fdefault-real-8 -fdefault-double-8")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-0 -static-libgcc -static-libgfortran -static -fdefault-real-8 -fdefault-double-8 -cpp")
endif()


set(SOURCES
src/Constants.f90
src/ControllerBlocks.f90
Expand All @@ -32,6 +33,18 @@ set(SOURCES
src/ReadSetParameters.f90
)

# Git version
if( DEFINED GIT_DESCRIBE )
message( WARNING
"Version information has been set as a CMake flag. This should only used when the git-version cannot be set automatically."
)
else()
include(${CMAKE_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake)
git_describe(GIT_DESCRIBE)
endif()
add_definitions(-DGIT_VERSION_INFO="${GIT_DESCRIBE}")

# Library
add_library(discon SHARED ${SOURCES})

install(TARGETS discon
Expand Down
160 changes: 160 additions & 0 deletions cmake/GetGitRevisionDescription.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# git_local_changes(<var>)
#
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
# Uses the return code of "git diff-index --quiet HEAD --".
# Does not regard untracked files.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Obtained from https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake
# on August 29 2017
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)

# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)

function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
# check if this is a submodule
if(NOT IS_DIRECTORY ${GIT_DIR})
file(READ ${GIT_DIR} submodule)
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()

if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)

configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY)
include("${GIT_DATA}/grabRef.cmake")

set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()

function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()

execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe --abbrev=8 --tags --dirty
# ${hash}
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()

set(${_var} "${out}" PARENT_SCOPE)
endfunction()

function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()

function(git_local_changes _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()

execute_process(COMMAND
"${GIT_EXECUTABLE}"
diff-index --quiet HEAD --
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(res EQUAL 0)
set(${_var} "CLEAN" PARENT_SCOPE)
else()
set(${_var} "DIRTY" PARENT_SCOPE)
endif()
endfunction()
44 changes: 44 additions & 0 deletions cmake/GetGitRevisionDescription.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Obtained from https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake.in
# on August 29 2017
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

set(HEAD_HASH)

file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)

string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
else()
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
set(HEAD_HASH "${CMAKE_MATCH_1}")
endif()
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()

if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 8)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()
111 changes: 110 additions & 1 deletion src/Functions.f90
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ SUBROUTINE Debug(LocalVar, CntrPar, DebugVar, avrSWAP, RootName, size_avcOUTNAME
INTEGER(4), PARAMETER :: UnDb2 = 86 ! I/O unit for the debugging information, avrSWAP
REAL(C_FLOAT), INTENT(INOUT) :: avrSWAP(*) ! The swap array, used to pass data to, and receive data from, the DLL controller.
CHARACTER(size_avcOUTNAME-1), INTENT(IN) :: RootName ! a Fortran version of the input C string (not considered an array here) [subtract 1 for the C null-character]

CHARACTER(200) :: Version ! git version of ROSCO
CHARACTER(10) :: DebugOutStr1, DebugOutStr2, DebugOutStr3, DebugOutStr4, DebugOutStr5, &
DebugOutStr6, DebugOutStr7, DebugOutStr8, DebugOutStr9, DebugOutStr10, &
DebugOutStr11, DebugOutStr12, DebugOutStr13, DebugOutStr14, DebugOutStr15, &
Expand Down Expand Up @@ -516,7 +516,9 @@ SUBROUTINE Debug(LocalVar, CntrPar, DebugVar, avrSWAP, RootName, size_avcOUTNAME
! If we're debugging, open the debug file and write the header:
! Note that the headers will be Truncated to 10 characters!!
IF (CntrPar%LoggingLevel > 0) THEN
Version = QueryGitVersion()
OPEN(unit=UnDb, FILE=RootName(1:size_avcOUTNAME-5)//'RO.dbg')
WRITE (UnDb,*) 'Generated on '//CurDate()//' at '//CurTime()//' using ROSCO-'//TRIM(Version)
WRITE (UnDb,'(99(a10,TR5:))') 'Time', DebugOutStrings
WRITE (UnDb,'(99(a10,TR5:))') '(sec)', DebugOutUnits
END IF
Expand Down Expand Up @@ -546,4 +548,111 @@ SUBROUTINE Debug(LocalVar, CntrPar, DebugVar, avrSWAP, RootName, size_avcOUTNAME
END IF

END SUBROUTINE Debug
!-------------------------------------------------------------------------------------------------------------------------------
FUNCTION QueryGitVersion()

CHARACTER(200) :: QueryGitVersion

! The Visual Studio project sets the path for where to find the header file with version info
#ifdef GIT_INCLUDE_FILE
#include GIT_INCLUDE_FILE
#endif

#ifdef GIT_VERSION_INFO
QueryGitVersion = GIT_VERSION_INFO
#else
QueryGitVersion = 'unversioned'
#endif

RETURN
END FUNCTION QueryGitVersion
!-------------------------------------------------------------------------------------------------------------------------------
! Copied from NWTC_IO.f90
!> This function returns a character string encoded with today's date in the form dd-mmm-ccyy.
FUNCTION CurDate( )

! Function declaration.

CHARACTER(11) :: CurDate !< 'dd-mmm-yyyy' string with the current date


! Local declarations.

CHARACTER(8) :: CDate ! String to hold the returned value from the DATE_AND_TIME subroutine call.



! Call the system date function.

CALL DATE_AND_TIME ( CDate )


! Parse out the day.

CurDate(1:3) = CDate(7:8)//'-'


! Parse out the month.

SELECT CASE ( CDate(5:6) )
CASE ( '01' )
CurDate(4:6) = 'Jan'
CASE ( '02' )
CurDate(4:6) = 'Feb'
CASE ( '03' )
CurDate(4:6) = 'Mar'
CASE ( '04' )
CurDate(4:6) = 'Apr'
CASE ( '05' )
CurDate(4:6) = 'May'
CASE ( '06' )
CurDate(4:6) = 'Jun'
CASE ( '07' )
CurDate(4:6) = 'Jul'
CASE ( '08' )
CurDate(4:6) = 'Aug'
CASE ( '09' )
CurDate(4:6) = 'Sep'
CASE ( '10' )
CurDate(4:6) = 'Oct'
CASE ( '11' )
CurDate(4:6) = 'Nov'
CASE ( '12' )
CurDate(4:6) = 'Dec'
END SELECT


! Parse out the year.

CurDate(7:11) = '-'//CDate(1:4)


RETURN
END FUNCTION CurDate
!=======================================================================
!> This function returns a character string encoded with the time in the form "hh:mm:ss".
FUNCTION CurTime( )

! Function declaration.

CHARACTER(8) :: CurTime !< The current time in the form "hh:mm:ss".


! Local declarations.

CHARACTER(10) :: CTime ! String to hold the returned value from the DATE_AND_TIME subroutine call.



CALL DATE_AND_TIME ( TIME=CTime )

CurTime = CTime(1:2)//':'//CTime(3:4)//':'//CTime(5:6)


RETURN
END FUNCTION CurTime
!=======================================================================



END MODULE Functions
Loading

0 comments on commit f98e887

Please sign in to comment.