Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I/O ?'s, read/write 1

Status
Not open for further replies.

bobo12

Programmer
Dec 26, 2004
74
US
please note that u'r responses to my ?'s are critical, i need to finish the fortran-java conversion by next 2 wks, so u'r help is REALLY appreciated!
suppose we have...

1. FORMAT (/' input a FORTRAN-type FORMAT for the data')
READ (*,'(A)') FMAT
ok so something got put into FMAT, what does '(A)' mean?
if i am converting this statement to java, how should i deal with fortran-type formats?

2. so for FORMAT(125A1), i know this prints 125 characters, so what is A1 stand for? A1 is not a variable in my program so what is it?

3.FORMAT (2X,50A1), so 2X is not a variable in my program, what is it? and 50A1, does this mean print 50 characters and A1 part i don't know what it means? so FORMAT is like printf but what is the general idea of a statement like this?

4.FORMAT (I5, F10.2,2F15.2,F14.2), please explain this mess?

u know i tried to google FORMAT and i even have a book here but i just don't understand this code.

5. 28 FORMAT (/' TOTAL TEST:',40X, F8.2);
26FORMAT( //' Summary statistics for subscale', I3)
what's the difference between /' and //'
 
It depends on whether you have formatted data or not.

1. '(A)' is an alternative to a label where the label has FORMAT(A). It is just one character: like getchar in C. Most people are quite lazy on input and just use READ(*,*)

2. A1 means that each item in the array is 1 character. There isn't a printf equivalent. If you have
Code:
CHARACTER*4 xxx(3)
xxx(1) = 'ABCD'
xxx(2) = 'EFGH'
xxx(3) = 'IJKL'
WRITE(*,'(3A1)') xxx
would produce AEI. To print everything use WRITE(*,'(3A4)') xxx

3. X is a space. The format is like a char* in C. 2X,50A1 prints 2 spaces followed by the string which can be up to 50 chars.

4. Not really a mess. In C it is "%5d %10.2f %15.2f %15.2f %14.2f". In F15.2, 15 is the width, 2 is the number of decimal places. F for float, I for integer. 2F15.2 means that there are 2 fields with 15 chars. Note that very often, they use something like 2F15.2 instead of 2(5X,F10.2).

5. / is one line, // is two lines.

Note that in the older versions of Fortran, the first character is for carriage control. A space means newline, a zero means stay on the same line and a 1 means throw a page. So if you see 5X, you only need one space because the first one is carriage control.

Also, the format repeats if it runs out.
 
does the following...
1 READ (*,5)KC
5 FORMAT (125A1)

mean that it's asking for 1 character 125 times, like you have a for loop i=0...124 where at each step you take

KC=character
 
Depends on the implementation. Console input is different on every machine. At a guess, 125A1 is the same as A. Very often it depends on which books the author read, whether they experiment with the language or not and whether they pick up styles from other programs.

If it is F77, you could download FORCE from and try out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top