imsl7.0中用use linear_operators这句话是会出错的,当时intel论坛上也有人问,后来intel 给出了个X64 imsl的补丁,但是32位的没有。
要使用包含在linear_operators这个库中的函数时,要用use+原函数例如:上面那个例子把use linear_operators改成use operation_xt即可另外,imsl7.0引用函数和以前版本不一样的补充一点:linear_operators这个文件是这样子的(一看就知道原因了):modulelinear_operatorsusecond_intusedet_intusediag_intusediagonals_intusefft_intuseifft_intuseeye_intuselin_eig_self_intuselin_sol_self_intusenorm_intuseoperation_iuseoperation_ixuseoperation_tuseoperation_huseoperation_txuseoperation_hxuseoperation_xuseoperation_xiuseoperation_xtuseoperation_xhuseorth_intuserand_intuserank_intusesvd_intuseunit_intuseeig_intusechol_intuseisnan_intend module1. 如何加大Stack size?选Project => Settings => Link => Category: Output =>Stack allocationsReserve: 这里填新值(默认为1M,若需要10M,则填10000000)2. 如何用Fortran批量生成文件?设要生成4000个文件,文件名为AA1-AA4000,如何写循环生成文件,而不用写4000次write 命令呢?用内部文件:character(len=80) :: filename,forminteger :: idoi=1,4000select case (i)case (1:9)write(form,'(i1)') icase (10:99)write(form,'(i2)') icase (100:999)write(form,'(i3)') icase (1000:9999)write(form,'(i4)') iend selectwrite(filename,*) "AA",trim(form),".TXT"open(10,file=filename)write(10,*) iclose(10)end dostopend3. 如何用Fortran动态生成输出格式?设有一个数组data(100),输出时,希望每行输出num个数,而num由用户输入,如何实现?用内部文件:character(len=80) :: formreal :: data(100)integer :: i,numdata = (/ (i,i=1,100) /)/10.0read(*,*) numwrite(form,*) "(",num,"f10.3)"write(*,form) datastopend4. MS POWERSTATION4.0是不是很垃圾?POWERSTATION4.0是垃圾,其中Bug太多,多到不可用的地步!在这个主题里,换了CVF后问题就没了的人已有相当的数目。
如果你用POWERSTATION4.0,遇到莫名其妙的错误,建议换CVF6.6,这是一个比较成熟的编译器。
5. 如何用F90/95生成随机数?注意:现在计算机产生的随机数都是伪随机数。
random_number(x) 产生一个0到1之间的随机数(x可以是向量),但是每次总是那几个数。
用了random_seed ()后,系统根据日期和时间随机地提供种子,使得随机数更随机了。
program randomimplicit nonereal :: xcallrandom_seed () ! 系统根据日期和时间随机地提供种子callrandom_number (x) ! 每次的随机数就都不一样了write(*,*) xstopend program random6. 函数/子程序超载的例子设要编一个两个变量值互换的子程序swap(a,b),哑元a,b可能是实型数,整型数,数组,矩阵,字符串,派生类型等等。
但是希望只用一个子程序接口swap(a,b)来实现。
F90可以用类属接口来实现这种子程序超载:module Utilitiesimplicit noneprivateI_Swap,R_Swap,RVec_Swap,RMat_Swap,Type_Swappublic :: Swapinterface Swapmodule procedure I_Swap,R_Swap,RVec_Swap,RMat_Swap,Type_Swapend interfacecontainssubroutinei_swap (a,b) ! 整型置换integer (ikind),intent(in out) :: a,binteger (ikind) :: t。
! 略end subroutine i_swapsubroutiner_swap (a,b) ! 实型置换real (rkind), intent(in out) :: a,breal (rkind) :: tt = aa = bb = treturnend subroutine r_swapsubroutineRVec_swap (a,b) ! 实型向量置换real (rkind), intent(in out) :: a(:),b(:)integer (ikind) :: idoi=1, size(a)callR_Swap (a(i),b(i))end doreturnend subroutine RVec_swapsubroutineRMat_swap (a,b) ! 实型矩阵置换。
! 略end subroutine RMat_swapsubroutineType_swap (a,b) ! 派生类型置换。
! 略end subroutine Type_swapend module Utilities7. 如何在CVF中为多行代码加注释?做法:(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的代码文件。
Enjoy!!!VBscript代码:Function FileType (ByVal doc)ext = FileType = 0pos = Instr(ext, ".")ifpos> 0 thenDo While pos<> 1ext = Mid(ext, pos, Len(ext) - pos + 1)pos = Instr(ext, ".")Loopext = LCase(ext)end ifIf ext = ".f90" ThenFileType = 8ElseIfext = ".for" ThenFileType = 9ElseFileType = 0End IfEnd FunctionSub CommentOut ()'DESCRIPTION: 为所选的多行代码加注释Dim winset win = ActiveWindowifwin.type<> "Text" ThenMsgBox "This macro can only be run when a text editor window is active." elseTypeOfFile = FileType(ActiveDocument)If TypeOfFile = 8 OrTypeOfFile = 9 ThenIf TypeOfFile = 8 ThenCommentType = "! "' Fortran 90 fileElseCommentType = "C " ' Fortran 77 fileEnd IfStartLine = ActiveDocument.Selection.TopLineEndLine = ActiveDocument.Selection.BottomLineIf EndLine<StartLine ThenTemp = StartLineStartLine = EndLineEndLine = TempEnd IfIf EndLine = StartLine ThenActiveDocument.Selection.SelectLineActiveDocument.Selection = CommentType + ActiveDocument.Selection ElseFor i = StartLineToEndLineActiveDocument.Selection.GoToLineiActiveDocument.Selection.SelectLineActiveDocument.Selection = CommentType + _ActiveDocument.SelectionNextEnd IfelseMsgBox("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 IfEnd IfEnd SubSub CommentDel ()'DESCRIPTION: 去除所选的多行代码的注释Dim winset win = ActiveWindowifwin.type<> "Text" ThenMsgBox "This macro can only be run when a text editor window is active." elseTypeOfFile = FileType(ActiveDocument)If TypeOfFile = 8 OrTypeOfFile = 9 ThenStartLine = ActiveDocument.Selection.TopLineEndLine = ActiveDocument.Selection.BottomLineIf EndLine<StartLine ThenTemp = StartLineStartLine = EndLineEndLine = TempEnd IfIf EndLine = StartLine ThenActiveDocument.Selection.SelectLineActiveDocument.Selection = mid(ActiveDocument.Selection, 3)ElseFor i = StartLineToEndLineActiveDocument.Selection.GoToLineiActiveDocument.Selection.SelectLineActiveDocument.Selection = mid(ActiveDocument.Selection, 3)NextEnd IfelseMsgBox("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 IfEnd IfEnd Sub8. 推荐好的代码风格根据F90子集语言ELF90和F的要求整理(部分)。