Code Blocks上的Fortran_Linux Mint

时间:2015-05-30 16:52:40

标签: gfortran

我开始在Fortan中使用代码块进行编程。 我创建了一个控制台应用程序,使用gnu fortran编译器进行编译,当我开始编译时,我得到了这个消息:

  

/ media / aleksandar / HD_2 / Programiranje / Code Blocks / Fortran / Aleksandar / main.f95 | 15 | / media / aleksandar / HD_2 / Programiranje / Code Blocks / Fortran / Aleksandar / main.f95 15 .1:| <登记/>   ||警告:不合格标签字符|
  / media / aleksandar / HD_2 / Programiranje / Code Blocks / Fortran / Aleksandar / main.f95 | 15 | / media / aleksandar / HD_2 / Programiranje / Code Blocks / Fortran / Aleksandar / main.f95 15 .25:|
  ||错误:格式字符串|
中格式字符串的意外结束   || ===构建失败:1个错误,7个警告(0分钟,0秒(秒))=== |

我的代码有什么问题?

这是我的代码:

Program KTO
!Program za sortiranje niza (rastuce i opadajuce vrijednosti)
Implicit none
Integer::i,n,Odabir
Real,dimension(24)::Ppot
Logical::Max
!Otvaranje datoteke sa podacima o potrosnji
!Kad se ucitava kolona na ovaj nacin uvijek ide n+1 broj ucitavanja
!Strogo paziti na ovo
Open(8,File='Ulaz',Status='OLD')   

    Read(8,'(i3,/,25(f5.1,/)')n,(Ppot(i),i=1,n) 

Close(8)
Write(*,'(2x,"Kakvo sortiranje zelite?",//,&
2x,"1 - Opadajuce vrijednosti?",/,&
2x,"2 - Rastuce vrijednost?")')
Read(*,'(i2)') Odabir
If (Odabir.eq.1) then
   Max=.true.
Else
   Max=.false.
End if
Call Sort(n,Ppot,Max)

! Ispis podataka u datoteku
Open(10,File='Izlaz',Status='Unknown')
    Write(10,'(1x,14hSortirani niz:,24(/,f5.1))') (Ppot(i),i=1,n)
Close(10)
Stop
End program KTO
!Potprogram za sortiranje
Subroutine Sort(n,Ppot,Max)
Implicit none
Integer::i,j
Integer,intent(in)::n
Real,dimension(n),intent(inout)::Ppot
Logical,intent(in)::Max
Real::Pom
If (Max.eqv..true.) then
   Do i=1,n-1
       Do j=i+1,n
          If (Ppot(i).lt.Ppot(j)) then
              Pom=Ppot(i)
              Ppot(i)=Ppot(j)
              Ppot(j)=Pom
          End if
       End do
   End do
Else
   Do i=1,n-1
      Do j=i+1,n
         If (Ppot(i).gt.Ppot(j)) then
              Pom=Ppot(i)
              Ppot(i)=Ppot(j)
              Ppot(j)=Pom
         End if
      End do
   End do

End if
Return
End subroutine Sort

1 个答案:

答案 0 :(得分:0)

我用gfortran4.7.2编译了代码。然后正如@albert建议的那样,以下一行证明是错误的:

ng-disabled

如果将其修复为

Read(8,'(i3,/,25(f5.1,/)')n,(Ppot(i),i=1,n)

Read(8,'(i3,/,25(f5.1,/))')n,(Ppot(i),i=1,n)
                        ^--- added this

代码开始运行,但很快就会中止,因为我没有文件&#34; Ulaz&#34;。