다음 포트란 코드는 사용자의 입력에 따라 원 또는 직사각형의 면적을 계산합니다. 입력 부동 소수점이 하나만있는 경우 원의 면적을 계산하고 두 개가 있으면 직사각형의 영역을 반환합니다. 현재, 사용자가 처음에 1 또는 2를 입력하여이 작업을 수행합니다. 그러나, 나는 fortran의 입력 매개 변수를 무한히 # 읽는 직접적인 방법이 있는지 알고 싶습니다. 당신의 지혜를 제공하십시오. 감사합니다! 포트란 컴파일러 명령 줄 인수를 처리하기위한 고유의 루틴을 제공합니다 최신Fortran에서 함수/서브 루틴의 입력 매개 변수를 무한정 # 읽는 방법?
module MA
implicit none
interface area
module procedure area_circ ! calculate the area of circles
module procedure area_rec ! rectangles
end interface
contains
real function area_circ(a)
implicit none
real, intent(in) :: a
real, parameter :: pi=3.14159
area_circ = pi*a**2
write(*,"('Area of circle = ',F6.2)") area_circ
return
end function area_circ
real function area_rec(a,b)
implicit none
real, intent(in) :: a,b
area_rec=a*b
write(*,"('Area of rectangle = ',F6.2)") area_rec
return
end function area_rec
end module MA
program hw1101
use MA
implicit none
real :: a,b,S
integer :: i
write(*,*) 'Please type # of parameters: '
read(*,*) i
if(i==1) then
write(*,*) "Please type one parameter: "
read(*,*) a
S=area(a)
else if (i==2) then
write(*,*) "Please type two paramters: "
read(*,*) a,b
S=area(a,b)
else
write(*,*) "Other functions under construction..."
end if
stop
end program hw1101