0

Hello! I am having some trouble with some code and needed help. Below is a sample program that hopefully shows what I would like to know. I want to write a program that will specify a FORMAT statement, that will tell the format statement how many times to repeat the format statement. To do this, I will be reading in "cols" from a file that will be different each time, so I need to be able to somehow tell the format statement how many times to repeat. I would think that I could do this by concatenating, but this dosnt work with ifort or gfortran. Ok, so hopefully this is clear, thanks for any help in advance!

PROGRAM test
 
Implicit none

INTEGER                            :: rows,cols
REAL, DIMENSIONS(2),ALLOCATABLE    :: VAR
CHARACTER (len=100), DIMENSIONS(1) :: FMT,colsSTR


cols=12345
rows=12345

ALLOCATE(VAR(rows,cols))

WRITE(colsSTR,'(I20)') cols

FMT = "'("//colsSTR//"F10.2"//")'"


100 FORMAT(FMT)
! 100 FORMAT( '(12345F10.2)' ) !FORMAT STATEMENT THAT I WANT TO GET TO

WRITE(*,100) VAR(1,:)

 
END PROGRAM test

Edited by bgk111: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by engineerik
0

You almost have it.
Just use the variable FMT in your write statement like:

write(*,FMT) var(1, : )

HTH
Erik

Edited by engineerik: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.