继续关于 dll 的最后一个未解决的问题,我尝试使用 g95 使用以下命令创建 fortran dll:
g95 -c FCall.f90
g95 -shared -mrtd -o FCall.dll FCall.o
当我将它链接到 VB 时,它显示“无法在 DLL 'C:\Users\Hp\Documents\Visual Studio 2010\Projects\WindowsApplication5\WindowsApplication5\FCall.dll' 中找到名为 'FortranCall' 的入口点。”
这是 FORTRAN 代码:
SUBROUTINE FortranCall (r1, num)
!DEC$ ATTRIBUTES DLLEXPORT :: FortranCall
!DEC$ ATTRIBUTES ALIAS:'FortranCall' :: FortranCall
REAL,INTENT(IN) :: r1
REAL,INTENT(OUT) :: num
num = MOD (r1, 256.0)
END SUBROUTINE
Run Code Online (Sandbox Code Playgroud)
这是VB代码:
Private Sub Command1_Click()
r1 = 456.78
Call FortranCall(r1, Num)
Text1.Text = Str$(Num)
End Sub
Run Code Online (Sandbox Code Playgroud)
VB中的模块代码:
Declare Sub FortranCall Lib"C:\Users\Hp\Documents\Visual Studio 2010\Projects\WindowsApplication5\WindowsApplication5\FCall.dll"
(r1 As …
我有这样的事情:
Module ModA
contains
subroutine FooA()
....
end subroutine
subroutine FooB()
....
end subroutine
end mofule ModA
Run Code Online (Sandbox Code Playgroud)
我可以将两个子程序分别拆分在一个单独的文件中,并且仍然属于同一个模块吗?
我n*n在 Xeon 处理器系统上使用 C 和 FORTRAN运行矩阵乘法代码。我很惊讶地看到两种方法之间的实时差异。为什么 FORTRAN 代码给了我更快的执行时间?我在dgemm()C 代码中使用并调用了相同的函数。我尝试运行更改循环顺序的通用 C 代码并尝试使用不同的标志来优化模拟过程。我无法达到使用dgemm().
FORTRAN 代码 - dgemm():
#include "stdio.h"
#include "time.h"
#include "sys/time.h"
#include "math.h"
#include "stdlib.h"
long long readTSC(void)
{
/* read the time stamp counter on Intel x86 chips */
union { long long complete; unsigned int part[2]; } ticks;
__asm__ ("rdtsc; mov %%eax,%0;mov %%edx,%1"
: "=mr" (ticks.part[0]),
"=mr" (ticks.part[1])
: /* no inputs */
: "eax", "edx");
return ticks.complete;
}
volatile double gtod(void) …Run Code Online (Sandbox Code Playgroud) 我正在通过 fortran 90 运行此代码
Program Projectile
! This Program Calculates the Velocity and Height of a
! Projectile
! Given its Initial Height, Initial Velocity and Constant
! Acceleration.
Implicit None
Real :: Initial_Hight, Height, Initial_Velocity, Velocity, &
Time, Acceleration = -9.807
! Obtain Values for Initial Height, Initial Velocity and
! Time
Print*, "Enter the Initial Height and Velocity:"
Read*, Initial_Height, Initial_Velocity
Print*, "Enter Time at Which to Calculate Height and &
Velocity:"
Read*, Time
! Calculate the Height …Run Code Online (Sandbox Code Playgroud) 我是使用 LAPACK/BLAS 的新手。我想计算一个方程的解:
AU=F
我想知道这部分代码的逻辑错误是什么。我使用求解器输入大小为 ((xdiv-1) (ydiv-1),(xdiv-1) (ydiv-1)) 的矩阵 A。然后,随后求解方程。U=逆(A)* f。
其中 U 和 f 大小相同。(u((xdiv-1) (ydiv-1),1),f((xdiv-1) (ydiv-1),1))。执行矩阵求逆时出现分段错误错误。
这是我的代码:
program main
double precision, allocatable :: A(:,:)
double precision, allocatable :: u(:,:), f(:,:)
double precision mesh(2), dx, dy
integer xdiv, ydiv
xdiv=55
ydiv=55
mesh(1)=.001
mesh(2)=.001
dx=mesh(1)
dy=mesh(2)
allocate (A((xdiv-1)*(ydiv-1),(xdiv-1)*(ydiv-1)))
allocate (Ainv((xdiv-1)*(ydiv-1),(xdiv-1)*(ydiv-1)))
allocate (u((xdiv-1)*(ydiv-1),1),f((xdiv-1)*(ydiv-1),1))
do i =1,(xdiv-1)*(ydiv-1)
A(i,i)=-2.d0*(1.d0/(dx**2)+1.d0/(dy**2))
enddo
do i=1,(xdiv-2)
do j=1,(ydiv-1)
A(i+(j-1)*(xdiv-1),i+(j-1)*(xdiv-1)+1)=1.d0/(dx**2)
A(i+(j-1)*(xdiv-1)+1,i+(j-1)*(xdiv-1))=1.d0/(dx**2)
enddo
enddo
do i=1,(xdiv-1)
do j=1,(ydiv-2)
A(i+(j-1)*(xdiv-1),i+(j)*(xdiv-1))=1.d0/(dy**2)
A(i+(j)*(xdiv-1),i+(j-1)*(xdiv))=1.d0/(dy**2)
enddo
enddo
do i=1,(xdiv-1)
do j=1,(ydiv-1)
xcoord = (i-1)*mesh(1) …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 fortran 写入文本文件。
我做了这个简短的测试程序,但当然它不起作用,因为它不会创建一个可读的文本文件:
PROGRAM teste
INTEGER(4) REC2,RECL1
character(20) :: charI, wanted
RECL1=10
DO REC2=1,10
OPEN(1,FILE='teste.txt',ACCESS="direct",RECL=RECL1);
write (charI, "(A5,I4)") "hello", REC2
wanted=trim(charI)
write(1,REC=REC2) wanted
close(1)
END DO
END PROGRAM teste
Run Code Online (Sandbox Code Playgroud)
我读了很多不同的东西,但仍然不清楚应该如何写。
在写之前我需要转换为字符串吗?如果是为什么?
我想了解如何在 f95 中使用动态内存。
我知道 f2003 中的以下代码有效。
program main
use pippo
implicit none
integer, allocatable :: arr(:)
call createDynamic(arr)
end program main
module pippo
contains
subroutine createDynamic(arr)
implicit none
integer, allocatable,dimension(:)::arr
integer :: i,n
n=10
allocate(arr(n))
do i=1,n
arr(i) = i
end do
end subroutine createDynamic
end module pippo
Run Code Online (Sandbox Code Playgroud)
我想在 f95 中编写一个版本:正确的方法是什么?
Fortran 中具有四次收敛的Borwein 算法的以下实现虽然可以计算 Pi,但收敛得太快了。理论上,a四次收敛到 1/?。在每次迭代中,正确数字的数量因此增加了四倍。
! pi.f90
program main
use, intrinsic :: iso_fortran_env, only: real128
implicit none
real(kind=real128), parameter :: CONST_PI = acos(-1._real128)
real(kind=real128) :: pi
integer :: i
do i = 1, 10
pi = borwein(i)
print '("Pi (n = ", i3, "): ", f0.100)', i, pi
end do
print '("Pi:", 11x, f0.100)', CONST_PI
contains
function borwein(n) result(pi)
integer, intent(in) :: n
real(kind=real128) :: pi
real(kind=real128) :: a, y
integer :: i
y = sqrt(2._real128) …Run Code Online (Sandbox Code Playgroud) 我正在使用F2C (FORTRAN 77 TO C) 将巨大的 FORTRAN 代码转换为 C。我的一个源 FORTRAN 文件有一个 F2C 由于某些原因不喜欢的包含文件。这是扩展名为 .INS 的包含文件 (TAGLINE.INS)(我怀疑扩展名是否重要):
C
C
C*** SCRATCH INPUT DATA FROM FILE FNAM (.RTV = RAW INPUT TAG VALUE)
C
STRUCTURE /STAGRICL/
CHARACTER*76 UFN !! U72 FILENAME.UP.CASE INIT BLANK
CHARACTER*76 RFN ! R72 FILENAME.RAWCASE INIT BLANK
INTEGER*4 LFN ! I4 FILENAME.LENGTH INIT 0
CHARACTER*32 USN !! U32 SECTION-NAME-UP.CASE INIT BLANK
CHARACTER*32 RSN ! R32 SECTION-NAME RAWCASE INIT BLANK
INTEGER*4 LSN ! I4 SECTION-NAME-LENGTH INIT 0
CHARACTER*32 UTN …Run Code Online (Sandbox Code Playgroud)