This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: learning functions
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: RadSurfer <RadSurfer at yahoo dot com>
- Cc: fortran at gcc dot gnu dot org
- Date: Sun, 02 Sep 2007 00:19:15 -0700
- Subject: Re: learning functions
- References: <loom.20070902T070943-273@post.gmane.org>
RadSurfer wrote:
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!
You really need to get a good book or google for some on line tutorials.
I took the liberty to clean up your code, by example it will show you some
things. Its not useful yet, but there are no compile errors at the moment.
Jerry
! 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)
real(8) :: fix
real(8), intent(in) :: x
if (x .lt. 0.0_8) then
fix = ceiling(x)
else
fix = floor(x)
end if
end function fix
function jdtomdy(jd,m,d,y)
real(8) :: jdtomdy
real(8), intent(in) :: jd
real(8), intent(in out):: m,d,y
! no code yet
jdtomdy = 0.0_8
end function jdtomdy
function mdytojd(m,d,y,jd)
real(8) :: mdytojd
real(8) :: m,d,y
real(8) :: jd
if (m<3.0) then
y=y-1; m=m+12.0;
end if
jd = fix(y/100.0_8)
jd = ( 2.0 - jd + fix(jd/4.0)) + fix(365.25*y) &
+ fix(30.6001*(m+1.0)) + d + 1720994.5
mdytojd = jd
end function mdytojd
end program jgreg