Nonnegative width required in format string [dupli

2019-09-19 16:13发布

问题:

This question already has an answer here:

  • Error: Nonnegative width required in format string at (1) 2 answers

This is my code which I am trying to compile

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 

I get the following errors when trying to compile it:

[cnsms@login2.marc1 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'

回答1:

In standard Fortran, format edit descriptors such as I, F, E, D, G all require widths. Some compilers, as an extension, allow you to omit the width. Evidently gfortran is not one of these. Your gfortran probably supports the Fortran 2008 feature of a zero width, such as I0, meaning to use the minimum possible width for the value.

FORM='BINARY' is another extension (from Microsoft Fortran PowerStation). ACCESS='STREAM' is the standard replacement.