Question

The code in question is this:

  subroutine PG_TLab_Write(c30,r,d)
  implicit none
  character*30 c30,leftjust
  real*4 r
  integer*4 d,k
  if (d.eq.0) then
    write(c30,'(i30)') nint(r)
  elseif (d.gt.0) then
    write(c30,'(f30.<d>)') r
  else
    k = abs(d)
    write(c30,'(1pe30.<k>') r
  endif
  c30 = leftjust(c30)
  if (d.lt.0) then
    k = index(c30,'E')
    c30 = c30(1:k-1)//'x10\\u'//c30(k+1:24)
  endif
  return
  end

It's really old (bad) code, and I'm not a fortran programmer. The error it gives is the following:

Error: Nonnegative width required in format string at (1) pg-util.f:561.26:

It gives errors on the last 2 write statements in the segment.

My question is how do I make d and k unsigned integers so it will compile?

Was it helpful?

Solution

You can't make d and k unsigned since Fortran does not have unsigned integers.

My guess, assuming that line 561 in the error message refers to the next-to-last line in the snippet you posted, is that the problem is in the variable format expression (the <k> thing). Variable format expressions is an extension to the standard which is not supported by gfortran. See the section about variable format expressions in the gfortran manual for an example how to do the equivalent thing in a standard conforming way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top