Skip to content

Commit

Permalink
Add a trailing \0 to the end of variable format strings.
Browse files Browse the repository at this point in the history
f2c does not recognize the length of a variable FORMAT string and will
try to read the string until a non-blank appears.

The format strings are declared as `CHARACTER*8` and do not
automatically have a `\0` appended at the end. Therefore, when the
string is filled with blanks until the end, it will read one char over
the end (which is hopefully a non-blank).

This is probably a bug in f2c; however it is not fixed in the recent
versions as well. To work around this, a trailing `\0` is
automatically added by this patch.
  • Loading branch information
olebole committed Oct 27, 2017
1 parent 9590f45 commit f9baf98
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pkg/tbtables/fitsio/ftc2dd.f
Expand Up @@ -20,11 +20,11 @@ subroutine ftc2dd(cval,val,status)

C construct the format statement to read the character string
if (nleng .le. 9)then
write(iform,1000)nleng
1000 format('(F',I1,'.0)')
write(iform,1000)nleng, '\0'
1000 format('(F',I1,'.0)',A)
else
write(iform,1001)nleng
1001 format('(F',I2,'.0)')
write(iform,1001)nleng, '\0'
1001 format('(F',I2,'.0)',A)
end if

read(cval,iform,err=900)val
Expand Down
8 changes: 4 additions & 4 deletions pkg/tbtables/fitsio/ftc2ii.f
Expand Up @@ -17,11 +17,11 @@ subroutine ftc2ii(cval,ival,status)

C construct the format statement to read the character string
if (nleng .le. 9)then
write(iform,1000)nleng
1000 format('(I',I1,')')
write(iform,1000)nleng, '\0'
1000 format('(I',I1,')',A)
else
write(iform,1001)nleng
1001 format('(I',I2,')')
write(iform,1001)nleng, '\0'
1001 format('(I',I2,')',A)
end if

read(cval,iform,err=900)ival
Expand Down
8 changes: 4 additions & 4 deletions pkg/tbtables/fitsio/ftc2rr.f
Expand Up @@ -22,11 +22,11 @@ subroutine ftc2rr(cval,val,status)

C construct the format statement to read the character string
if (nleng .le. 9)then
write(iform,1000)nleng
1000 format('(F',I1,'.0)')
write(iform,1000)nleng, '\0'
1000 format('(F',I1,'.0)',A)
else
write(iform,1001)nleng
1001 format('(F',I2,'.0)')
write(iform,1001)nleng, '\0'
1001 format('(F',I2,'.0)',A)
end if

read(cval,iform,err=900)val
Expand Down

0 comments on commit f9baf98

Please sign in to comment.