Fortran을 처음 사용하지만 필자가 작성한 프로그램에서 새 파일에 서브 프로그램으로 포함시키지 않고 정보를 검색 할 수있는 방법을 찾으려고합니다. 현재로서는 새 파일 내에 4 개의 서브 루틴이 있으며 대신 모든 4에 반경을 입력하고 해당 출력을받을 수 있기를 원합니다.여러 파일을 fortran으로 연결
이것은 내 코드의 기본 형식입니다. 기본적으로 현재 프로그램 표현에 필요한 모든 변수를 얻으려면 4 개의 개별 프로그램이 필요합니다. 지금까지 include 및 call 표현식을 모두 사용해 보았지만 파일로 되돌리려면 필요한 정보를 검색 할 수 없었으며 "적용되지 않는"답변이있었습니다.
program practicedynamo
implicit none
real:: A,B,C, Radius
real::Bsquared,Vsquared
read*,radius
call programA(radius,A)
call programB(radius,B)
call programC(radius,C)
Vsquared=(1.0/3.0)*B
Bsquared= 4*pi*density*Vsquared
gradient=radius*C
Rvector=Bsquared*Vsquared*gradient
ThetaVector=Rvector*sin(A)
end program practicedynamo
!and then my four subroutines would be placed afterwards
!here is an example of one of my subroutines within my actual code (the version above has been simplified and I've changed the variables)
subroutine testdensity(radius,density)
implicit none
real::radius,x,sunradius,density
if (radius>0.and.radius<=695500000) then
sunradius=695500000
x=radius/sunradius
density=((519*x**4.0)-(1630*x**3.0)+(1844*x*x)-(889*x)+155)
print*," "
density=density*1000
print*,"the density is",density, "kg per meters cubed"
else
print*, "this radius is not an option for the sun"
end if
end subroutine testdensity
반지름을 서브 루틴 인수로 전달합니다. 괜찮습니다. programA와 같은 서브 루틴 중 하나에 대한 코드와 프로그램의 출력이 포함되어야합니다. 이전에 서브 루틴을 사용해 보셨습니까? 온라인 튜토리얼에서 서브 루틴이 사용되는 방법의 예를 찾으십시오. – Fortranner
내 서브 루틴은 잘 작동합니다. 서브 루틴으로 할 때 원하는 모든 것을 제공하기 위해 노력하고있는 코드를 얻을 수 있습니다. 나는 그들 중 엄청난 양의 것을 가지고있을 때 항해하기가 어려워 질 것이고, 나는 문제를 겪을 것이라고 걱정한다. 서브 루틴을 사용하는 것이 이런 종류의 일을하는 가장 좋은 방법이라면 나는 그것을 계속 할 것입니다. 나는 물건을 더 분명하게하기 위해 나의 서브 루틴 중 하나를 포함 할 것이다. – user3617451