fortran77 's input format, and how to, in linux, plz help
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
fortran77 's input format, and how to, in linux, plz help
Dear linux fortran 77 programers/experts:
I borrow a numerical analysis book from my city's library, (Carnahan 's (applied numerical methods) published 1969 by son john wily), I tried to copy in/test the first chapter, first example, example 1.1
on my gfortran on linux
I found I have difficult to insert input data, after I rund ./a.out
the input data, according to that book, is in page 24
I only can type in first 2 rows, then the program response(for one line of title, that's it, no numerical data as output)
please help, thanks your effort a lot in advance, Eric
/* you might show some link/url/discussing forum about fortran77 and numerical analysis */
Script started on Sun 09 Aug 2015 10:38:39 AM PDT
]0;eric@ubuntu: ~/fortranprogramseric@ubuntu:~/fortranprograms$ cat d1_1
8 6
0.0000 0.20000 0.30000 0.40000 0.60000
0.7000 0.9000 1.0000
0.25 1
0.25 2
0.2500 3
0.2500 4
0.2500 5
0.2500 6
0.4500 1
0.4500 2
0.4500 3
0.0500 1
0.0500 2
0.0500 3
0.9500 1
0.9500 2
0.9500 3
0.1000 4
-0.100 4
0.5500 7
1.1000 1
2.000 1
2.0000 1
2.0000 2
2.0000 3
2.0000 4
2.0000 5
2.0000 6
]0;eric@ubuntu: ~/fortranprogramseric@ubuntu:~/fortranprograms$ ./a.out < d1_1
At line 19 of file example1_1.f (unit = 5, file = 'stdin')
Fortran runtime error: Bad value during floating point read
]0;eric@ubuntu: ~/fortranprogramseric@ubuntu:~/fortranprograms$ exit
exit
Script done on Sun 09 Aug 2015 10:39:04 AM PDT
-----------------------------------------------------------------------------------------------------------------------
if I typed in by hand of that d1_1 at ./a.out
again , after 2 line, it will response
/*------------------- */
Script started on Sun 09 Aug 2015 10:42:20 AM PDT
]0;eric@ubuntu: ~/fortranprogramseric@ubuntu:~/fortranprograms$ ./a.out
8 6
0.0 0.2 0.3 0.4 0.6 0.7 0.9 1.0
At line 19 of file example1_1.f (unit = 5, file = 'stdin')
Fortran runtime error: Bad value during floating point read
]0;eric@ubuntu: ~/fortranprogramseric@ubuntu:~/fortranprograms$ ./a.out
8 6
0.0 0.2 0.3 0.4 0.6
1THE SAMPLE FUNCTIONAL VALUES ARE
0 I, X(I) Y(I)
/**-----------------------------------------------------------------------------------**/
so please help,
why its read and its format is hard to correspond my input format?
Eric
C Applied Numerical Methods, Example 1.1
C NEWTON'S DIVIDED-DIFFERENCE INTERPOLATING POLYNOMIAL
C
C TEST PROGRAM FOR THE SUBROUTINE DTABLE AND THE FUNCTION
C FNEWT. THIS PROGRAM READS A SET OF N VALUES X(1)...X(N),
C COMPUTE A CORRESPONDING SET OF VALUES Y(1)...Y(N) WHERE
C Y(1)=COS(X(1)), AND THEN CALLS ON SUBROUTINE DTABLE
C TO CALCULATE ALL FINITE DIVIDED DIFFERENCES OF ORDER M OR
C LESS. WITH THE DIVIDED DIFFERENCES STORED IN MATRIX TABLE,
C THE PROGRAM READS VALUES FOR XARG, THE INTERPOLATION
C ARGUMENT, AND IDEG, THE DEGREE OF THE INTERPOLATING
C POLYNOMIAL TO BE EVALUATED BY THE FUNCTION FNEWT.
C FNEWT COMPUTES THE INTERPOLANT VALUE, YINTER, WHICH IS
C COMPARED WITH THE TRUE VALUE, TRUVAL = COS(XARG).
C
DIMENSION X(20), Y(2), TABLE(20, 20)
C
C ..... READ DATA, COMPUTE Y VALUES, AND PRINT .....
READ (5,100) N, M, (X(I), I=1,N)
WRITE (6, 200)
DO 1 I=1,N
Y(I) = COS(X(I))
1 WRITE (6,201) I, X(I), Y(I)
C
C ..... COMPUTE AND PRINT DIVIDED DIFFERENCES .....
CALL DTABLE( X,Y,TABLE,N,M,TRUBL,20 )
IF (TRUBL.NE.0.0) CALL EXIT
WRITE (6,202) M
NM1 = N - 1
DO 6 I=1,NM1
L = 1
IF (I.GT.M) L = M
6 WRITE (6,203) (TABLE(I,J), J=1,L)
C
C ..... READ XARG AND IDEG, CALL ON FNEWT TO INTERPOLATE ....
WRITE (6,204)
7 READ(5,101) XARG, IDEG
YINTER = FNEWT( X,Y,TABLE,N,M,IDEG,XARG,TRUBL,20 )
C
C ..... COMPUTE TRUE VALUE OF COS(XARG) AND PRINT RESULTS ......
TRUVAL = COS(XARG)
WRITE (6,205) XARG, IDEG, YINTER, TRUVAL, TRUBL
GO TO 7
C
C ..... FORMATS FOR INPUT AND OUTPUT STATEMENTS .....
100 FORMAT ( 4X, I3, 10X, I3 / (15X, 5F10.4) )
101 FORMAT ( 7X, F8.4, 13X, I3 )
200 FORMAT ( 33h1THE SAMPLE FUNCTIONAL VALUES ARE / 5H0 I, 8X,
1 4HX(I), 9X, 4HY(I) / 1H )
201 FORMAT ( 1H, I4, 2F13.6 )
202 FORMAT ( 8H1FOR M = , I2, 29H, THE DIVIDED DIFFERENCES ARE )
203 FORMAT ( 1H / (1H, 8E16.7) )
204 FORMAT ( 25H1THE DATA AND RESULTS ARE / 1H0, 5X, 4HXARG, 5X,
1 4HIDEG, 5X, 6HYINTER, 6X, 6HTRUVAL, 3X, 5HTRUBL / 1H )
205 FORMAT ( 1H, F9.4, I8, 2F12.6, F7.1 )
C
END
SUBROUTINE DTABLE ( X,Y,TABLE,N,M,TRUBL,K )
C
C DTABLE COMPUTES THE FINITE DIVIDED DIFFERENCES OF
C Y(1)...Y(N) FOR ALL ORDERS M OR LESS AND STORES THEM IN
C THE LOWER TRIANGULAR PORTION OF THE FIRST M COLUMNS OF THE FIRST
C N-1 ROWS OF THE MATRIX TABLE. FOR INCONSISTENT ARGUMENTS,
C TRUBL = 1.0 ON EXIT. OTHERWISE, TRUBL = 0.0 ON EXIT.
C
DIMENSION X(N), Y(N), TABLE(K, K)
C
C ..... CHECK FOR ARGUMENT CONSISTENCY
IF (M.LT.N) GO TO 2
TRUBL = 1.0
RETURN
C
C ...... CALCULATE FIRST=ORDER DIFFERENCES .....
2 NM1 = N - 1
DO 3 I=1,NM1
3 TABLE(I,1) = (Y(I+1) - Y(I))/(X(I+1) - X(I))
IF (M.LE.1) GO TO 6
C
C ...... CALCULATE HIGHER-ORDER DIFFERENCES .....
DO 5 J=2,M
DO 5 I=J,NM1
ISUB = I+1-J
5 TABLE(I,J) = (TABLE(I,J-1) - TABLE(I-1,J-1))/(X(I+1) - X(ISUB))
C
6 TRUBL = 0.0
RETURN
C
END
FUNCTION FNEWT ( X,Y,TABLE,N,M,IDEG,XARG,TRUBL,K )
C
C FNEWT ASSUMES THAT X(1)...X(N) ARE IN ASCENDING ORDER AND
C FIRST SCANS THE X VECTOR TO DETERMINE WHICH ELEMENT IS
C NEAREST (.GE.) THE INTERPOLATION ARGUMENT, XARG
C THE IDEG+1 BASE POINTS NEEDED FOR THE EVALUATION OF THE
C DIVIDED-DIFFERENCE POLYNOMIAL OF DEGREE IDEG+1 ARE THEN
C CENTERED ABOUT THE CHOSEN ELEMENT WITH THE LARGEST HAVING
C THE SUBSCRIPT MAX. IT IS ASSUMED THAT THE FIRST M DIVIDED
C DIFFERENCES HAVE BEEN COMPUTED BY THE SUBROUTINE
C DTABLE AND ARE ALREADY PRESENT IN THE MATRIX TABLE.
C MAX IS CHECKED TO INSURE THAT ALL REQUIRED BASE POINTS ARE
C AVAILABLE, AND THE INTERPOLANT VALUE IS COMPUTED USING NESTED
C POLYNOMIAL EVALUATION. THE INTERPOLANT IS RETURNED AS
C THE VALUE OF THE FUNCTION. FOR INCONSISTENT ARGUMENTS,
C TRUBL = 1.0 ON EXIT. OTHERWISE, TRUBL = 0.0 ON EXIT
C
DIMENSION X(N), Y(N), TABLE(K,K)
C
C ...... CHECK FOR ARGUMENT INCONSISTENCY ......
IF (IDEG.LE.M) GO TO 2
TRUBL = 1.0
FNEWT = 0.0
RETURN
C
C ....... SEARCH X VECTOR FOR ELEMENT .GE. XARG .....
2 DO 4 I=1,N
4 IF (I.EQ.N .OR. XARG.LE.X(I)) GO TO 5
5 MAX = I + IDEG/2
C
C ......... INSURE THAT ALL REQUIRED DIFFERENCES ARE IN TABLE .........
IF (MAX.LE.IDEG) MAX = IDEG + 1
IF (MAX.GT.N) MAX = N
C
C .... COMPUTE INTERPOLANT VALUE .......
YEST = TABLE(MAX-1, IDEG)
IF (IDEG.LE.1) GO TO 13
IDEGM1 = IDEG - 1
DO 12 I=1,IDEGM1
ISUB1 = MAX - 1
ISUB2 = IDEG - 1
12 YEST = YEST*(XARG - X(ISUB1)) + TABLE(ISUB1-1,ISUB2)
13 ISUB1 = MAX - IDEG
TRUBL = 0.0
FNEWT = YEST*(XARG - X(ISUB1)) + Y(ISUB1)
RETURN
C
END
C /************************************************************************************************/
this is from that book's example 1.1, 's fortran program, I just copied it, and tested it. if did not work on either gfortran or fort77
but, if I modify that program 's first format for 5f to 8f, and by hand enter at command prompt of ./a.out, I have a chance to survive to
enter 4th line of data,
0.25 1
when I compile my executable code through gfortran
I wish any expert can dig something more useful for me at next post, thanks a lot in advance., eric
I modify a little bit typo and using hand input data, I found X(I) and Y(I) are correct(same as book's print), but
table(the divided differences are), are different from book's(and I believe book's is correct, mine is wrong), especially at very begining stage,i.e. TABLE(1,1)
I got it as 0.3295133E+00
(book's is -0.9966671E-01 )
plz help
/* I certain hope to learn the way to input data by file, ./a.out < Data, rathern than type in by hand each time it execute./a.out or ./a.exe; hope some expert give advice */
/* if you are not reading that (same) book, please don't post reply */
After I modify 2 typo(s) (one is Y(2) should change to Y(20) , the other is L = 1 , should change to L = I), I tested it again,
most of my result correspond with books's result, but still not 100 (at high degree of TABLE and (THE DATA AND RESULT)(DEGE =1 , is OK, but after that , DEGE = 2 to 6, all deviate from book's result)
Here is my typescript
---------------------------------------------------------------------------
Script started on Tue, Aug 11, 2015 9:35:24 AM
]0;~/fortranprograms [32mErli89080@Erli89080-PC [33m~/fortranprograms[0m $ a.[K[K./a.exe [K
N = 8 M = 6
X(1)...X(5) = 0.0000 0.2000 0.3000 0.4000 0.6000
X(6)...X(8) = 0.7000 0.9000 1.0000
1THE SAMPLE FUNCTIONAL VALUES ARE
0 I, X(I) Y(I)
Script done on Tue, Aug 11, 2015 9:45:27 AM
------------------------------------------------------------------------------------------------------------------------
I am on cygwin(64 bit), compile by gfortran, on my pc with intel core 2 duo processor, in window vista ultrimate 64 bits
(book author said he did it in IBM360/370)
I found my final typo(s), and fix them.
Now it work 100 corresponding with book's result.
thanks your concern and help /* it can be small homework for novice */
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.