2016-12-22 31 views
-1

這是我的代碼,我試圖編譯格式字符串所需的非負寬度

module vars 
implicit none 


    real*8,dimension(:,:,:),allocatable :: u,v,w 

    real*8,dimension(:),allocatable :: zets 

end module vars 

program post_mean 
    use vars 

    implicit none 

    real*8 rtime,dt,deltax,deltay,rlenz 
    integer itime,nx0,ny0,nz,nzm 

    real*8 pi,pin,hpin,sum,sum1,dum,dum1 
    real*8 aalpha !Need to hardwire aalpha into output 

    integer i,j,k,l,ip,error 

    character (len=32) :: arg,filename,name,dot 
!Range of files to post-process: conc.min to conc.max 
    character (len=32) min, incr, max, i1_str,chr1,zone 
!Integers corresponding to the above range 
    integer i_min, i_incr, i_max, i1 

    chr1 = '00000' 
    dot = '.' 

    call getarg(0,arg) 
    if (iargc().eq.0) then 
    print *,'Usage: ',trim(arg),' filename' 
    stop 
    end if 

    call getarg(2,min) 
    call getarg(3,incr) 
    call getarg(4,max) 
    call getarg(1,arg) 


    read(min, '(i)') i_min 
    read(incr, '(i)') i_incr 
    read(max, '(i)') i_max 

    do i1 = i_min, i_max, i_incr 
    write(i1_str, '(i)') i1 
    filename=trim(arg)//trim(dot)//trim(adjustl(i1_str)) 

    open(21,file=filename,form='binary') 
    read(21) rtime,itime,dt,nx0,ny0,nz,deltax,deltay,rlenz 

    !allocate memory 
    allocate(u(nx0,ny0,nz),stat=error) 
    allocate(v(nx0,ny0,nz),stat=error) 
    allocate(w(nx0,ny0,nz),stat=error) 

    allocate(zets(nz),stat=error) 

    ! reading file 
    print *,'reading file ',filename 
    write(45,*)'reading file ',filename 
    rewind(21) 
    read(21) rtime,itime,dt,nx0,ny0,nz,deltax,deltay,rlenz 
    read(21) u,v,w 
    close(21) 
    write(45,*)'reading file complete',rtime,itime,dt,nx0,ny0,nz 

    !compute grid in the vertical direction 
    pi = 4.d0*atan(1.d0) 
    nzm = nz-1 
    pin = pi/dble(nzm) 

! set aalpha to 0 for GL pts. Alpha aproaches 1 for uniform. Cannot be 1 
     aalpha = 0.99d0 ! Need to hardwire alpha into output 
     do k = 1,nz/2 
     if(aalpha.eq.0)then 
      zets(k) = 0.5d0*rlenz*cos(dble(k-1)*pin) 
      zets(nz+1-k) = -zets(k) 
     else 
      zets(k)=0.5d0*rlenz*asin(aalpha*cos(dble(k-1)*pin))/asin(aalpha) 
      zets(nz+1-k) = -zets(k) 
     endif 
     enddo 
     if (mod(nz,2).eq.1) then 
     k = nz/2 + 1 
     zets(k) = 0.d0 
     endif 

    error = 10 


    ! Zero padding (for a total string length of 6 digits) for zone for easier 
    ! access into tecplot 
    zone = adjustr(trim(chr1)//trim(adjustl(adjustr(i1_str)))) 
    do j=1,15 
     if(zone(7:7).ne.' ')then 
     zone(1:1) = ' ' 
     zone = adjustl(zone) 
     else 
     go to 55 
     endif 
    enddo 
55 continue 

     name = "vel_"//trim(zone)//".dat" 
     open(1,file=name,status='unknown') 
     write(1,*)'tittle="conc"' 
     write(1,*)'variables=x,y,z,u,v,w' 
     write(1,*)'zone t="',trim(zone),'"',',i=',nx0-1,',j=',ny0-1,',k=',nz 
     do k=1,nz 
     do j=1,ny0-1 
      do i=1,nx0-1 
      write(1,26) deltax*(i-1),deltay*(j-1),zets(k)+rlenz/2.d0 & 
       ,u(i,j,k),v(i,j,k),w(i,j,k) 
      enddo 
     enddo 
     enddo 

    enddo 


26 format(6(3x,g25.5)) 
end program 

試圖編譯它,當我得到以下錯誤:

[[email protected] Post_Proc]$ gfortran -c vel_Y2015M09D15.f90 -o vel.x 
vel_Y2015M09D15.f90:45.15: 

    read(min, '(i)') i_min 
       1 
Error: Nonnegative width required in format string at (1) 
vel_Y2015M09D15.f90:46.16: 

    read(incr, '(i)') i_incr 
       1 
Error: Nonnegative width required in format string at (1) 
vel_Y2015M09D15.f90:47.15: 

    read(max, '(i)') i_max 
       1 
Error: Nonnegative width required in format string at (1) 
vel_Y2015M09D15.f90:50.20: 

    write(i1_str, '(i)') i1 
        1 
Error: Nonnegative width required in format string at (1) 
vel_Y2015M09D15.f90:53.40: 

    open(21,file=filename,form='binary') 
             1 
Error: FORM specifier in OPEN statement at (1) has invalid value 'binary' 
+3

這是什麼語言?它看起來不像C或C++。 – NathanOliver

+0

'endo'是至少一個不會出現在c或C++中的單詞,這些標籤必須在這裏引起注意。 –

+0

它是fortran,我應該說我猜 – cnsms

回答

1

在標準的Fortran,格式編輯諸如I,F,E,D,G的描述符都需要寬度。一些編譯器,作爲擴展,可以讓你省略寬度。顯然gfortran不是其中之一。您的gfortran可能支持零寬度的Fortran 2008功能,如I0,這意味着使用該值的最小可能寬度。

FORM ='BINARY'是另一個擴展(來自Microsoft Fortran PowerStation)。 ACCESS ='STREAM'是標準替換。

+0

我已經試過把i0,但它編譯時仍然給我同樣的錯誤。我已經說了i6並且修復了它,但我不確定這是否是正確的方法。對於二進制部分,我需要按照你所說的去做,而不是form = binary有access = stream – cnsms

+0

也許你用的編譯器太老了,不能支持這個功能,但我知道目前的gfortran版本是合理的。一般來說,如果您的編譯器支持此Fortran 2003功能,則可以使用access ='stream'替換form ='binary'。 –

相關問題