LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-08-2015, 02:43 PM   #1
fsshl
Member
 
Registered: Jan 2002
Distribution: Ubuntu10.04
Posts: 49

Rep: Reputation: 1
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 */
 
Old 08-08-2015, 11:44 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
You should use an input-file:
Code:
mcedit input.file
./myprogram <input.file
So you could quote the input file along with the program and the error message. (Just for those who aren't clairvoyants.)
 
Old 08-09-2015, 12:45 PM   #3
fsshl
Member
 
Registered: Jan 2002
Distribution: Ubuntu10.04
Posts: 49

Original Poster
Rep: Reputation: 1
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)

]0;eric@ubuntu: ~/fortranprogramseric@ubuntu:~/fortranprograms$ exit
exit

Script done on Sun 09 Aug 2015 10:43:40 AM PDT

/**-----------------------------------------------------------------------------------**/
so please help,
why its read and its format is hard to correspond my input format?
Eric
 
Old 08-09-2015, 01:01 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Please do something with your post to make it human-readable. Use [code] and [/code] tags for codes/lists.
Also paste the source-program.
 
Old 08-09-2015, 01:21 PM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
Hi fsshl

make sure that you have the OLD legacy gcc3.3( or 3.4)-fortran compiler and tools installed

F77( g77) is not in the gcc 4.? or gcc5
it is in the OLD version 3 compiler

if you ran this
Code:
sudo apt-get install gfortran
that would have installed the F95 Gfortran-95 software

for the 1977 version
Code:
sudo apt-get install fort77
Quote:
(Carnahan 's (applied numerical methods) published 1969 by son john wily),
also think of the date on that book

while somethings do not change ... other things DO, like the hardware used in 1969

Last edited by John VV; 08-10-2015 at 01:06 AM.
 
Old 08-09-2015, 10:28 PM   #6
fsshl
Member
 
Registered: Jan 2002
Distribution: Ubuntu10.04
Posts: 49

Original Poster
Rep: Reputation: 1
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
 
Old 08-09-2015, 11:15 PM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Please do something with your post to make it human-readable. Use [code] and [/code] tags for codes/lists.
 
Old 08-11-2015, 02:54 AM   #8
fsshl
Member
 
Registered: Jan 2002
Distribution: Ubuntu10.04
Posts: 49

Original Poster
Rep: Reputation: 1
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 */
 
1 members found this post helpful.
Old 08-11-2015, 03:50 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> if you are not reading that (same) book, please don't post reply

Okay. Also I don't reply because you didn't add the [code] and [/code] tags. Good bye.
 
Old 08-11-2015, 11:54 AM   #10
fsshl
Member
 
Registered: Jan 2002
Distribution: Ubuntu10.04
Posts: 49

Original Poster
Rep: Reputation: 1
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 Erli89080@Erli89080-PC ~/fortranprograms $ a../a.exe 
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)

, 1 0.000000 1.000000
, 2 0.200000 0.980067
, 3 0.300000 0.955337
, 4 0.400000 0.921061
, 5 0.600000 0.825336
, 6 0.700000 0.764842
, 7 0.900000 0.621610
, 8 1.000000 0.540302
1.00000000
0.980066597
-1.99334025E-02
1FOR M = 6, THE DIVIDED DIFFERENCES ARE

, -0.9966701E-01

, -0.2473008E+00 -0.4921128E+00

, -0.3427553E+00 -0.4772725E+00 0.3710069E-01

, -0.4786268E+00 -0.4529047E+00 0.6091952E-01 0.3969805E-01

, -0.6049349E+00 -0.4210273E+00 0.7969350E-01 0.3754797E-01 -0.3071550E-02

, -0.7161609E+00 -0.3707533E+00 0.1005480E+00 0.3475756E-01 -0.3986300E-02 -0.1016389E-02

, -0.8130769E+00 -0.3230534E+00 0.1192497E+00 0.3116940E-01 -0.5125936E-02 -0.1424545E-02
1THE DATA AND RESULTS ARE
0 XARG IDEG YINTER TRUVAL TRUBL

XARG = 2.0000 IDEG = 1
, 2.0000 1 -0.272775 -0.416147 0.0
XARG = 2.0000 IDEG = 2
, 2.0000 2 -0.628133 -0.416147 0.0
XARG = 2.0000 IDEG = 3
, 2.0000 3 -0.062670 -0.416147 0.0
XARG = 2.0000 IDEG = 4
, 2.0000 4 1.519942 -0.416147 0.0
XARG = 2.0000 IDEG = 5
, 2.0000 5 1.216805 -0.416147 0.0
XARG = 2.0000 IDEG = 6
, 2.0000 6 0.932131 -0.416147 0.0

]0;~/fortranprograms Erli89080@Erli89080-PC ~/fortranprograms $ exit
exit

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)

plz help
 
Old 08-11-2015, 01:13 PM   #11
fsshl
Member
 
Registered: Jan 2002
Distribution: Ubuntu10.04
Posts: 49

Original Poster
Rep: Reputation: 1
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 */
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
RHCE New Exam Format...plz help... harshaabba Linux - Certification 2 02-07-2011 11:40 PM
problem installing fortran77 on suse11 minaesm Linux - Software 54 03-01-2009 11:14 AM
Plz tell me, how to get input in awk script intikhabalam Linux - General 1 07-27-2008 07:01 AM
Dynamically set array length in Fortran77? halfpower Programming 2 12-15-2005 08:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration