This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
learning functions
- From: RadSurfer <RadSurfer at yahoo dot com>
- To: fortran at gcc dot gnu dot org
- Date: Sun, 2 Sep 2007 05:32:46 +0000 (UTC)
- Subject: learning functions
Error messages I get are found below.
I need to learn how to do Functions (and Subroutines) in Fortran.
I am compiling this as .f95
I do not understand why I am getting so many errors,
nothing I do seems to reduce them; only increase them!
I. In the first function JDtoMDY(JD,M,D,Y), JD is input value, and
M,D,Y is the only output:
1) in this function M,D,Y are written to, to create the needed result.
month/day/year.
II. In the second function MDYtoJD(M,D,Y,JD) M,D,Y are input values only, and
JD is the only output:
1) am I permitted to set both JD and JDtoMDY to the same numerical value?
this would be convenient.
in I. M,D,Y are used for output; JD for input
in II. M,D,Y are purely input; JD for output
and should pose no problems for Fortran as these conditions are in
different functions, and thus do not conflict since only one function
can be called at a time.
I would just like to see this compile! I'm sure the declarations inside the
functions are at fault.
! Sat 01 Sep 2007 09:11:37 PM EDT
! Convert to/from Gregorian/Julian Dates
! jgreg.f95
program jgreg
IMPLICIT NONE
Real(8) JD, M, D, Y
Integer n,c
Character arg*80,astr*45,buffer*256
n = iargc()
if (n == 1) then
call getarg(1, arg);
read(arg,*) JD ! Get CmdLine value (Real8)
! write(*,*) 'Fraction ',Fraction(JD);
! JDtoMDY(M,D,Y)
else
if (n == 3) then
call getarg(1, arg);
read(arg,*) M ! Get CmdLine value (Real8)
call getarg(2, arg);
read(arg,*) D ! Get CmdLine value (Real8)
call getarg(3, arg);
read(arg,*) Y ! Get CmdLine value (Real8)
! JD = MDYtoJD(M,D,Y)
else
write(*,*) 'Error: Improper Number of Aruments!'
end if
end if
contains
function fix(x)
implicit none
real :: fix
real,intent(in) x
if (x .lt. 0.0_8) then
fix = ceil(x)
else
fix = floor(x)
end if
function end fix
function JDtoMDY(JD,M,D,Y)
implicit none
real(8) JDtoMDY
intent(in) JD
intent(in out) M,D,Y
! no code yet
function end JDtoMDY
function MDYtoJD(M,D,Y,JD)
implicit none
real(8) MDYtoJD
intent(in) M,D,Y
intent(in out) JD
if (M<3.0) then
Y=Y-1; M=M+12.0;
end if
JD = fix(Y/100.0)
JD = ( 2.0 - JD + fix(JD/4.0)) + fix(365.25*Y)
+ fix(30.6001*(M+1.0)) + D + 1720994.5
MDYtoJD = JD
function end MDYtoJD
end program jgreg
[RadSurfer@centos fortran]$ gfortran jg0.f95
jg0.f95:38.5:
real,intent(in) x
1
Error: Invalid character in name at (1)
jg0.f95:44:
function end fix
1
Error: Unclassifiable statement at (1)
jg0.f95:46:
function JDtoMDY(JD,M,D,Y)
1
Error: Unclassifiable statement at (1)
jg0.f95:47.13:
implicit none
1
Error: Unexpected IMPLICIT NONE statement at (1)
jg0.f95:48.22:
real(8) JDtoMDY
1
Error: Unexpected data declaration statement at (1)
jg0.f95:49.22:
intent(in) JD
1
Error: Unexpected attribute declaration statement at (1)
jg0.f95:50.22:
intent(in out) M,D,Y
1
Error: Unexpected attribute declaration statement at (1)
jg0.f95:52:
function end JDtoMDY
1
Error: Unclassifiable statement at (1)
jg0.f95:54:
function MDYtoJD(M,D,Y,JD)
1
Error: Unclassifiable statement at (1)
jg0.f95:55.13:
implicit none
1
Error: Unexpected IMPLICIT NONE statement at (1)
jg0.f95:56.22:
real(8) MDYtoJD
1
Error: Unexpected data declaration statement at (1)
jg0.f95:57.22:
intent(in) M,D,Y
1
Error: Unexpected attribute declaration statement at (1)
jg0.f95:58.22:
intent(in out) JD
1
Error: Unexpected attribute declaration statement at (1)
jg0.f95:62.2:
JD = fix(Y/100.0)
1
Error: Unclassifiable statement at (1)
jg0.f95:63.23:
JD = ( 2.0 - JD + fix(JD/4.0)) + fix(365.25*Y)
1
Error: Expected a right parenthesis in expression at (1)
jg0.f95:64.6:
+ fix(30.6001*(M+1.0)) + D + 1720994.5
1
Error: Invalid character in name at (1)
jg0.f95:66:
function end MDYtoJD
1
Error: Unclassifiable statement at (1)
jg0.f95:68.3:
end program jgreg
1
Error: Expecting END FUNCTION statement at (1)
Error: Unexpected end of file in 'jg0.f95'
[RadSurfer@centos fortran]$