fortran 多行注释

fortran 多行注释
fortran 多行注释

fortran 多行注释

你编程序时肯定遇到要一次为很多行代码加注释的情况,以前我都是一行行的加“!”,今天偶然在一个论坛上看到一个解决方案,而且自己按照他的方法,试验了一下,证明切实可行!现与大家分享:

不止一位问道可不可以在visual fortran中为多行代码加注释。

visual fortran本身无这样的功能,但是可以用macro功能自己添!而且是添加工具钮!

做法:

(1) 在..\Microsoft Visual Studio\Common\MSDEV98\MACROS文件夹下生成文件GrpComment.dsm

(2) 用文本编辑器打开该文件,将以下所附的代码贴在其中,保存(注意保留.dsm 后缀)

(3) 启动CVF,选Tools=>Customize=>Add-ins and Macro Files

(4) 在GrpComment前打勾,去掉其他的勾

(5) 在同一对话框中选Commands=>Macros,此时在右边可以看见CommentDel 和CommentOut

(6) 选中CommentOut,拖到CVF的工具栏上去(添加工具钮),会弹出Button Appearance对话框

(7) 选Image and text,在下边Button text框中输入名称(默认是CommentOut),如“加注释”

(8) 类似的方法再将CommentDel命令以工具钮的形式添加到工具栏上,名称可取为“去注释”

这时,工具栏上应该多了两个工具钮:“加注释”和“去注释”。

用法:

加注释:选择要加注释的多行代码,点击“加注释”按钮即可;

去注释:选择已经注释的多行代码,点击“去注释”按钮即可。

适用:后缀为f90或f77的代码文件。

============================================================= VBscript代码:

Function FileType (ByVal doc)

ext = https://www.360docs.net/doc/985398986.html,

FileType = 0

pos = Instr(ext, ".")

if pos > 0 then

Do While pos <> 1

ext = Mid(ext, pos, Len(ext) - pos + 1)

pos = Instr(ext, ".")

Loop

ext = LCase(ext)

end if

If ext = ".f90" Then

FileType = 8

ElseIf ext = ".for" Then

FileType = 9

Else

FileType = 0

End If

End Function

Sub CommentOut ()

'DESCRIPTION: 为所选的多行代码加注释

Dim win

set win = ActiveWindow

if win.type <> "Text" Then

MsgBox "This macro can only be run when a text editor window is active."

else

TypeOfFile = FileType(ActiveDocument)

If TypeOfFile = 8 Or TypeOfFile = 9 Then

If TypeOfFile = 8 Then

CommentType = "! " ' Fortran 90 file

Else

CommentType = "C " ' Fortran 77 file

End If

StartLine = ActiveDocument.Selection.TopLine

EndLine = ActiveDocument.Selection.BottomLine

If EndLine < StartLine Then

Temp = StartLine

StartLine = EndLine

EndLine = Temp

End If

If EndLine = StartLine Then

ActiveDocument.Selection.SelectLine

ActiveDocument.Selection = CommentType + ActiveDocument.Selection

Else

For i = StartLine To EndLine

ActiveDocument.Selection.GoToLine i

ActiveDocument.Selection.SelectLine

ActiveDocument.Selection = CommentType + _

ActiveDocument.Selection

Next

End If

else

MsgBox("Unable to comment out the highlighted text" + vbLf + _

"because the file type was unrecognized." + vbLf + _

"If the file has not yet been saved, " + vbLf + _

"please save it and try again.")

End If

End If

End Sub

Sub CommentDel ()

'DESCRIPTION: 去除所选的多行代码的注释

Dim win

set win = ActiveWindow

if win.type <> "Text" Then

MsgBox "This macro can only be run when a text editor window is active."

else

TypeOfFile = FileType(ActiveDocument)

If TypeOfFile = 8 Or TypeOfFile = 9 Then

StartLine = ActiveDocument.Selection.TopLine

EndLine = ActiveDocument.Selection.BottomLine

If EndLine < StartLine Then

Temp = StartLine

StartLine = EndLine

EndLine = Temp

End If

If EndLine = StartLine Then

ActiveDocument.Selection.SelectLine

ActiveDocument.Selection = mid(ActiveDocument.Selection, 3)

Else

For i = StartLine To EndLine

ActiveDocument.Selection.GoToLine i

ActiveDocument.Selection.SelectLine

ActiveDocument.Selection = mid(ActiveDocument.Selection, 3)

Next

End If

else

MsgBox("Unable to comment out the highlighted text" + vbLf + _ "because the file type was unrecognized." + vbLf + _

"If the file has not yet been saved, " + vbLf + _

"please save it and try again.")

End If

End If

End Sub

fortran语法手册

1 FORTRAN77四则运算符 + - * / ** (其中**表示乘方) 在表达式中按优先级次序由低到高为:+或-→*或/→**→函数→() 2 FORTRAN77变量类型 2.1 隐含约定:I-N规则 凡是以字母I,J,K,L,M,N六个字母开头的,即认为是整型变量,其它为实型变量。 如IMPLICIT REAL (I,J) 三种定义的优先级别由低到高顺序为:I-N规则→IMPLICIT语句→类型说明语句,因此,在程序中IMPLICIT语句应放在类型说明语句之前。 2.4 数组的说明与使用 使用I-N规则时用DIMENSION说明数组,也可在定义变量类型同时说明数组,说明格式为:数组名(下标下界,下标上界),也可省略下标下界,此时默认为1,例: DIMENSION IA(0:9),ND(80:99),W(3,2),NUM(-1:0),A(0:2,0:1,0:3) REAL IA(10),ND(80:99)使用隐含DO循环进行数组输入输出操作:例如WRITE(*,10) ('I=',I,'A=',A(I),I=1,10,2) 10FORMAT(1X,5(A2,I2,1X,A2,I4)) 2.5 使用DATA语句给数组赋初值 变量表中可出现变量名,数组名,数组元素名,隐含DO循环,但不许出现任何形式的表达式:例如 DATA A,B,C/-1.0,-1.0,-1.0/ DATA A/-1.0/,B/-1.0/,C/-1.0/ DATA A,B,C/3*-1.0/CHARACTER*6 CHN(10)

DATA CHN/10*' '/INTEGER NUM(1000) DATA (NUM(I),I=1,500)/500*0/,(NUM(I),I=501,1000)/500*1/ 3 FORTRAN77程序书写规则 程序中的变量名,不分大小写; 变量名称是以字母开头再加上1到5位字母或数字构成,即变更名字串中只有前6位有效; 一行只能写一个语句; 程序的第一个语句固定为PROGRAM 程序名称字符串 某行的第1个字符至第5个字符位为标号区,只能书写语句标号或空着或注释内容; 某行的第1个字符为C或*号时,则表示该行为注释行,其后面的内容为注释内容; 某行的第6个字符位为非空格和非0字符时,则该行为上一行的续行,一个语句最多可有19个续行; 某行的第7至72字符位为语句区,语句区内可以任加空格以求美观; 某行的第73至80字符位为注释区,80字符位以后不能有内容。 4 FORTRAN77关系运算符 .GT. 大于 .GE. 天于或等于 .LT. 小于 .LE. 小于或等于 .EQ. 等于 .NE. 不等于 .AND. 逻辑与 .OR. 逻辑或 .NOT. 逻辑非 .EQV. 逻辑等 .NEQV. 逻辑不等 运算符优先级由高到低顺序为:()→**→*或/→+或-→.GT.或.GE.或.LT. 或.LE.或.EQ.或.NE.→.NOT.→.AND.→.OR.→.EQV.或.NEQV 5 FORTRAN77语句

一些 免费的fortran编译器

一些免费的fortran编译器 https://www.360docs.net/doc/985398986.html,/node/8 Free Fortran Compilers 取自https://www.360docs.net/doc/985398986.html,/compilers/fortran.shtml This page lists free Fortran compilers for various operating systems. Some of the compilers are compliant with the ANSI Fortran 77 specifications, others with Fortran 95, and so on. Some of them may also come complete with debuggers, editors and an integrated development environment (IDE). If you need a book on Fortran, you may want to check out the selection of books available at https://www.360docs.net/doc/985398986.html,. Disclaimer The information provided on this page comes without any warranty whatsoever. Use it at your own risk. Just because a program, book or service is listed here or has a good review does not mean that I endorse or approve of the program or of any of its contents. All the other standard disclaimers also apply. Free Fortran Compilers and IDEs Sun Studio Compilers and Tools Sun Studio Compilers and Tools for Linux and Solaris OS on Sparc and x86/x64 platforms includes command line tools as well as a NetBeans-based IDE for developing, compiling and debugging C, C++ and Fortran programs. It also includes performance analysis tools. Intel Fortran Compiler for Linux

fortran常见问题解决

楼主为了减少重复回答问题,特编此帖,并不定期添加和更新内容。 错误难免,欢迎讨论,仅供参考。 很多人问哪里可以找到Fortran编译器,有不少热心学友提供网址,特汇集在这里。虽然俺检验过这些链接,但是它们不一定总有效。 Fortran编译器下载: CVF? FTN95(License:Freeforpersonaluse) 以下操作,如无特别说明,都是以为例。 1.如何加大Stacksize? 选Project=>Settings=>Link=>Category:Output=>? Stackallocations Reserve:这里填新值(默认为1M,若需要10M,则填) 2.如何用Fortran批量生成文件? 设要生成4000个文件,文件名为AA1-AA4000,如何写循环生成文件,而不用写4000次write 命令呢? 用内部文件: character(len=80)::filename,form integer::i doi=1,4000 selectcase(i) case(1:9) write(form,'(i1)')i case(10:99) write(form,'(i2)')i case(100:999) write(form,'(i3)')i case(1000:9999) write(form,'(i4)')i endselect write(filename,*)"AA",trim(form),".TXT" open(10,file=filename) write(10,*)i close(10)

enddo? stop end 3.如何用Fortran动态生成输出格式? 设有一个数组data(100),输出时,希望每行输出num个数,而num由用户输入,如何实现? 用内部文件: character(len=80)::form real::data(100) integer::i,num data=(/(i,i=1,100)/)/ read(*,*)num write(form,*)"(",num,"" write(*,form)data stop end 4.MS是不是很垃圾? 是垃圾,其中Bug太多,多到不可用的地步! 在这个主题里,换了CVF后问题就没了的人已有相当的数目。 如果你用,遇到莫名其妙的错误,建议换,这是一个比较成熟的编译器。 5.如何用F90/95生成随机数? 注意: 现在计算机产生的随机数都是伪随机数。 random_number(x)产生一个0到1之间的随机数(x可以是向量),但是每次总是那几个数。用了random_seed()后,系统根据日期和时间随机地提供种子,使得随机数更随机了。 programrandom implicitnone real::x callrandom_seed()!系统根据日期和时间随机地提供种子 callrandom_number(x)!每次的随机数就都不一样了 write(*,*)x stop endprogramrandom 6.函数/子程序超载的例子

ABAQUS常见错误与警告信息汇总

*************************错误与警告信息汇总************************* --------------简称《错误汇总》 %%%%%%%%%%%%%%% @@@ 布局 @@@ &&&&&&&&&&&&&&&&&&&&&& AB系列:常见错误信息 C系列:常见警告信息 D系列:cdstudio斑竹总结的fortran二次开发的错误表 E系列:网格扭曲%%%%%%%%%%%%%%%%% @@@@@@ &&&&&&&&&&&&&&&&&&&&&&&&& 模型不能算或不收敛,都需要去monitor,msg文件查看原因,如何分析这些信息呢?这个需要具体问题具体分析,但是也存在一些共性。这里只是尝试做一个一般性的大概的总结。 如果你看见此贴就认为你的warning以为迎刃而解了,那恐怕令你失望了。不收敛的问题千奇万状,往往需要头疼医脚。接触、单元类型、边界条件、网格质量以及它们的组合能产生许多千奇百怪的警告信息。企图凭一个警告信息就知道问题所在,那就只有神仙有这个本事了。一个warning出现十次能有一回参考这个汇总而得到解决了,我们就颇为欣慰了。 我已霸占2楼3楼4楼,以便分类并续加整理。 斑竹可随意编辑或者添加你们觉得合适的条目和链接,其他版友有warning方面的疑问请回复到这个帖子,大家集思广益,斑竹们也可以集中讨论并定期汇总到1-4楼。 类似于: Fixed time is too large Too many attamps have been made THE SOLUTION APPEARS TO BE DIVERGING. CONVERGENCE ISJUDGED UNLIKELY. Time increment required is less than the minimum specified 这样的信息几乎是无用信息(除了告诉你的模型分析失败以外,没有告诉你任何有用的东西)。宜再查找别的信息来考察。根据经验,改小增量步也不一定能收敛,虽然也有人报告过改好的先例,我是从来没有遇到过,也从来没有那个奢望。所以我一般从模型的设置入手。原则上本贴只欢迎以下回帖: 1)你出现了已经解决的错误信息or解决不了的错误信息,可以回帖附上信息,并对模型和症状加以描述(斑竹会酌情加分); 2)你发现某个帖子有已经解决的错误信息or解决不了的错误信息, 可以提供链接(斑竹会加分); 3)你发现某一条错误信息可能还存在别的情况or别的应对方案, 可以回帖说明(斑竹会加分) 必须说明的是:Error和warning的性质是完全不同的。Error意味着运算失败,but出现warning可能还能算,而且有些运算必定会出现warning(比如接触分析必定出“负特征值”,下有详述)。很多警告只是通知性质的,或者只是说明一下而已,不一定都是模型有问题。比如以下warning完全可以忽略: xxxxx will (not)printed,这种只是通知你一声,某些玩意儿不输出了。还有: The parameter frequency cannot be used with the parameter field. It will be ignored(都说某某被ignored了).

FORTRAN 90 程序编程规范

FORTRAN 90 程序编程规范 Fortran 90 编程规范,使程序代码高度组织化,更加易读、易懂、易于维护,程序更加高效。使编出的程序更易懂、易于维护。 1 语言选择 数值预报创新系统软件开发应避免使用Fortran77 的某些过时特征以Fortran 90不一致的特征。选择Fortran 90 作为开发语言,并采用Fortran 90 的新功能,如动态内存的分配(dynamic memory allocation)、递归(recursion ), 模块(modules)、POINTER 、长变量名、自由格式等。 Fortran 77其中某些只是一些冗余的功能,这些功能已经过时,另外,还有一些在Fortran90 中被证明是不好的用法,建议不要使用。 2 Fortran 90 的新特性 2.1.1 建议使用的Fortran 90 新特性 建议使用Fortran 90 提供的模块(module ),并用Use ONLY 指定module 中哪些变量或派生类型定义可用于调用程序。 尽量使用数组下标三元组,这样可优化并减少所需的代码行数。为提高可读性,要在括号内表明数组的维数,例如: 1dArrayA(:) = 1dArrayB(:) + 1dArrayC(:) 2dArray(: , :) = scalar * Another2dArray(: , :) 当访问数组的子集时,例如在有限差分等式中,可以通过使用下标三元组实现。例如:2dArray(: , 2:len2) = scalar *( & Another2dArray(:, 1:len2 -1) & - Another2dArray(:, 2:len2) & ) 对程序单元(program units )命名,并使用End program ,End subroutine ,End interface ,End module 等结构再次指定“program unit ”的名称。 在逻辑表达式中使用>、 >=、 ==、 <、 <=、 /=,它们分别代 替.gt.、.ge.、.eq.、.lt.、.le.、.ne. 。新的表示方法更接近标准的数学符号 在变量定义中始终使用“::”;始终用“DIMENSION ”定义数组形状;始终用(len=)的语法格式声明字符变量的长度。

fortran常见错误

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步) 运行时错误,一般是执行代码时,遇到了事先未料及的错误。比如内存不足了,磁盘空间不够了,输入文件格式不对了,输出文件写入失败了等等。 四. 计算结果不符合预期(程序代码不规范,或不符合你的设想) 计算结果不符合预期,可能性就很多了。语法与你的想法不一致,超出函数库的适用范围,执行流程控制不当等等。 这四种错误,其排查难度依次增大。也就是,编译错误最容易排查和修改,而计算结果不正确,最让人头疼。

Fortran常用函数

1、RANDOM_NUMBER Syntax ['sint?ks] n. 语法 CALL RANDOM_NUMBER (harvest结果) Intrinsic Subroutine(固有子程序):Returns a pseudorandom number greater than or equal to zero and less than one from the uniform distribution. 返回大于或等于0且小于1,服从均匀分布的随机数 2、RNNOA/ DRNNOA (Single/Double precision) Generate pseudorandom numbers from a standard normal distribution using an acceptance/rejection method. 产生服从标准正态分布的随机数 Usage(用法) CALL RNNOA (NR, R) Arguments(参数) NR— Number of random numbers to generate. (Input) 要产生随机数的个数 R— Vector of length NR containing the random standard normal deviates. (Output) 输出长度为NR,随机正态分布的向量 Comments(注解) The routine RNSET can be used to initialize the seed of the random number generator. The routine RNOPT can be used to select the form of the generator. 程序RNSET可以用来初始化随机数发生器的种子 Example In this example, RNNOA is used to generate five pseudorandom deviates from a standard normal distribution. INTEGER ISEED, NOUT, NR REAL R(5) EXTERNAL RNNOA, RNSET, UMACH C CALL UMACH (2, NOUT) NR = 5 ISEED = 123457 CALL RNSET (ISEED) CALL RNNOA (NR, R) WRITE (NOUT,99999) R 99999 FORMAT (' Standard normal random deviates: ', 5F8.4) END Output Standard normal random deviates: 2.0516 1.0833 0.0826 1.2777 -1.2260

ADINA常见问题解答

ADINA常见问题解答 一般问题 Q:怎样改进ADINA-AUI 中实体的显示效果? A:在某些情况下,ADINA-AUI 显示的实体在边界上不光滑,这仅仅是显示的问题,并不影响几何尺寸的精确度。为了改进显示的效果, 1 点击Modify Mesh Plot 。 2 点击Line Depiction 。 3 将ADINA-M Chord Angle 由默认的0.4改为0.1 并且点击OK。 4 点击Surface Depiction 。 5将ADINA-M Chord Angle 由默认的0.4改为0.1 并且点击OK。 6 点击OK,关闭Modify Mesh Plot 对话框。 Q:为什么AUI 的图形功能在我的计算机上不能正常的工作? A:有些计算机的显卡在Open GL 图形系统中不能正常的工作。请切换到Windows GDI 图形系统,在Edit 菜单中,点击Graphics System ,然后选择Windows GDI 图形系统。 Q:当我从ADINA-AUI 打印文件时,为什么打印不出来任何结果? A:注意只有Windows 版本才会发生这样的问题。 当使用Open GL 图形方式时,有的打印机会出现上述问题。为解决该问题,当打印的时候,选择Windows GDI 图形方式。从菜单Edit > Graphics System…中选择Windows GDI 作为图形系统,然后开始打印。注意打印结束后,可以将图形系统切换回Open GL 以便获得更快的图形效果。 Q:为什么安装了浮动License(Floating Industry或者Floating Educational)后,Adina无法启动? A:如果安装过程正确,而且电脑上的防火墙不阻止Adina读取服务器上的License,那么这样的问题一般是由于计算机使用了中文名。不论是Adina的服务器还是Adina客户端,都不允许使用中文计算机名。 Q:如何将壳单元厚度显示出来? A:在Display-->Geometry/Mesh Plot-->Modify打开的窗口中点击Element Depiction,在新打开的窗口中的Shell Element Attributes域中选择Top/Bottom(默认是Mid-Surface)。 有关界面启动 Q:怎样在Windows 版本中以批处理的方式运行ADINA? A:在Windows 版本中,ADINA 常常是在交互方式下运行。然而,有时为了连续进行几项作业,则必须在批处理方式下运行。 以批处理方式运行ADINA-AUI 的命令为: ...\aui.exe -b -m [b|w] .[in|plo] 这里…\ 是指aui.exe 的全路径名。 值可以用bytes(b) 或者 words(w) 来定义。1 word = 4 bytes 。 例如,在批处理方式下运行prob02.in 文件,并且分配20Mb 内存(假设aui.exe 安装在c:\adina\bin) ,命令行就是: c:\adina\bin\aui.exe -b -m 20mb prob02.in 注意在定义 值时,m 可以是m(Mega)、k(Kilo)、g(Giga) 。 选项-b的含义是用adina-aui读一遍命令流,但是不打开adina-aui(如果命令流中有生成dat文件的命令行,则会自动生成一个dat文件。)。如果不用-b选项,会看到打开adina-aui,并且打开模型。批处理方式下运行ADINA 求解器的命令行是: ...\.exe -b -s -m [b|w] -M [b|w] -t <#cpu> .dat 这里.exe 是adina、adinaf、adinat、adfsi或者adtmc ,…\ 是指.exe 的全路径名。 是分配给sparse solver 内存值,<#cpu> 定义了cpu 的数目。 例如,在批处理方式下运行prob02.dat 文件,分配10Mw 的内存给ADINA求解器,分配100Mw 的内存给sparse solver ,使用2个cpu ,命令行如下所示(假设adina.exe 安装在c:\adina\bin ): c:\adina\bin\adina.exe -b -s -m 10mw -M 100mw -t 2 prob02.dat 选项-b和-s是为了保证求解完成后自动关掉求解器窗口。 以下是当ADINA安装在c:\adina目录下时,顺序求解两个模型(prob02.in和prob03.in)的批处理文

Fortran常见错误

fortran运行常用错误(转) (2006-11-1010:18:44) 转载▼ 分类:分子动力学 41Insufficient virtual memory虚拟内存不足 70Integer overflow整数溢出错误 71Integer divide by zero整数除0错误 72Floating overflow浮点数溢出错误 73Floating divide by zero浮点数除0错误 74Floating underflow浮点数下溢错误 75Floating point exception浮点数异常错误 77Subscript out of range数组定义超出边界 95Floating-point conversion failed浮点数格式转换失败 146Null pointer error空指针错误 147Stack overflow堆栈溢出 148String length error字符串长度超出允许范围 149Substring error数组下标超出允许范围 150Range error整数值超出允许范围 151Allocatable array is already allocated数组重复定义 161Program Exception-array bounds exceeded引用数组下标超出允许范围162Program Exception-denormal floating-point operand非法浮点数操作符163Program Exception-floating stack check浮点数堆栈检查 164Program Exception-integer divide by zero整数除0错误 165Program Exception-integer overflow整数溢出 166Program Exception-privileged instruction非法执行特权指令 168Program Exception-illegal instruction非法指令 170Program Exception-stack overflow堆栈溢出

FORTRAN知识点总结

F O R T R A N 第2章FORTRAN90基础知识: 程序单元的概念: fortran90程序是一种分块形式的程序,整个程序由若干程序单元块组成。每个程序只有一个主程序单元。各单元体的程序体形式上相同。 程序单元可以是主程序、子程序(外部过程或内部过程)、模块MODULE (供其他程序单元引用即把该程序单元内的全部语句复制到程序单元中)或块数据程序单元BLOCK 。 语言元素:指在程序设计中用到的基本成分,如字符集、常量、变量、记号(标号、关键字、名字、常数、运算符和定界符)以及其他的基本结构等。 字符集:英文字母、阿拉伯数字、下划线、21个特殊字符($和?没有规定用法)。 数据结构: 整型INTEGER (34-2下划线后面是种别参数),n 位字长的计算机的数据表示范围一般为12~211-+---n n ,种别参数由内在询问函数KIND 送回,种别值提供的最小范围由内在函数SELECTED-INT-KIND 送回,表示十进制幂的范围由内在函数RANGE 送回; 实型REAL ,小数形式和指数形式;复型COMPLEX (种别类

型参数值取实部与虚部中较大者); 字符型CHARACTER,由一对单撇号或双撇号之间的字符序列组成; 逻辑型LOGICAL。 派生数据类型TYPE; 数组INTEGER,DIMENSION(1,50)::A,可直接对数组元素进行运算如3*A,SQRT(A); 字符子串,在字符串CHARACTER(LEN=80)::ROW中,ROW(1:3)就表示字符串ROW中第1到第3个元素组成的子串。 变量名的命名规则:不能超过31个字符;组成成分是字母、数字、下划线;第一个字符必须是字母。 第3章基本语句: 类型说明语句:类型说明(种别说明),属性说明::变量名表 尽量避免把两个实数作相等或不相等的比较。淘汰隐式说明IMPLICIT NONE 种别说明:种别参数即对可移植数据精度和范围进行选择的机制 KIND(X) 返回变元X的种别参数值 SELECTED-REAL-KIND(n,m) 产生一个种别值,它表示某一精度和范围。N指十进制有效位数,m指明值范围内以10为底的幂次。

fortran心得

Read 的规则: 按行读取,每次读一行,读完后光标自动跳到下一行的开头,空格和逗号代表结束(所以空格和逗号也是读取的一部分的话,需要使用“输入输出格式”) 如果想要将一行数据读入数组,代码为: Read(10,*) s(:,:,:) 不用规定输入输出格式,因为会根据s(:,:,:)确定需要读入的数字的个数,然后fortran会按部就班的读取,甚至文件中当前这一行的数字个数不足以填满s(:,:,:)的时候,read会自动跳到下一行继续搜索数字,直到填满s(:,:,:)为止。 但是需要注意给数组赋值的顺序:read会把它搜索到的第一个数字给s(1,1,1),第二个给s(2,1,1),第三个给s(3,1,1)… 程序9 1: 将read(unit=field,fmt="(A79)",iostat=status)buffer 中的A79改为A2,结果只输出每行的前两个字符,说明read是按整行整行读取的。 中间空了几行之后,空行之后的内容还是能被读取和输出,这说明,空行和空白是不一样的:空行也算是一种文本内容,因此不会终止读取,而空白意味着结束。 !读取文件 program main implicit none character(len=79)::filename="number.txt",buffer integer,parameter::field=10 integer::status=0 logical alive inquire(file=filename,exist=alive) if(alive)then open(unit=field,file=filename) do while(.true.) read(unit=field,fmt="(A79)",iostat=status)buffer if(status/=0)exit write(*,"(A79)")buffer end do else write(*,*)filename,"does't exist." end if pause stop end program main ============================================= 附number.txt =============================== 1234555666

Fortran 运行中给出的系统错误及解决方法

. Fortran 运行中给出的系统错误及解决方法 以下均为linker tools errors and warnings Linker Tools Error LNK1000 unknown error; consult documentation for technical support options Note the circumstances of the error, try to isolate the problem and create a reproducible test case, then contact technical support. Linker Tools Error LNK1101 incorrect MSPDBxx.DLL version; recheck installation of this product The version of MSPDBxx.DLL available on your system does not match the version required by this tool. Linker Tools Error LNK1102 out of memory There was not enough memory for the tool to run. Probably the paging file exceeded available disk space. If a shortage of disk space is not the cause, note the circumstances of the error, try to isolate the problem and create a reproducible test case, then request technical support. Linker Tools Error LNK1103 debugging information corrupt; recompile module Probably the compilation was terminated before a valid object file was created.Recompile the given object file. If recompiling does not correct the problem,note the circumstances of the error, try to isolate the problem and create a reproducible test case, then consult technical support. Linker Tools Error LNK1104 cannot open file "filename" The tool could not open the given file. One of the following may be a cause: l There was not enough disk space. l The file does not exist. l The filename or its path was incorrectly specified. l The specified drive is invalid. l The file does not have the appropriate permissions. l The path for filename expands to more than 260 characters. l If the given file is named LNKn, which is a filename generated by the linker for a temporary file, then the directory specified in the TMP environment variable may not exist, or more than one directory is specified for the TMP environment variable. (Only one directory path should be specified for the TMP environment variable.) l If the error occurs on the executable filename, an earlier version of the executable may still be running. You will need to terminate the executable before linking it. In Windows NT (including Windows 2000) or Windows 95,you can use the utility PVIEW to look for and kill instances of the application. l If the error message occurs for a library name, and you recently ported the .MAK file from a previous Microsoft Visual C++ development

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或负数

fortran语法手册

1F O R T R A N77四则运算符+ - */ ** (其中**表示乘方) 在表达式中按优先级次序由低到高为:+或-→*或/→**→函数→() 2 FORTRAN77变量类型 隐含约定:I-N规则 凡是以字母I,J,K,L,M,N六个字母开头的,即认为是整型变量,其它为实型变量。 如IMPLICIT REAL (I,J) 三种定义的优先级别由低到高顺序为:I-N规则→IMPLICIT语句→类型说明语句,因此,在程序中IMPLICIT语句应放在类型说明语句之前。 数组的说明与使用 使用I-N规则时用DIMENSION说明数组,也可在定义变量类型同时说明数组,说明格式为:数组名(下标下界,下标上界),也可省略下标下界,此时默认为1,例:DIMENSION IA(0:9),ND(80:99),W(3,2),NUM(-1:0),A(0:2,0:1,0:3) REAL IA(10),ND(80:99)使用隐含DO循环进行数组输入输出操作:例如 WRITE(*,10) ('I=',I,'A=',A(I),I=1,10,2) 10FORMAT(1X,5(A2,I2,1X,A2,I4)) 使用DATA语句给数组赋初值 变量表中可出现变量名,数组名,数组元素名,隐含DO循环,但不许出现任何形式的表达式:例如 DATA A,B,C/,, DATA A/,B/,C/ DATA A,B,C/3*CHARACTER*6 CHN(10) DATA CHN/10*''/INTEGER NUM(1000) DATA (NUM(I),I=1,500)/500*0/,(NUM(I),I=501,1000)/500*1/ 3 FORTRAN77程序书写规则

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编

相关文档
最新文档