Silverfrost Forums

Welcome to our forums

Character variable in format specification statement

13 Jan 2017 9:27 #18699

I have a format specification statement as below:

2400  format(/' Pipe  Load  Dist.   -- Axial force --     Bending mome',
     &       'nt   Stress  ------------ Pressure -----------  System  ',
     &       ' Local'/
     &' name  ',[color=orange]stcase[/color],'   node    design     resi-    design     res',
     &       'i-  param.   ext.  local  coll.  burst conta-   col-  bu',
     &       'ckling'/
     &       '              name              stance              stan',
     &       'ce alpha c    pe    pld     pc     pb  inment   lapse eq',
     &       'ua ratio'/
     &       '               (m)      (kN)      (kN)     (kNm)     (kN',
     &       'm)          (MPa)  (MPa)  (MPa)  (MPa)  ratio   ratio ti',
     &       'on'/)

My stcase is a character variable which can take several values. IS it possible to somehow include that variable in the format 2400?

13 Jan 2017 9:29 #18700

The stacse which I intended colouring it didnøt take up the color. I meant this one:

[color=orange:816a875b90]stcase[/color:816a875b90],

13 Jan 2017 12:26 #18701

You can build up a format string at run time as follows. I am sure that you will need to edit the strings to get the spacings and labels correct, but the main idea is that you can use a character variable as a format string, just as you can use a character constant as a format string.

program TEST
implicit none
character(len=200) :: fmt1
character(len=10) :: stcase
character(len=400) :: fmt2
character(len=600) :: fmt2400
fmt1='(/' Pipe  Load  Dist.   -- Axial force --     Bending mome' // & 
     'nt   Stress  ------------ Pressure -----------  System  ' // & 
     ' Local  name  ,'
stcase='Severe'
fmt2='   node    design     resi-    design     res' // &
     'i-  param.   ext.  local  coll.  burst conta-   col-  bu' // & 
     'ckling'/, ' // &
     ''              name              stance              stan' // & 
     'ce alpha c    pe    pld     pc     pb  inment   lapse eq' // &
     'ua ratio',/ ' // &
     ''               (m)      (kN)      (kN)     (kNm)     (kN' // & 
     'm)          (MPa)  (MPa)  (MPa)  (MPa)  ratio   ratio ti' // &
     'on'/)'
fmt2400=trim(fmt1) // stcase // trim(fmt2)
write(*,fmt2400)
end program
13 Jan 2017 1:56 #18703

Thanks, I did as follows.

character stcase*4

stcase = 'blah'

write(6,2400) stcase

2400 format(/,' S T R E S S   A N A L Y S I S   A C C O R D I N G',
     &       '   T O   ',A4, 'whatever')
Please login to reply.