Variable Format Expressions not supported?

Hi,

I am trying to run the following code in PGI Visual Fortran. It is using the value of a variable in a FORMAT statement:

integer output_unit
character*() variable_name
integer
2 variable_value
character*(varnamelength) varname

varname=adjustl(variable_name)

write(output_unit,901) varname, variable_value

901 format(a,’ = ',i6)

I am getting the following syntax error:
“Syntax error at or near <”

I can work around this problem by replacing the statement with something like this:
901 format(a25,’ = ',i6)

We like to use variables in FORMAT statements in some cases. In a post from 2007 I read that this was supported in F77 but is not for current versions. Is this still true? The documentation states that this is supported.

I am using PGI Visual FoORTRAN 2008 on Windows Vista.

Thanks,

TomL

Below is a reply related to this topic. I am trying to find out if this is still current or if something is in the works. Good workarounds are also appreciated.

Thanks,

Tom


Posted: Thu Nov 29, 2007 12:23 pm


Hi Catherine,

Unfornately, we currently support only pgf77. If possible, please try to modify your program to be f77 for now. We have filed a TPR# 14158 for pgf90 support.

Thank you,
Hongyon

Hi Tom,

Unfortunately, this feature is still only supported in pgf77. What I would suggest is to build your format string into an character array. It’s a little awkward but more portable. For example:

% cat testme.f90
program testme

character (100) chr

chr = 'TESTME'
call test(chr, 6, 6, 0)

chr = 'TESTME AGAIN'
call test(chr, 12, 12, 0)

end program testme

subroutine test (variable_name, varnamelength, variable_value, output_unit)

integer output_unit
integer varnamelength
character*(*) variable_name
integer*2 variable_value
character*(varnamelength) varname
character(100) frmt

varname=adjustl(variable_name)
write(frmt,*) '(a', varnamelength, ''' = '', i6)'
write(*,frmt) varname, variable_value

end subroutine test
% pgf90 testme.f90 -o testme.out
% testme.out
TESTME =      6
TESTME AGAIN =     12

Hope this helps,
Mat

Thank you, Mat,

this will help. I guess variable formatting is a legacy extension and not in the newer FORTRAN standard. Gnu and Sun don’t seem to support it either. Thanks for the code.

Tom