fortran常见错误

合集下载

Fortran FAQ

Fortran FAQ

1.1 FAQ之常见错误本文从编译错误,链接错误,运行时错误,计算结果错误等四个方面介绍了常见的错误及解决思路。

适合初学者阅读。

首先应该明确:错误有哪几种?我们当前遇到的是何种错误?阐述这些问题前,我们先讨论一下常规的应用程序开发的过程:1>>编写代码,使用一个或多个源代码文件。

2>>对第一步的每一个源代码文件执行编译操作。

得到一个或若干个目标代码。

3>>将目标代码,运行时库(Run-time Library)和其他使用到的函数库链接起来。

得到一个可执行文件(EXE 或其他)4>>编写程序的说明书,必要的(输入)数据文件5>>将上述得到的结果发布给用户。

(发布的方式可以是刻录成光盘,销售,放在网站上供别人下载,或者其他)6>>用户得到程序后,运行,输入数据,得到计算结果。

对于很多Fortran 程序员来说,可能用户就是自己,也可能仅仅是自己教研室的同事同学。

所以第4,5,6步骤很多时候不明显。

而如果使用集成开发环境(IDE)进行开发,第1,2,3步骤又可以一键完成。

因此,很多初学者就认为,写程序就是:输入代码,运行,得到结果。

这样的理解太狭义。

不管我们面对什么使用者来写代码,程序开发应该是上述的过程。

我们的编译器,编译环境,也是为这个过程而设计的。

于是,我们将错误分为四种:一. 编译错误(发生在第2步)编译错误,一般是源代码书写格式不正确,不符合语法要求。

二. 链接错误(发生在第3步)链接错误,一般是源代码结构不完整,运行时库或函数库使用不合理。

三. 运行时错误(发生在第6步)运行时错误,一般是执行代码时,遇到了事先未料及的错误。

比如内存不足了,磁盘空间不够了,输入文件格式不对了,输出文件写入失败了等等。

四. 计算结果不符合预期(程序代码不规范,或不符合你的设想)计算结果不符合预期,可能性就很多了。

语法与你的想法不一致,超出函数库的适用范围,执行流程控制不当等等。

FORTRAN常见错误

FORTRAN常见错误

FORTRAN常见错误41 Insufficient virtual memory 虚拟内存不足70 Integer overflow 整数溢出错误71 Integer divide by zero 整数除0错误72 Floating overflow 浮点数溢出错误73 Floating divide by zero 浮点数除0错误74 Floating underflow 浮点数下溢错误75 Floating point exception 浮点数异常错误77 Subscript out of range 数组定义超出边界95 Floating-point conversion failed 浮点数格式转换失败146 Null pointer error 空指针错误147 Stack overflow 堆栈溢出148 String length error 字符串长度超出允许范围149 Substring error 数组下标超出允许范围150 Range error 整数值超出允许范围151 Allocatable array is already allocated 数组重复定义161 Program Exception - array bounds exceeded 引用数组下标超出允许范围162 Program Exception - denormal floating-point operand 非法浮点数操作符163 Program Exception - floating stack check 浮点数堆栈检查164 Program Exception - integer divide by zero 整数除0错误165 Program Exception - integer overflow 整数溢出166 Program Exception - privileged instruction 非法执行特权指令168 Program Exception - illegal instruction 非法指令170 Program Exception - stack overflow 堆栈溢出540 Array or substring subscript expression out of range 数组下标低下数组定义下界或高于数组定义上界541 CHARACTER substring expression out of range 字符串非法表示542 Label not found in assigned GOTO list 不属于GOTO语句引用的标号543 INTEGER arithmetic overflow 整数运算结果出现溢出544 INTEGER overflow on input 输入的整数值超出允许范围545 Invalid INTEGER 非法整数值546 REAL indefinite (uninitialized or previous error) 产生非法实数547 Invalid REAL 非法实数548 REAL math overflow 实数值溢出549 No matching CASE found for SELECT CASE select case语句中缺少case项550 INTEGER assignment overflow 整数定义超出允许范围556 A edit descriptor expected for CHARACTER 字符型数据的格式化输入和输出需要A编辑符557 E, F, D, or G edit descriptor expected for REAL 实数型数据的格式化输入和输出需要E,F,D,G编辑符558 I edi t descriptor expected for INTEGER 整数型数据的格式化输入和输出需要I编辑符559 L edit descriptor expected for LOGICAL 逻辑型数据的格式化输入和输出需要L编辑符568 Multiple radix specifiers 输入或输出语句重复说明582 Array already allocated 数组已分配583 Array size zero or negative 数组大小为0或负数585 Array not allocated 没有被分配的数组610 Invalid argument 非法参数616 Invalid number in input 输入非法数字617 Invalid string in input 输入非法字符串618 Comma missing in COMPLEX input 输入的多个表达式之间缺少逗号619 T or F expected in LOGICAL read 输入的逻辑值必须是T或F622 Illegal character in hexadecimal input 输入非法的十六进制数637 Integer expected in format 格式语句中要求的整数638 Initial left parenthesis expected in format 格式语句中多余的左括号639 Positive integer expected in format 格式语句中要求用正整数641 Integer expected preceding H, X, or P edi t descriptor 在H、X、P编辑符前要求用整数644 '.' expected in format 在D、E、F、G编辑符中w和d域之间用'.'分隔645 Unexpected end of format 格式语句没有结束646 Unexpected character in format 格式语句中的非法字符647 M field exceeds W field in I edit descriptor 在I编辑符中M域的值大于W域的值648 Integer out of range in format 格式语句中的整数值超出允许范围650 Separator expected in format 格式语句中需要分隔符663 Out of range: substring starting position 'pos' is less than 1 子字符串的起始位置小于1664 Out of range: substring ending position 'pos' is greater than string length 'len' 子字符串的终止位置大于字符串长度672 Out of memory 内存不足718 Cannot allocate temporary array -- out of memory 由于内存不足不能分配临时数组727 Cannot ALLOCATE allocatable array -- out of memory 由于内存不足不能分配数组729 DEALLOCATE failure: ALLOCATABLE array is not ALLOCATED 释放没有被分配的数组。

Visual Fortran常见错误内容

Visual Fortran常见错误内容

Visual Fortran 常见运行错误信息41 Insufficient virtual memory 虚拟内存不足70 Integer overflow 整数溢出错误71 Integer divide by zero 整数除0错误72 Floating overflow 浮点数溢出错误73 Floating divide by zero 浮点数除0错误74 Floating underflow 浮点数下溢错误75 Floating point exception 浮点数异常错误77 Subscript out of range 数组定义超出边界95 Floating-point conversion failed 浮点数格式转换失败146 Null pointer error 空指针错误147 Stack overflow 堆栈溢出148 String length error 字符串长度超出允许范围149 Substring error 数组下标超出允许范围150 Range error 整数值超出允许范围151 Allocatable array is already allocated 数组重复定义161 Program Exception - array bounds exceeded 引用数组下标超出允许范围162 Program Exception - denormal floating-point operand 非法浮点数操作符163 Program Exception - floating stack check 浮点数堆栈检查164 Program Exception - integer divide by zero 整数除0错误165 Program Exception - integer overflow 整数溢出166 Program Exception - privileged instruction 非法执行特权指令168 Program Exception - illegal instruction 非法指令170 Program Exception - stack overflow 堆栈溢出540 Array or substring subscript expression out of range 数组下标低下数组定义下界或高于数组定义上界541 CHARACTER substring expression out of range 字符串非法表示542 Label not found in assigned GOTO list 不属于GOTO语句引用的标号543 INTEGER arithmetic overflow 整数运算结果出现溢出544 INTEGER overflow on input 输入的整数值超出允许范围545 Invalid INTEGER 非法整数值546 REAL indefinite (uninitialized or previous error) 产生非法实数547 Invalid REAL 非法实数548 REAL math overflow 实数值溢出549 No matching CASE found for SELECT CASE select case语句中缺少case项550 INTEGER assignment overflow 整数定义超出允许范围556 A edit descriptor expected for CHARACTER 字符型数据的格式化输入和输出需要A编辑符557 E, F, D, or G edit descriptor expected for REAL 实数型数据的格式化输入和输出需要E,F,D,G编辑符558 I edit descriptor expected for INTEGER 整数型数据的格式化输入和输出需要I编辑符559 L edit descriptor expected for LOGICAL 逻辑型数据的格式化输入和输出需要L编辑符568 Multiple radix specifiers 输入或输出语句重复说明582 Array already allocated 数组已分配583 Array size zero or negative 数组大小为0或负数585 Array not allocated 没有被分配的数组610 Invalid argument 非法参数616 Invalid number in input 输入非法数字617 Invalid string in input 输入非法字符串618 Comma missing in COMPLEX input 输入的多个表达式之间缺少逗号619 T or F expected in LOGICAL read 输入的逻辑值必须是T或F622 Illegal character in hexadecimal input 输入非法的十六进制数637 Integer expected in format 格式语句中要求的整数638 Initial left parenthesis expected in format 格式语句中多余的左括号639 Positive integer expected in format 格式语句中要求用正整数641 Integer expected preceding H, X, or P edit descriptor 在H、X、P编辑符前要求用整数644 '.' expected in format 在D、E、F、G编辑符中w和d域之间用'.'分隔645 Unexpected end of format 格式语句没有结束646 Unexpected character in format 格式语句中的非法字符647 M field exceeds W field in I edit descriptor 在I编辑符中M域的值大于W域的值648 Integer out of range in format 格式语句中的整数值超出允许范围650 Separator expected in format 格式语句中需要分隔符663 Out of range: substring starting position 'pos' is less than 1 子字符串的起始位置小于1664 Out of range: substring ending position 'pos' is greater than string length 'len' 子字符串的终止位置大于字符串长度672 Out of memory 内存不足718 Cannot allocate temporary array -- out of memory 由于内存不足不能分配临时数组727 Cannot ALLOCATE allocatable array -- out of memory 由于内存不足不能分配数组729 DEALLOCATE failure: ALLOCATABLE array is not ALLOCATED 释放没有被分配的数组。

FORTRAN常见错误

FORTRAN常见错误

FORTRAN常见错误41 Insufficient virtual memory 虚拟内存不足70 Integer overflow 整数溢出错误71 Integer divide by zero 整数除0错误72 Floating overflow 浮点数溢出错误73 Floating divide by zero 浮点数除0错误74 Floating underflow 浮点数下溢错误75 Floating point exception 浮点数异常错误77 Subscript out of range 数组定义超出边界95 Floating-point conversion failed 浮点数格式转换失败146 Null pointer error 空指针错误147 Stack overflow 堆栈溢出148 String length error 字符串长度超出允许范围149 Substring error 数组下标超出允许范围150 Range error 整数值超出允许范围151 Allocatable array is already allocated 数组重复定义161 Program Exception - array bounds exceeded 引用数组下标超出允许范围162 Program Exception - denormal floating-point operand 非法浮点数操作符163 Program Exception - floating stack check 浮点数堆栈检查164 Program Exception - integer divide by zero 整数除0错误165 Program Exception - integer overflow 整数溢出166 Program Exception - privileged instruction 非法执行特权指令168 Program Exception - illegal instruction 非法指令170 Program Exception - stack overflow 堆栈溢出540 Array or substring subscript expression out of range 数组下标低下数组定义下界或高于数组定义上界541 CHARACTER substring expression out of range 字符串非法表示542 Label not found in assigned GOTO list 不属于GOTO语句引用的标号543 INTEGER arithmetic overflow 整数运算结果出现溢出544 INTEGER overflow on input 输入的整数值超出允许范围545 Invalid INTEGER 非法整数值546 REAL indefinite (uninitialized or previous error) 产生非法实数547 Invalid REAL 非法实数548 REAL math overflow 实数值溢出549 No matching CASE found for SELECT CASE select case语句中缺少case项550 INTEGER assignment overflow 整数定义超出允许范围556 A edit descriptor expected for CHARACTER 字符型数据的格式化输入和输出需要A编辑符557 E, F, D, or G edit descriptor expected for REAL 实数型数据的格式化输入和输出需要E,F,D,G编辑符558 I edit descriptor expected for INTEGER 整数型数据的格式化输入和输出需要I编辑符559 L edit descriptor expected for LOGICAL 逻辑型数据的格式化输入和输出需要L编辑符568 Multiple radix specifiers 输入或输出语句重复说明582 Array already allocated 数组已分配583 Array size zero or negative 数组大小为0或负数585 Array not allocated 没有被分配的数组610 Invalid argument 非法参数616 Invalid number in input 输入非法数字617 Invalid string in input 输入非法字符串618 Comma missing in COMPLEX input 输入的多个表达式之间缺少逗号619 T or F expected in LOGICAL read 输入的逻辑值必须是T或F622 Illegal character in hexadecimal input 输入非法的十六进制数637 Integer expected in format 格式语句中要求的整数638 Initial left parenthesis expected in format 格式语句中多余的左括号639 Positive integer expected in format 格式语句中要求用正整数641 Integer expected preceding H, X, or P edit descriptor 在H、X、P编辑符前要求用整数644 '.' expected in format 在D、E、F、G编辑符中w和d域之间用'.'分隔645 Unexpected end of format 格式语句没有结束646 Unexpected character in format 格式语句中的非法字符647 M field exceeds W field in I edit descriptor 在I编辑符中M域的值大于W域的值648 Integer out of range in format 格式语句中的整数值超出允许范围650 Separator expected in format 格式语句中需要分隔符663 Out of range: substring starting position 'pos' is less than 1 子字符串的起始位置小于1664 Out of range: substring ending position 'pos' is greater than string length 'len' 子字符串的终止位置大于字符串长度672 Out of memory 内存不足718 Cannot allocate temporary array -- out of memory 由于内存不足不能分配临时数组727 Cannot ALLOCATE allocatable array -- out of memory 由于内存不足不能分配数组729 DEALLOCATE failure: ALLOCATABLE array is not ALLOCATED 释放没有被分配的数组。

fortran常见错误及其原因

fortran常见错误及其原因

fortran常见错误及其原因常见fortran错误1.Incrementally linked image--PC correlation disabled.!编译终止2. forrtl:severe(157):Program Exception - access violationbounds and /warn:argument_checking options set, to see if theproblem is an out-of-bounds memory reference or a argument mismatch that causes data to be treated as anaddress.Other causes of this error include:severe(64):input conversion error, unit 2, file D:\FORTRAN2\testi!文件testi正在读写,直到读写到2时错误。

举例:程序想读写整数,却碰到变量故终止。

4 error LNKZOOI :unresolved external symbol _ SN @ 4 fatal error LNKllZO :1 unresolved externals!出现了未指定的外部函数符号Sn。

这是因为在函数子程序中错把函数名Sn写成了ns。

根据错误信息中的提示,用户在编辑窗口寻找有错位置进行修改。

连接错误往往出现在有函数调用或子程序调用的程序中,常见的错误性质有:未定的函数符号、找不到主程序或子程序、实参与虚参的个数不一致等。

注意:连接错误只给出错误代号和错误性质,不给出具体语句的行号。

5 :: error FOR229O :implicit type for 1 detected between 1 and = C :\ abc.: error FOR33Og :undefined label 10编译系统提示用户:在程序的第5行,变量i未经类型说明;在程序的第H行,标号10未定义。

fortran runtime end of file

fortran runtime end of file

fortran runtime end of file在Fortran编程中,"End of File"是一个常见的错误,通常发生在尝试从一个文件读取数据,但是已经到达文件的末尾时。

当程序尝试读取超出文件末尾的数据时,就会触发这个错误。

为了避免这个错误,你可以在读取文件之前检查是否已经到达文件的末尾。

在Fortran中,你可以使用EOF函数来检查是否到达文件末尾。

EOF函数返回一个逻辑值,如果已经到达文件末尾,那么它返回.TRUE.,否则返回.FALSE.。

下面是一个简单的例子,演示了如何在读取文件时使用EOF函数:fortran复制代码PROGRAM ReadFileIMPLICIT NONEINTEGER :: iosCHARACTER(LEN=100) :: lineOPEN('myfile.txt', STATUS='OLD', IOSTAT=ios)IF (ios /= 0) THENPRINT *, 'Error opening file'STOPEND IFDO WHILE (.NOT. EOF(1))READ(1, *, IOSTAT=ios) lineIF (ios /= 0) EXITPRINT *, lineEND DOCLOSE(1)END PROGRAM ReadFile在这个例子中,程序打开一个名为'myfile.txt'的文件,并在一个循环中逐行读取文件的内容。

每次读取一行之前,它都会检查是否已经到达文件的末尾。

如果已经到达文件的末尾,那么EOF(1)将返回.TRUE.,循环将结束,程序将关闭文件并退出。

如果在读取过程中发生任何错误,程序也会退出。

fortran90常见错误

fortran90常见错误

1、运行fortran时出现forrt1:severe<59>:list-directed I/O syntax error,unit 1,file G:\1\1\meat.dat怎么办这是通道1 ,链接到文件meat.dat 的读写出错了。

这问题你得认真检查类似read( 1 , * ) 或write( 1 , * ) 这样的语句,错误原因挺多的。

比如二进制文件用了文本方式读取,比如变量列表与文件不匹配。

问:另外forrt1:severe<161>:program exception -array bounds exceeded是怎么回事?回答:数组越界,也是很常见的错误。

比如real a(100)如果你使用了a(101) 就会越界,因为a 数组只有100 个元素。

2、fortran运行提示error M6201:math-**,现将代码贴出,求高手帮忙看看,急求解答!我不能确定你的错误是怎么引起的。

可能咱们的编译器不同。

你的代码在我这里的问题是:虚参和实参精度不同。

在程序中,你定义了部分real*8,但是对应的虚参和返回值却定义为real。

比如主程序里的z1(双精度),传入函数g里面的x却定义为单精度。

主程序Do 死循环了。

z2_jiashe 和 z2_suan 每一次循环都没有发生改变,于是永远跳不出循环。

我给你的建议是:同一个程序,统一使用real*8 或real*4,尽量不要混用,除非你很自信能理清他们的关系。

检查Do 循环,尤其是z2_jiashe 和z2_suan,是否应该每次循环不同?fortran_排除错误(2012-04-20 23:22:44)安装好VISUAL FORTRAN后1、运行Developer studio即可开始编译FORTRAN程序2、选择File菜单中的New选项3、在弹出的对话框选择projects标签,其他标签不用管,projects格式选用Fortran console application;在project name里命名(最好英文名),点击“ok ”4、接下来画面中,选择“an empty project”,点击“finish”5、接下来画面点击“ok”6、再选择一次File菜单中的new7、对话框选用files标签,选择Fortran free format source file ,并在file里命名8、点击“ok”数Source Files 放源文件(.c、.cpp)程序的实现代码全放在这里Header Files 放头文件(.h)声明放在这里Resource Files 资源文件(.rc)放图标、图片、菜单、文字之类的,主要用来做界面的东东一般都放这里External Dependencies 除上三种以外的,程序编译时用到的文件全放这里fortran内部函数出错信息解释内部函数出错信息解释[sourcefile(line)]run-time error M62××MATH错误号函数级数学错误信息M6201 functionnames:DOMAIN error函数的自变量超出了约定的取值域,例如sqrt(-1)M6202 functionname:SING error无意义的变量。

fortran常见错误代码

fortran常见错误代码

fortran常见错误代码If you have installed the Parallel Software Environment and compiled a program for parallel execution, additional messages specific to parallel execution may appear (see the DIGITAL High Performance Fortran 90 HPF and PSE Manual).statement specified STATUS= 'NEW '(create new file) using I/O unit x. Make sure correct file name, directory path, unit, and so forth were specified in the source program. Decide whether to:Rename or remove the existing file before rerunning theprogram.Modify the source file to specify different filespecification, I/O unit, or OPEN statement STATUS.severe (19): Invalid reference to variable in NAMELIST inputFOR$IOS_INVREFVAR. One of the following conditions occurred: 19The variable was not a member of the namelist group.An attempt was made to subscript a scalar variable.A subscript of the array variable was out-of-bounds. An array variable was specified with too many or too few subscripts for the variable.An attempt was made to specify a substring of a noncharacter variable or array name.A substring specifier of the character variable wasout-of-bounds.A subscript or substring specifier of the variable was not an integer constant.An attempt was made to specify a substring by using an unsubscripted array variable.20 severe (20): REWIND errorFOR$IOS_REWERR. One of the following conditions occurred:The file was not a sequential file.The file was not opened for sequential or append access. The DIGITAL Fortran 90 RTL I/O system detected an error condition during execution of a REWIND statement.severe (24): End-of-file during readFOR$IOS_ENDDURREA. One of the following conditions occurred:A DIGITAL Fortran 90 RTL I/O system end-of-file conditionwas encountered during execution of a READ statement that did not contain an END, ERR, or IOSTAT specification.An end-of-file record written by the ENDFILE statement was encountered during execution of a READ statement that did not contain an END, ERR, or IOSTAT specification.An attempt was made to read past the end of an internal file character string or array during execution of a READ statement that did not contain an END, ERR, or IOSTATspecification.This error is returned by END and ERRSNS.27 severe (27): Too many records in I/O statementFOR$IOS_TOOMANREC. An attempt was made to do one of the following: Read or write more than one record with an ENCODE or DECODEstatement.Write more records than existed.condition is not one of the more common conditions for which specific error messages are provided. It can occur when an OPEN operation was attempted for one of the following:Segmented file that was not on a disk or a raw magnetic tape Standard I/O file that had been closed31 severe (31): Mixed file access modesFOR$IOS_MIXFILACC. An attempt was made to use any of the following combinations:Formatted and unformatted operations on the same unit An invalid combination of access modes on a unit, such as direct and sequentialA DIGITAL Fortran 90 RTL I/O statement on a logical unit that was opened by a program coded in another language33severe (33): ENDFILE errorFOR$IOS_ENDFILERR. One of the following conditions occurred: The file was not a sequential organization file with variable-length records.The file was not opened for sequential or append access.An unformatted file did not contain segmented records. The DIGITAL Fortran 90 RTL I/O system detected an error during execution of an ENDFILE statement.severe (46): Inconsistent OPEN/CLOSE parametersFOR$IOS_INCOPECLO. Specifications in an OPEN or CLOSE statement 46were inconsistent. Some invalid combinations follow:READONLY or ACTION= 'READ 'with STATUS= 'NEW 'or STATUS='SCRATCH 'READONLY with STATUS= 'REPLACE ', ACTION= 'WRITE ', or ACTION= 'READWRITE 'ACCESS= 'APPEND 'with READONLY, ACTION= 'READ ', STATUS= 'NEW ', or STATUS= 'SCRATCH ' DISPOSE= 'SAVE ', 'PRINT ', or 'SUBMIT 'with STATUS= 'SCRATCH 'DISPOSE= 'DELETE 'with READONLYCLOSE statement STATUS= 'DELETE 'with OPEN statement READONLYACCESS= 'APPEND 'with STATUS= 'REPLACE 'ACCESS= 'DIRECT 'or 'KEYED 'with POSITION= 'APPEND ', 'ASIS ', or 'REWIND 'error (75): Floating point exceptionFOR$IOS_SIGFPE. A floating-point exception occurred. Core dump file created. Possible causes include: Division by zeroOverflowInvalid operation, such as subtraction of infinite values, multiplication of zero by infinity (without signs), division of zero by zero or infinity by infinityConversion of floating-point to fixed-point format when an overflow prevents conversioninfo (95): Floating-point conversion failedFOR$IOS_FLOCONFAI. The attempted unformatted read or write of nonnative floating-point data failed because the floating-point value:Exceeded the allowable maximum value for the equivalentnative format and was set equal to infinity (plus or minus) Was infinity (plus or minus) and was set to infinity (plus or minus) Was invalid and was set to not a number (NaN)Very small numbers are set to zero (0). This error could be caused by the specified nonnative floating-point format not matching the floating-point format found in the specified file.Check the following:The correct file was specified.The record layout matches the format DIGITAL Fortran 90 is expecting.The ranges for the data being used (Chapter 9)The correct nonnative floating-point data format wasspecified (Chapter 10).。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

FAQ之常见错误2014-02-02 13:45:35 来源:Fcode研讨团队评论:2点击:4419本文从编译错误,链接错误,运行时错误,计算结果错误等四个方面介绍了常见的错误及解决思路。

适合初学者阅读。

首先应该明确:错误有哪几种?我们当前遇到的是何种错误?阐述这些问题前,我们先讨论一下常规的应用程序开发的过程:1>>编写代码,使用一个或多个源代码文件。

2>>对第一步的每一个源代码文件执行编译操作。

得到一个或若干个目标代码。

3>>将目标代码,运行时库(Run-time Library)和其他使用到的函数库链接起来。

得到一个可执行文件(EXE 或其他)4>>编写程序的说明书,必要的(输入)数据文件5>>将上述得到的结果发布给用户。

(发布的方式可以是刻录成光盘,销售,放在网站上供别人下载,或者其他)6>>用户得到程序后,运行,输入数据,得到计算结果。

对于很多 Fortran 程序员来说,可能用户就是自己,也可能仅仅是自己教研室的同事同学。

所以第4,5,6步骤很多时候不明显。

而如果使用集成开发环境(IDE)进行开发,第1,2,3步骤又可以一键完成。

因此,很多初学者就认为,写程序就是:输入代码,运行,得到结果。

这样的理解太狭义。

不管我们面对什么使用者来写代码,程序开发应该是上述的过程。

我们的编译器,编译环境,也是为这个过程而设计的。

于是,我们将错误分为四种:一. 编译错误(发生在第2步)编译错误,一般是源代码书写格式不正确,不符合语法要求。

二. 链接错误(发生在第3步)链接错误,一般是源代码结构不完整,运行时库或函数库使用不合理。

三. 运行时错误(发生在第6步)运行时错误,一般是执行代码时,遇到了事先未料及的错误。

比如内存不足了,磁盘空间不够了,输入文件格式不对了,输出文件写入失败了等等。

四. 计算结果不符合预期(程序代码不规范,或不符合你的设想)计算结果不符合预期,可能性就很多了。

语法与你的想法不一致,超出函数库的适用范围,执行流程控制不当等等。

这四种错误,其排查难度依次增大。

也就是,编译错误最容易排查和修改,而计算结果不正确,最让人头疼。

不管是阅读本文,还是在网络上求助,抑或是与其他程序员交流。

首先一定要弄清楚,自己遇到的,是哪一种错误。

如你使用的是 IDE 方式开发,具体不知道是第一种还是第二种错误,应该尝试手动编译代码,手动链接程序,看错误发生在哪一步。

使用一键 Build 可能会让初学者搞不清楚。

对于前三种错误,一定要找到错误提示,这对于你解决问题至关重要!另外需要说明的是,对于同样的错误,不同的编译器给出的提示可能也是不一样的。

下面都以Compaq Visual Fortran 和 Intel Visual Fortran 举例。

其他编译器提示应该类似。

一. 编译错误编译错误经常让初学者感到恐怖,因为动辄几十几百乃至上千个错误。

然而实际上,错误可能并没有那么多。

这是因为编译器对代码进行构析,遇到错误后,会严重影响接下来的分析,导致将本来正确的写法认为是错误。

所以,对于编译错误,一定先解决第一个。

然后重新编译,然后再解决新的第一个。

直到顺利编译为止。

编译错误,在 IDE 环境下一般可通过双击切换到错误所在行。

在命令行下也会显示错误所在的行数。

Q0001:【CVF】Severe: Invalid argument , Error executing df.exe编译错误提示类似于:f90: Severe: Invalid argument... file is 'C:\?D??\fcode.f90'Error executing df.exe原因:这是由于 Compaq Visual Fortran 不支持中文路径下的源代码文件。

源代码文件名作为参数(argument)传递给编译器(df.exe)被认为是非法的(Invalid 因为含有中文)。

解决:将源代码文件放入英文路径下重新编译。

Q0002:【CVF / IVF 】Error spawning df.exe 或 The Fortran compiler (ifort.exe) cannot be found. 原因:这多半是由于编译器安装不合适造成的,或者安装时未设置合理的环境变量。

执行编译器( df.exe 或 ifort.exe ) 失败或根本找不到。

解决:重新安装编译器(win7/win8 下请不要使用 CVF),注意安装时如选择是否设置环境变量,选Yes。

Q0003:【CVF / IVF 】Unrecognized token '?' skipped原因:代码中出现了编译器无法识别的字符。

解决:首先检查自己的源代码文件是否为 ANSI 编码,而不是Unicode编码或其他。

然后检查错误行,是否存在特殊字符?包括除字符串常量和注释行之外的中文。

尤其注意括号,逗号,冒号是否是半角?Q0004:【CVF / IVF 】Syntax error原因:语法错误解决:语法错误的可能性很多,但凡违反语法规定的写法,都可能出这个错误。

认真检查错误行,某些编译器可能会给出更详细的错误提示,翻译一下会更便于查找错误。

Q0005:【CVF / IVF 】Unbalanced parentheses原因:括号不成对出现,例如 a(3))解决:检查错误行的括号,确保成对出现。

Q0006:【CVF / IVF 】An unterminated block exists.原因:If 或 Do 等区块没有结束。

解决:检查 If 是否有 EndIf 对应,Do 是否有 End Do 对应Q0007:【CVF / IVF 】A specification statement cannot appear in the executable section.原因:声明语句出现在了执行语句中解决:所有声明语句必须在所有执行语句前面,即先声明所有变量,然后才有执行语句。

调整这些语句的顺序既可。

Q0008:【CVF / IVF 】The type of the actual argument differs from the type of the dummy argument. [SOME].原因:SOME作为实参,它的的类型与对应的虚参不一致解决:我们建议所有实参与对应的虚参具有相同的类型,精度,大小和数组上下限。

检查一下被提示的变量,其类型精度是否与虚参一致?尤其是没有使用 Implicit None 的程序单元,默认 IN 规则情况下,容易发生类型不一致。

Q0009:【CVF / IVF 】 Cannot open include file '文件名.inc'原因:文件名.inc 做为被包含文件,无法打开解决:1.检查是否存在文件名.inc;2.检查文件名.inc 是否在你的工程目录(文件夹);3.检查该文件是否被隐藏了扩展名,有时候我们看起来是文件名.inc ,其实是文件名.inc.txt,我建议取消隐藏扩展名设置。

方法是打开我的电脑,工具,文件夹选项,查看,取消“隐藏已知文件扩展名”;4.检查该文件是否是 ANSI 编码,用记事本打开,文件另存为时既可查看编码,请确保是ANSI 的,而不是 unicode,utf-8 等;Q0010:【CVF / IVF 】 Recommended relationship between field width 'W' and the number of fractional digits 'D' in this edit descriptor is 'W>=D+3'原因:浮点数格式输出符中,W < D+3。

解决:由于浮点数输出时,需输出至少一位整数,一个小数点,(可能的)一个负号。

所以,建议宽度 W 大于小数点后的 D + 3。

比如 3.1415,格式为 F6.4,6只比4大2,如果遇到负数,就会无法输出负号。

造成 ****** 出现。

注意,这只是一个警告,如果你确定不会有负数,则可以无需干涉。

同理,对于科学计数法,会有 W>=D+7 的要求。

比如 3.1415E+35,格式为 ES10.4,10只比4大6,遇到负号无法输出。

Q0011:【CVF / IVF 】 The statement label ?? is referenced but not defined in this scope.原因:某语句标号的语句被使用了,但没有定义。

比如 goto 100,但没有 100 这句标号的语句。

解决:补齐语句标号语句,或者取消对该标号语句的使用。

二. 链接错误Q1001: unresolved external symbol _SOME / 无法解析的外部符号 _SOME,该符号在函数_MAIN__ 中被引用原因:找不到某些函数或子程序。

如果这些函数或子程序在函数库中,没有正确被使用。

如果 SOME 是数组,可能没有定义为数组,而被编译器误认为是函数。

解决:找到这个函数并添加到工程内,或正确设置函数库并使用,或定义该数组。

Q1002: unresolved external symbol _MAIN__ / 无法解析的外部符号 _MAIN__,该符号在函数 _main 中被引用原因:找不到主程序。

解决:补充主程序。

Q1003:unresolved external symbol _WinMain@16 / 无法解析的外部符号 _WinMain@16__,该符号在函数 _main 中被引用原因:找不到 WinMain 主程序。

WinMain 是 WinGUI 界面工程所需的函数。

解决:如果你不是刻意的开发windows界面程序,请重新选择 console 工程类型。

否则,请补充 WinMain 函数。

Q1004: _MAIN__ already defined in main.obj / _MAIN__ 已经在 main.obj 中定义原因:MAIN 函数已经在 main.obj 文件中定义过。

即,有多个文件中书写了相同名称的函数或主函数。

解决:删除多余的同名函数,或者检查是否重复添加了相同的文件在工程中。

三. 运行时错误请注意,某些编译器编译后的程序,在发生运行时错误时,会弹出VC++ Runtime Library 的警告框。

这是因为这些编译器的 Runtime Library 部分使用了 VC++ 的运行时库。

对于这个警告框,基本上得不到有用的信息某些编译器编译后的程序,在发生运行时错误时,会弹出VC++ Runtime Library 的警告框。

相关文档
最新文档