Skip to content

Commit

Permalink
Added --output option for output file
Browse files Browse the repository at this point in the history
  • Loading branch information
vmagnin committed Oct 31, 2021
1 parent ea8d915 commit 2a9646f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
All notable changes to the taptempo project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [TapTempo Fortran dev]

### Added
- A new option:
-o, --output save the results in the taptempo.txt file

### Fixed
- More robust command line options.

## [TapTempo Fortran 0.9] 2021-10-28
Initial commit.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Usage : taptempo [options]
Options :
-h, --help display this help message
-o, --output save the results in the taptempo.txt file
-p, --precision change the number of decimal for the tempo,
the default is 0 decimal places, the max is 5 decimals
-r, --reset-time change the time in seconds to reset the calculation,
Expand Down
2 changes: 1 addition & 1 deletion fpm.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "taptempo"
version = "0.9.0"
version = "1.0.0"
license = "license"
author = "Vincent Magnin and the Fortran-lang community"
maintainer = "Vincent Magnin"
Expand Down
27 changes: 22 additions & 5 deletions src/taptempo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ module taptempo
implicit none

! Tap Tempo Version:
character(len=*), parameter :: version = "0.9.0"
character(len=*), parameter :: version = "1.0.0"

! Default values of the command options:
integer :: s = 5 ! Stack size
integer :: p = 0 ! Precision
integer :: r = 5 ! Reset time in seconds
integer :: s = 5 ! Stack size
integer :: p = 0 ! Precision
integer :: r = 5 ! Reset time in seconds
logical :: out_flag = .false. ! Flag for the ouput file

private

Expand All @@ -33,6 +34,7 @@ subroutine print_options
print '(A)'
print '(A)', "Options :"
print '(A)', " -h, --help display this help message"
print '(A)', " -o, --output save the results in the taptempo.txt file"
print '(A)', " -p, --precision change the number of decimal for the tempo,"
print '(A)', " the default is 0 decimal places, the max is 5 decimals"
print '(A)', " -r, --reset-time change the time in seconds to reset the calculation,"
Expand Down Expand Up @@ -62,6 +64,8 @@ subroutine manage_command_line
call print_version()
call print_options()
stop
case("-o", "--output")
out_flag = .true.
case("-p", "--precision")
i = i + 1
call get_command_argument(i, value=args)
Expand Down Expand Up @@ -92,7 +96,10 @@ subroutine measure_tempo
integer(int64) :: count ! Count of the processor clock
real(wp) :: rate ! Number of clock ticks per second
integer :: i
integer :: my_file ! Unit of the output file
real(wp), dimension(s) :: t ! Time FIFO stack
real(wp) :: t0 ! Time reference
real(wp) :: bpm ! Beats Per Minute
integer :: oldest
character(len=28) :: fmt

Expand All @@ -101,6 +108,11 @@ subroutine measure_tempo
! Stack initialization:
t = 0

if (out_flag) then
open(newunit=my_file, file="taptempo.txt", status="replace")
write(my_file, '(A)') "# t bpm"
end if

print '(A)', "Hit Enter key for each beat (q to quit)."

! Infinite loop:
Expand All @@ -120,13 +132,16 @@ subroutine measure_tempo

if (i == 1) then
print '(A)', "[Hit enter key one more time to start BPM computation...]"
t0 = t(1)
else
! Verify that the user is actively tapping:
if (t(1) - t(2) <= r) then
! Oldest time in the stack:
oldest = min(i, s)
! Computes and prints the beats per minute:
write(*, fmt, advance="no") 60 / ((t(1) - t(oldest)) / (oldest - 1))
bpm = 60 / ((t(1) - t(oldest)) / (oldest - 1))
write(*, fmt, advance="no") bpm
if (out_flag) write(my_file, '(F9.3, F12.5)') t(1)-t0, bpm
else
print '(A)', "Time reset"
i = 1
Expand All @@ -136,6 +151,8 @@ subroutine measure_tempo
end do

print '(A)', "I don't know why you say goodbye..."
if (out_flag) close(my_file)

end subroutine measure_tempo

end module taptempo

0 comments on commit 2a9646f

Please sign in to comment.