Skip to content
Snippets Groups Projects
Commit a3bfacd4 authored by dali662d's avatar dali662d
Browse files

Delete 03_zeitmodul.f95

parent a0384336
No related branches found
No related tags found
No related merge requests found
module zeit_mod
implicit none
private
public :: zeit, GET, operator(<), operator(+), zeit_string
type zeit
private
integer :: h
integer :: m
real :: s
end type
interface GET
module procedure zeit_einlesen
end interface
interface operator (<)
module procedure zeit_vgl
end interface
interface operator (+)
module procedure zeit_add
end interface
contains
subroutine zeit_einlesen(time)
type(zeit), intent(out) :: time
do
read(*,*) time
if (time%h >= 0 .and. time%m >= 0 .and. time%m < 60 .and. time%s >= 0 .and. time%s < 60) exit
write(*,*) "Eingabe fehlerhaft. Gebe die Stunden, Minuten und Sekunden erneut ein."
end do
end subroutine zeit_einlesen
function zeit_string (time)
! gibt die time als string (character) in der form hh:mm:ss zurück
type(zeit), intent(in) :: time
character (len = 8) :: zeit_string
character (len = 2) :: help
! trage stunden in string ein
write(help,'(I2)') time%h
if (time%h * 0.1 < 1) help(1:1) = "0"
zeit_string(1:3) = help // ":"
! trage minuten in string ein
write(help,'(I2)') time%m
if (time%m * 0.1 < 1) help(1:1) = "0"
zeit_string(4:6) = help // ":"
! trage sekunden in string ein
write(help,'(I2)') nint(time%s)
if (time%s * 0.1 < 1) help(1:1) = "0"
zeit_string(7:8) = help
end function
function zeit_vgl(time1, time2) result(kleiner)
type(zeit), intent(in) :: time1, time2
logical :: kleiner !rückgabevariable
kleiner = .false.
if (time1%h < time2%h) then ! vgl stunden
kleiner = .true.
elseif (time1%h == time2%h ) then
if ( time1%m < time2%m ) then
kleiner = .true.
elseif (time1%m == time2%m) then
if (time1%s < time2%s) kleiner = .true.
end if
end if
end function zeit_vgl
function zeit_add(time1, time2) result(sum)
type(zeit), intent(in) :: time1, time2
type(zeit) :: sum ! rückgabewert
sum = zeit(0,0,0)
sum%s = time1%s + time2%s
if (sum%s >= 60) then
sum%s = sum%s - 60
sum%m = 1
end if
sum%m = sum%m + time1%m + time2%m
if (sum%m >= 60) then
sum%m = sum%m - 60
sum%h = 1
end if
sum%h = sum%h + time1%h + time2%h
end function zeit_add
end module zeit_mod
program test
use zeit_mod
implicit none
type(zeit) :: time1, time2
call get(time1)
call get(time2)
write(*,*) zeit_string(time1 + time2)
end program test
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment