- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've had a hard time finding this information and don't even know if it is possible. I'd like to use a format statement, in which spacing will be variable. For example,I'd like to usean integer variable 'nspacer' that would be put in a format statement that will allow me to change the spacing without explicitly writing out the number.
100 format('nspacer'x,'blah blah blah')
Is this possible and if so, what is the type of format (I know the above is wrong) I should use? Ifanyone canhelp me out, I'd really appreciate it. Forgive my ignorance.
Thanks,
CN
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is an example of what you can do.....
Code:
! VARIABLEFORM.f90 ! ! FUNCTIONS: ! VARIABLEFORM - Entry point of console application. ! ! Example of displaying 'Hello World' at execution time. ! !**************************************************************************** ! ! PROGRAM: VARIABLEFORM ! ! PURPOSE: Entry point for 'Hello World' sample console application. ! ! A variable format is constructed in the character array VARFORMAT ! this is used to control a WRITE to the console ! one element of the array will contain an integer multiplier for the ! 'space' indicator 'X'. ! !**************************************************************************** PROGRAM VARIABLEFORMAT IMPLICIT NONE character*8 varformat(8) character*8 openbracket, closebracket, comma, xspace, blanks, BLAH1, BLAH2 CHARACTER*8 multispace character*100 vformat integer*4 ispaces, i, j, istart, iend, length DATA BLANKS/8H / DATA BLAH1, BLAH2/8H'HELLO' , 8H' WORLD'/ ! define parts used to make up the format statement DATA OPENBRACKET, CLOSEBRACKET,COMMA, XSPACE/8H(1H , , 8H ) , 8H, , 8HX / VFORMAT=ADJUSTL(ADJUSTR(VFORMAT)) ! Initialises character variable VFORMAT to all blanks... ! Initialise each element of character array VARFORMAT to contain blanks DO I=1,8 VARFORMAT(I)=BLANKS ENDDO ! construct a sequence of 5 variable formats, increasing the space multiplier by 5 each time DO I=1,5 VARFORMAT(1)=OPENBRACKET ISPACES=5*I WRITE(MULTISPACE,'(I8)') ISPACES !Converts integer in ISPACES to character-string in MULTISPACE VARFORMAT(2)=BLAH1 VARFORMAT(3)=COMMA VARFORMAT(4)=MULTISPACE VARFORMAT(5)=XSPACE VARFORMAT(6)=COMMA VARFORMAT(7)=BLAH2 VARFORMAT(8)=CLOSEBRACKET ! concatenate all the parts of the format into a single character variable ! so that it can be output....each added part is 8 characters long DO J=1,8 VFORMAT(1+(J-1)*8:8+(J-1)*8)=VARFORMAT(J)(1:8) ENDDO WRITE(6,'(A100)') VFORMAT ! Write the whole variable format out.... WRITE(6,varformat) !Then use the variable format... ENDDO end program VARIABLEFORMAT
Message Edited by anthonyrichards on 08-16-2004 05:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can also do as follow:
character(lenmax) spaces
spaces =" "
write(..,100)spaces(1:nspaces)
100 format(a,,'blah blah blah')
character(lenmax) spaces
spaces =" "
write(..,100)spaces(1:nspaces)
100 format(a,,'blah blah blah')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
why don't you use the angle brackets within your format expression:
100 format(x, 'blah, blah blah')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As a variation on Aliho's idea, let me also suggestthe following(brackets are simple but non-standard, internal write is standard but complicated):
Code:
write(*, "(A, BLAH BLAH BLAH)") REPEAT(" ",nSpaces), blah, blah, blahJugoslav
Message Edited by JugoslavDujic on 08-16-2004 04:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you all for your help. Great ideas!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page