Skip to content

Commit

Permalink
add color text demo
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jan 23, 2019
1 parent 500ed3f commit 8270473
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 36 deletions.
2 changes: 1 addition & 1 deletion coarray/CMakeLists.txt
Expand Up @@ -22,7 +22,7 @@ endif()
include(CheckFortranSourceCompiles)
set(CMAKE_REQUIRED_FLAGS ${Coarray_COMPILE_OPTIONS})
set(CMAKE_REQUIRED_LIBRARIES ${Coarray_LIBRARY})
check_fortran_source_compiles("program cs; real :: x[*]; call co_sum(x); end"
check_fortran_source_compiles("real :: x[*]; call co_sum(x); end"
f18coarray SRC_EXT f90)


Expand Down
3 changes: 0 additions & 3 deletions lapack95/CMakeLists.txt
Expand Up @@ -10,9 +10,6 @@ if(NOT hasParent)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/)
endif()

if(UNIX AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "~/.local" CACHE PATH "..." FORCE)
endif()

if(DEFINED ENV{MKLROOT})
set(USEMKL 1)
Expand Down
1 change: 1 addition & 0 deletions meson.build
Expand Up @@ -12,4 +12,5 @@ endif

subdir('cxx')
subdir('mpi')
subdir('standard')
subdir('system')
11 changes: 6 additions & 5 deletions overloading/CMakeLists.txt
Expand Up @@ -7,17 +7,18 @@ if(NOT hasParent)
include(../cmake/compilers.cmake)
endif()

check_fortran_source_compiles("use iso_fortran_env; print *, compiler_options(); end"
f08version SRC_EXT f90)

if(f08version)
add_executable(proc pragma.f90)
target_compile_options(proc PRIVATE ${FFLAGS})
target_link_libraries(proc ${FLIBS})
add_test(NAME FortranPragma COMMAND proc)

if(NOT f18errorstop)
message(WARNING "Your compiler does not support Fortran 2018 Error Stop")
return()
endif()

if(f18errorstop)
add_executable(f18es f2018errorstop.f90)
target_compile_options(f18es PRIVATE ${FFLAGS})
target_link_libraries(f18es PRIVATE ${FLIBS})

endif()
3 changes: 2 additions & 1 deletion overloading/pragma.f90
Expand Up @@ -2,6 +2,7 @@ program procprint

use,intrinsic:: iso_fortran_env

print *,compiler_version(),compiler_options()
print *,compiler_version()
print *, compiler_options()

end program
5 changes: 5 additions & 0 deletions standard/CMakeLists.txt
Expand Up @@ -7,9 +7,14 @@ if(NOT hasParent)
include(../cmake/compilers.cmake)
endif()

check_fortran_source_compiles("error stop; end"
f08block SRC_EXT f90)

if(f08block)
add_executable(block block.f90)
target_compile_options(block PRIVATE ${FFLAGS})
target_link_libraries(block ${FLIBS})
endif()

add_executable(shortcircuit short_circuit.f90)
target_compile_options(shortcircuit PRIVATE ${FFLAGS})
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions standard/meson.build
@@ -0,0 +1,23 @@
fc = meson.get_compiler('fortran')

f08block = fc.links('error stop; end', name : 'F2008 block')

if f08block
block_exe = executable('block', 'block.f90')
endif

shortcircuit_exe = executable('shortcircuit', 'short_circuit.f90')

bitpat= executable('bitpat', 'bitpat.f90')
test('Bit Pattern', bitpat)

justwait_exe = executable('justwait', 'pause.f90')

mkdirstd = executable('mkdirstd', 'mkdir.f90')
test('mkdir', mkdirstd, args: 'testdir/hello')

sleepstd = executable('sleepstd', 'sleep.f90')
test('Micro sleep', sleepstd, timeout : 1)

statement = executable('statement', 'statement_function.f90')
test('Statement', statement)
5 changes: 4 additions & 1 deletion standard/mkdir.f90
Expand Up @@ -36,7 +36,10 @@ function mkdir(path) result(ret)
character(kind=c_char, len=:), allocatable :: buf
!! must use allocatable buffer, not direct substring to C

if (len(path) == 0) error stop 'must specify directory to create'
if (len(path) == 0) then
write(stderr,*) 'must specify directory to create'
stop 1
endif

!> single directory
i = index(path, '/')
Expand Down
10 changes: 5 additions & 5 deletions system/CMakeLists.txt
Expand Up @@ -7,12 +7,11 @@ if(NOT hasParent)
include(../cmake/compilers.cmake)
endif()

if(hasParent AND NOT f08command)
return()
elseif(NOT f08command)
message(FATAL_ERROR "Fortran 2008 execute_command_line necessary for these programs.")
endif()
add_executable(color color_text.f90)
target_compile_options(color PRIVATE ${FFLAGS})
target_link_libraries(color ${FLIBS})

if(f08command)
add_library(osdet os_detect.f90)
target_compile_options(osdet PRIVATE ${FFLAGS})

Expand All @@ -29,6 +28,7 @@ add_test(NAME FortranCompiler COMMAND complog)
add_executable(playsound play_sound.f90)
target_compile_options(playsound PRIVATE ${FFLAGS})
target_link_libraries(playsound ${FLIBS})
endif()

if(f18errorstop)
add_executable(callpython call_python_script.f90)
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions system/color_text.f90
@@ -0,0 +1,23 @@
!! This program demonstrates color text output to terminal from Fortran program.
!! It uses ANSI escape codes and also works on modern Windows consoles.
!! It is compatible across compiler vendors.
!!
!! More colors: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

use, intrinsic :: iso_fortran_env, only: stderr=>error_unit

character, parameter :: e = char(27) !< escape

character(5), parameter :: &
red = e // '[31m', &
yellow = e // '[33m', &
normal = e // '[0m'

print *, red // 'this is red text to stdout' // normal // ' this is regular text to stdout'
write(stderr,*) red // 'this is red text to stderr' // normal // ' this is regular text to stderr'

print *, yellow // 'this is yellow on stdout'
print *, 'this stdout is also yellow because the prior statement did not set normal'

write(stderr,*) 'stderr is also yellow.'
end program
35 changes: 15 additions & 20 deletions system/meson.build
@@ -1,28 +1,23 @@
osdet = library('osdet', ['os_detect.f90'])
color_exe = executable('color', 'color_text.f90')

fc = meson.get_compiler('fortran')
code = '''call execute_command_line(' '); error stop; end'''
f2008 = fc.compiles(code)
osdet = library('osdet', 'os_detect.f90')

code = '''character :: b; error stop b; end'''
f2018 = fc.compiles(code)
fc = meson.get_compiler('fortran')
f08command = fc.links('call execute_command_line(" "); end',
name : 'F2008 execute_command_line')

if f2008
if f08command
gitrev = executable('gitrev', 'gitrev.f90')
test('Git revision log', gitrev)

complog = executable('complog', 'compiler_log.f90')
test('Compiler version log', complog)

sound = executable('sound', 'play_sound.f90')
test('Play Sound', sound)
test('Compiler version logging', complog)

gitrev = executable('gitrev', 'gitrev.f90')
test('Git Revision', gitrev)
playsound_exe = executable('playsound', 'play_sound.f90')
endif

if f2018

callpy = executable('call_python', 'call_python_script.f90', link_with : osdet)
test('Call Python', callpy)

f18errorstop = fc.compiles('error stop; end', name: 'F2018 error stop')
if f18errorstop
callpython_exe = executable('callpython', 'call_python_script.f90',
link_with : osdet)
endif


0 comments on commit 8270473

Please sign in to comment.