2017-07-02 49 views
0

我正在制定計算超音速噴嘴中最小噴嘴長度的程序(特性方法)。我似乎無法找出爲什麼我的代碼不會寫信給我的輸出文件(行「寫(6,1000)......)我的代碼如下:Fortran代碼不會寫入文件

 program tester 
c----------------------------------------------------------------------c 
     implicit real (a-h,o-z) 
     integer count 
     real kminus(0:100),kplus(0:100),theta(0:100),nu(0:100),mach(0:100) 
    +  ,mu(0:100) 
     open (5,file='tester.in') 
     open (6,file='tester.out') 
     read (5,*) me 
     read (5,*) maxturn 
     read (5,*) nchar 
     read (5,*) theta0 
     close(5) 
c.....set count to 0 and calculate dtheta 
     count=0 
     dtheta=(maxturn-theta0)/nchar 
c.....first characteristic 
     do 10 an=1,nchar+1 
     count=count+1 
c........these are already known 
     theta(count)=theta0+dtheta*(an-1) 
     nu(count)=theta(count) 
c........trivial, but we will "calculate" them anyways 
     kminus(count)=2*theta(count) 
     kplus(count)=0 
c........we feed it nu(count) and get m out 
     call pm_hall_approx(nu(count),m) 
     mach(count)=m 
c........does not work with sqrt(...) for some reason 
     mu(count)=atan((1/(mach(count)**2)-1)**0.5) 
     write (6,1000) count,kminus(count),kplus(count),theta(count) 
    +     ,nu(count),mach(count),mu(count) 
    10 continue 
c.....the other characteristics 
     do 30 bn=1,nchar 
     do 20 cn=1,(nchar+1-bn) 
      count=count+1 
c...........these are given 
      kminus(count)=kminus(cn+bn) 
      kplus(count)=-1*kplus(bn+1) 
c...........if this is the last point, copy the previous values 
      if (cn.eq.(nchar+1-bn)) then 
       kminus(count)=kminus(count-1) 
       kplus(count)=kplus(count-1) 
      endif 
c...........calculate theta and nu 
      theta(count)=0.5*(kminus(count)+kplus(count)) 
      nu(count)=0.5*(kminus(count)-kplus(count)) 
c...........calculate m 
      call pm_hall_approx(nu(count),m) 
      mach(count)=m 
      mu(count)=atan((1/(mach(count)**2)-1)**0.5) 
      write (6,1000) count,kminus(count),kplus(count),theta(count) 
    +      ,nu(count),mach(count),mu(count) 
    20 continue 
    30 continue 
     close(6) 
     stop 
1000 format (11(1pe12.4)) 
     end 
c======================================================================c 

     include 'pm_hall_approx.f' 

我的子程序在這裏給出:

 subroutine pm_hall_approx(nu,mach) 
c----------------------------------------------------------------------c 
c  Given a Mach number, use the Hall Approximation to calculate the 
c  Prandtl-Meyer Function. 
c----------------------------------------------------------------------c 
     implicit real (a-h,o-z) 
c.....set constants 
     parameter (a=1.3604,b=0.0962,c=-0.5127,d=-0.6722,e=-0.3278) 
     parameter (numax=2.2769) 
     y=nu/numax 
     mach=(1+a*y+b*y*y+c*y*y*y)/(1+d*y+e*y*y) 
     return 
     end 

這裏是tester.in

2.4  = mache 
5.0  = maxturn 
7  = nchar 
0.375 = theta0 
+0

'tester.in'的內容是什麼? –

+0

加入@ m-chinoune。 CH。謝謝! – rxc370

+0

@ M.Chinoune謝謝! – rxc370

回答

0

在FORTRAN的內容,6號機組被保留用於屏幕切勿使用,作爲單位數量嘗試將其更改爲。一些其他的號碼,如write(7,1000)然後它應該工作。

+0

Fortran不「保留」單元6. – francescalus

+0

@francescalus:可能我不好使用正確的單詞。見[this](http://www.oc.nps.edu/~bird/oc3030_online/fortran/io/io.html)。 – Peaceful

+0

@francescalus,許多編譯器保留單位= 6輸出,只是嘗試'使用iso_fortran_env; print *,output_unit' –