双precision阵列错误 [英] Double precision array error

查看:218
本文介绍了双precision阵列错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行code的数学算法(共轭梯度法)。在这方面,我输入了双precision矩阵,在我的preamble来定义。编译时,我得到了如下错误:

I'm trying to run code for a mathematical algorithm (Conjugate Gradient method). In doing so I input a double precision matrix, defined as such in my preamble. When compiling, I get the follow error:

A=RESHAPE((/ 0,8,0,4,26,8,0,17.5,0,0,0,17.5,0,2.5,-8,4,0,2.5,0,-5,26,0,-8,-5,0 
                        1
Error: Element in INTEGER(4) array constructor at (1) is REAL(4)
make: FTranProjectBuilder: Error: Execution exited with code 2 
*** [cg_main.o] Error 1

我在与被定义的矩阵程序定义被给定为这样的(数组定义是我的节目的第一操作):

My definition in the program with the matrix being defined is given as such (the array definition is the first operation of my program):

PROGRAM cg_main 
IMPLICIT NONE 

INTEGER,PARAMETER                     ::d=5 !use a parameter for the dimensions (simple)
DOUBLE PRECISION,DIMENSION(d,d)       ::A !matrix
INTEGER,DIMENSION(2)                  ::order2 = (/ 2, 1 /) !matrix reshape order

[MORE DECLARATIONS HERE]

A=RESHAPE((/ 0,8,0,4,26,8,0,17.5,0,0,0,17.5,0,2.5,-8,4,0,2.5,0,-5,26,0,-8,-5,0 /),(/d,d/), order2) !specify dxd matrix

[MORE CODE HERE]

END PROGRAM 

在code作品,未经我的矩阵输入十进制数字,但似乎并没有与我的小数,我不知道为什么。

The code works without the decimal numbers in my matrix input, but doesn't seem to with my decimals and I have no idea why.

推荐答案

Fortran标准(S)的措辞是有点棘手,但他们的意思是阵列从一个数组构造器内置的类型由类型决定在数组构造第一八佰伴pression。这正是该错误消息告诉你。

The wording of the Fortran standard(s) is a little tricky but they mean that the type of an array built from an array-constructor is determined by the type of the first expression in the array-constructor. This is exactly what the error message is telling you.

在您的code除权pression

In your code the expression

 (/ 0,8,0,4,26,8,0,17.5,0,0,0 ...

是一个数组构造函数及其第一八佰伴pression是一个整型常量(默认那种),这样编译器会将此理解为一个整型数组构造和抱怨时,它读取值 17.5 。您可以通过编写你的构造类似这样否则说服编译:

is an array-constructor and its first expression is an integer constant (of default kind) so the compiler understands this to be a constructor for an integer array and complains when it reads the value 17.5. You can convince the compiler otherwise by writing your constructor like this:

 (/ 0.0d0,8,0,4,26,8,0,17.5,0,0,0 ...

这是它的类型是双precision的明确的第一元素。

that is with a first element which is explicitly of type double precision.

如果你有一个Fortran 2003标准的编译器,你也可以这样写:

If you have a Fortran 2003 compliant compiler you can also write:

 (/ double precision :: 0,8,0,4,26,8,0,17.5,0,0,0 ..

这是precede常数与类型声明列表中。

that is, precede the list of constants with a type declaration.

这篇关于双precision阵列错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆