我在编译一个简单的fortran程序时遇到了麻烦,该程序在同一目录中使用了一个模块.我有2个文件:test1.f90,其中包含程序和modtest.f90,其中包含模块.
这是test1.f90:
program test
use modtest
implicit none
print*,a
end program test
Run Code Online (Sandbox Code Playgroud)
这是modtest.f90:
module modtest
implicit none
save
integer :: a = 1
end module modtest
Run Code Online (Sandbox Code Playgroud)
两个文件都在同一目录中.我像这样编译modtest.f90和test.f90:
gfortran -c modtest.f90
gfortran -o test1 test1.f90
Run Code Online (Sandbox Code Playgroud)
但后来我得到了这个错误:
/tmp/cckqu8c3.o: In function `MAIN__':
test1.f90:(.text+0x50): undefined reference to `__modtest_MOD_a'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
有什么我想念的吗?谢谢您的帮助
我的程序正在运行,虽然3D阵列,标签"群",它发现,然后做一些检查,看看是否有临近簇具有比目前更高的集群的标签.还有第二个数组保存了"正确的"群集标签.如果它发现正确标记了第n个相邻簇,则将该元素分配给0,否则将其分配给正确的标签(例如,如果第n个站点具有标签2,并且邻居标记为3,则第3个元素为labelArray设置为2).老实说,我有充分的理由这样做!
我想要的只是能够分配动态的第n个元素labelArray.我已经看过可分配的数组并将事物声明为,labelArray(*)但我并不是真的理解这些,尽管在网上搜索和StackOverflow.
因此,任何帮助这样做都会很棒.
我明白gfortran可以编译f90或f95吗?它如何知道它正在编译哪一个?还可以编译f77代码吗?ubuntu已经有了fortran编译器,还是需要下载gfortran?
我正在努力学习使用函数.我有以下代码:
program main
implicit none
write(*,*) test(4)
end program
integer function test(n)
implicit none
integer, intent(in) :: n
integer :: i, ans
ans=1
do i=1,n
ans=ans*i
enddo
test=ans
end function test
Run Code Online (Sandbox Code Playgroud)
当我编译(使用gfortran 4.1.2)时,我收到以下错误:
In file test.f90:4
write(*,*) test(4)
1
Error: Function 'test' at (1) has no IMPLICIT type
Run Code Online (Sandbox Code Playgroud) 这是以下部分,
调用Fortran 90样式例程的危险
Run Code Online (Sandbox Code Playgroud)program main real, dimension(5) :: x x = 0. ! THIS IS WRONG call incb(x) print *, x end program main subroutine incb(a) ! this is a fortran90 style subroutine real, dimension(:) :: a a = a + 1. end subroutine incb解释子例程incb使用Fortran 90样式的假定形状数组(包含维度(:)).此类例程必须位于模块中,或者在使用它们的任何地方都具有显式接口.在这个例子中,没有一个是真的.
调用此类过程的一种正确方法是使用显式接口,如下所示:
Run Code Online (Sandbox Code Playgroud)program main real, dimension(5) :: x ! THIS IS THE RIGHT WAY interface subroutine incb(a) real, dimension(:) :: a end subroutine incb end interface x = 0. call incb(x) …
我不理解使用pgf90 7.2的present()内在函数的行为.我写了一个20行的示例程序来测试这个,但结果对我来说仍然没有意义.注意:
subroutine testopt(one,two,three,four,five)
implicit none
integer, intent(in) :: one,two
integer, intent(out) :: three
integer, intent(in), optional :: four
integer, intent(out), optional :: five
three = one + two
print *,"present check: ",present(four),present(five)
if (present(four) .and. present(five)) then
five = four*four
end if
end subroutine testopt
Run Code Online (Sandbox Code Playgroud)
如果我:从我的主程序调用testopt(1,2,(任何变量)),它打印:"present check:T F".但是如果我:从子程序中调用testopt(1,2,(任何变量)),它会打印:"present check:T T".我希望在任何一种情况下都能看到"当前检查:F F",因为我只使用3个非可选参数调用子程序,而不是任何可选参数.我无法理解为什么它会以这种方式运行,这导致我正在处理的程序中的一个主要错误.我很欣赏任何见解.谢谢.
我有编码fortran 77但我想转换为fortran 90 ..我可以在哪里下载转换器软件?
我在fortran中写了一些简单的输出,但我想要空白分隔符.但是,如果使用以下语句:
format(A20,ES18.8,A12,ES18.8)
Run Code Online (Sandbox Code Playgroud)
我得到这样的输出:
p001t0000 3.49141273E+01obsgp_oden 1.00000000E+00
Run Code Online (Sandbox Code Playgroud)
我更喜欢这个:
p001t0000 3.49141273E+01 obsgp_oden 1.00000000E+00
Run Code Online (Sandbox Code Playgroud)
我尝试使用负值宽度(如在Python中),但没有骰子.那么,有没有办法让数字左对齐?
提前谢谢了!
我用gfortran编译了一个fortran 90程序,它以我想要的方式构建可扩展的3D数组.运行时,我收到以下错误:
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x10542ee42
#1 0x10542f60e
#2 0x7fff8d7895a9
#3 0x10542575e
#4 0x105425975
#5 0x105425d0e
Segmentation fault: 11
Run Code Online (Sandbox Code Playgroud)
我相信这是大型3D阵列的内存问题,因为它可以减小尺寸,但是无论如何都可以解决这个问题吗?这是我的代码:
PROGRAM phantomtest
IMPLICIT NONE
INTEGER, PARAMETER:: columns=34, rows=34, diags=((4*columns)-6), m=(4*columns)-6+(2*columns)
REAL, ALLOCATABLE, DIMENSION(:,:,:)::phantom
INTEGER :: i, j, k
CHARACTER (LEN=3) :: nstring, nullstring=''
ALLOCATE(phantom(columns,rows,m))
phantom=0
CALL Phantom_Making(phantom,columns,rows,diags,m)
WRITE(nstring,FMT="(I3)"), columns
PRINT*, nullstring
DO k=1,m
DO i=1,columns
WRITE(*,FMT="("//nstring//"I2)") phantom(i,:,k)
END DO
PRINT *, nullstring
END DO
END PROGRAM phantomtest
!--------------------------- …Run Code Online (Sandbox Code Playgroud) 在Fortran中,有两种标准方法可以从函数返回结果.第一种方法是将函数的返回值赋给函数名.
function foo()
integer :: foo
foo = 10
end function foo
Run Code Online (Sandbox Code Playgroud)
在Fortran 90中标准化的第二种形式是通过"结果"变量.
function foo result(res)
integer :: res
res = 10
end function foo
Run Code Online (Sandbox Code Playgroud)
调用函数的任何一种形式都会返回值10.我的问题是,Fortran 90委员会引入结果变量的理由是什么?他们是否标准化了一种常规做法?或者他们通过不将函数名称绑定到函数结果来允许程序更加模块化.例如,在第二个版本中foo(),函数的名称foo()可以更改为bar(),并且函数在调用时仍将按预期工作.
但是,我可能错了.有谁知道引入结果变量的实际理由是什么?