




Fortran Programming Language









please help
does this program work, i dont know did i call in the right way function deqn the task is to solve 20 linear equations with 20 unknowns, and to write the solution of x2 this is my program: program matrice real(8), dimension(20,20)::a real(8), dimension(20)::b integer::i,j,ifail dimension IR(20) do i=1,20 do j=1,20 if (i==j) then a(i,j)=real(i) else if (j==(i1)) then a(i,j)=0.5*sqrt(real(i+1)) else if (j==(i+1)) then a(i,j)=0.5*sqrt(real(i+1)) else a(i,j)=0.0 end if end do end do b(1)=1.0 do i=2,20 b(i)=0.0 end do call deqn(20,a,20,IR,IFAIL,20,b) print*,b(2) end program
fake wrote: > does this program work, i dont know did i call in the right way function > deqn > the task is to solve 20 linear equations with 20 unknowns, and to write the > solution of x2 > this is my program: > program matrice > real(8), dimension(20,20)::a > real(8), dimension(20)::b > integer::i,j,ifail > dimension IR(20) > do i=1,20 > do j=1,20 > if (i==j) then > a(i,j)=real(i) > else if (j==(i1)) then > a(i,j)=0.5*sqrt(real(i+1)) > else if (j==(i+1)) then > a(i,j)=0.5*sqrt(real(i+1)) > else > a(i,j)=0.0 > end if > end do > end do > b(1)=1.0 > do i=2,20 > b(i)=0.0 > end do > call deqn(20,a,20,IR,IFAIL,20,b) > print*,b(2) > end program
What happened when you tried it? Do you have the documentation for deqn? you should at least print out the value of IFAIL. It also would help if you would use a different name or email address. There is so much spam on the internet that I almost deleted your message without reading it. Even a title like "please help with subroutine deqn" would be better. Dick Hendrickson
> What happened when you tried it? Do you have the documentation for > deqn? you should at least print out the value of IFAIL.
i cant try because i dont have that documentation... ifail is declared in that function i know that.. > It also would help if you would use a different name or email address. > There is so much spam on the internet that I almost deleted your message > without reading it. Even a title like "please help with subroutine deqn" > would be better.
sorry for that, this is my first time that i am here, i am from croatia, and we dont have so much spam here, as maybe on english pages
On May 17, 5:21 pm, "fake" <a@a.a> wrote: > > What happened when you tried it? Do you have the documentation for > > deqn? you should at least print out the value of IFAIL. > i cant try because i dont have that documentation... ifail is declared in > that function i know that.. > > It also would help if you would use a different name or email address. > > There is so much spam on the internet that I almost deleted your message > > without reading it. Even a title like "please help with subroutine deqn" > > would be better. > sorry for that, this is my first time that i am here, i am from croatia, and > we dont have so much spam here, as maybe on english pages
If vector x is supposed to solve A * x = b, why don't you test if the norm of (A * x  b) is effectively zero?
On May 17, 6:21 pm, "fake" <a@a.a> wrote: > > What happened when you tried it? Do you have the documentation for > > deqn? you should at least print out the value of IFAIL. > i cant try because i dont have that documentation... ifail is declared in > that function i know that.. > > It also would help if you would use a different name or email address. > > There is so much spam on the internet that I almost deleted your message > > without reading it. Even a title like "please help with subroutine deqn" > > would be better. > sorry for that, this is my first time that i am here, i am from croatia, and > we dont have so much spam here, as maybe on english pages
This looks like a routine from CERN. A google search on CERNLIB and DEQN eventually leads to http://dollywood.itp.tuwien.ac.at/cernlib/shortwrupsdir/f010/top.html You *may* have an argument mismatch here. In particular, look at the value of K. If K is too large for your problem, your subroutine may write over other variables. A google search may also show you source code for the DEQN routine, but a quick look shows that it appears to differ from the documentation listed above.  email: epc8 at juno dot com  elliot
On 18 May 2007 10:32:06 0700, e p chandler <e@juno.com> wrote in <1179509526.436240.265@k79g2000hse.googlegroups.com>: > This looks like a routine from CERN. A google search on CERNLIB and > DEQN eventually leads to > http://dollywood.itp.tuwien.ac.at/cernlib/shortwrupsdir/f010/top.html > You *may* have an argument mismatch here. In particular, look at the > value of K. If K is too large for your problem, your subroutine may > write over other variables. > A google search may also show you source code for the DEQN routine, > but a quick look shows that it appears to differ from the > documentation listed above. The version on one of my machines, from 2004, has the 4th parameter as REAL R(N). It's not used in the routine, but passed on to DFACT() and DFEQN(). In both of them the corresponding array is again INTEGER so it should be a harmless passthrough, providing compiler flags aren't playing games with variable sizes. Note it is a workspace so it could be dimensioned larger than IDIM, but smaller sizes would cause problems.  Ivan Reid, School of Engineering & Design, _____________ CMS Collaboration, Brunel University. Ivan.Reid@[brunel.ac.ukcern.ch] Room 401B12, CERN KotPT  "for stupidity above and beyond the call of duty".
On Thu, 17 May 2007 22:36:02 +0200, fake <a@a.a> wrote in <f2iebm$nr@news1.carnet.hr>: > does this program work, i dont know did i call in the right way function > deqn > the task is to solve 20 linear equations with 20 unknowns, and to write the > solution of x2 > this is my program: > program matrice > real(8), dimension(20,20)::a > real(8), dimension(20)::b > integer::i,j,ifail > dimension IR(20) ... > call deqn(20,a,20,IR,IFAIL,20,b) > print*,b(2)
This is the library declaration (2004 version of KERNLIB): SUBROUTINE DEQN(N,A,IDIM,R,IFAIL,K,B) REAL R(N),T1,T2,T3 DOUBLE PRECISION A(IDIM,N),B(IDIM,K),DET,S,TEMP, The value of K (parameter 6) should be 1, n'estce pas? I've mentioned in another post that the mismatch in declaration of IR/R should not be a problem as it's a scratch array, and passed through to other routines which do declare it integer anyway. Note that in general I recommend against passing literal constants to library routines. This helps avoid problems with type mismatches/conversions.  Ivan Reid, School of Engineering & Design, _____________ CMS Collaboration, Brunel University. Ivan.Reid@[brunel.ac.ukcern.ch] Room 401B12, CERN KotPT  "for stupidity above and beyond the call of duty".
On May 18, 2:52 pm, "Dr Ivan D. Reid" <Ivan.R@brunel.ac.uk> wrote:
> On Thu, 17 May 2007 22:36:02 +0200, fake <a @a.a> > wrote in <f2iebm$nr @news1.carnet.hr>: > > does this program work, i dont know did i call in the right way function > > deqn > > the task is to solve 20 linear equations with 20 unknowns, and to write the > > solution of x2 > > this is my program: > > program matrice > > real(8), dimension(20,20)::a > > real(8), dimension(20)::b > > integer::i,j,ifail > > dimension IR(20) > ... > > call deqn(20,a,20,IR,IFAIL,20,b) > > print*,b(2) > This is the library declaration (2004 version of KERNLIB): > SUBROUTINE DEQN(N,A,IDIM,R,IFAIL,K,B) > REAL R(N),T1,T2,T3 > DOUBLE PRECISION A(IDIM,N),B(IDIM,K),DET,S,TEMP, > The value of K (parameter 6) should be 1, n'estce pas? I've > mentioned in another post that the mismatch in declaration of IR/R should > not be a problem as it's a scratch array, and passed through to other > routines which do declare it integer anyway. > Note that in general I recommend against passing literal constants > to library routines. This helps avoid problems with type > mismatches/conversions. >  > Ivan Reid, School of Engineering & Design, _____________ CMS Collaboration, > Brunel University. Ivan.Reid@[brunel.ac.ukcern.ch] Room 401B12, CERN > KotPT  "for stupidity above and beyond the call of duty".
Setting K to 1 seems to solve the OP's problem: call deqn(20,a,20,ir,ifail,1,b) A * X is reasonably close to B. (checked in Excel). Note: I compiled the test program plus the minimal set of source files needed (after making necessary changes). The libraries provided on CERN's web site for Windows use DVF, not a 'GNU' toolset. Google shows libraries built on Cygwin but not MinGW. Has someone built these for (MinGW) g77, g95 or gfortran?  elliot
On 19 May 2007 09:43:49 0700, e p chandler <e@juno.com> wrote in <1179593029.327277.26@p77g2000hsh.googlegroups.com>: > On May 18, 2:52 pm, "Dr Ivan D. Reid" <Ivan.R @brunel.ac.uk> wrote: >> The value of K (parameter 6) should be 1, n'estce pas? I've >> mentioned in another post that the mismatch in declaration of IR/R should >> not be a problem as it's a scratch array, and passed through to other >> routines which do declare it integer anyway. > Setting K to 1 seems to solve the OP's problem: > call deqn(20,a,20,ir,ifail,1,b) Oh, good, I though it would. > A * X is reasonably close to B. (checked in Excel). > Note: > I compiled the test program plus the minimal set of source files > needed (after making necessary changes). The libraries provided on > CERN's web site for Windows use DVF, not a 'GNU' toolset. Google shows > libraries built on Cygwin but not MinGW. Has someone built these for > (MinGW) g77, g95 or gfortran?
When I first started using CERNLIB in anger (back about 1990 at PSI) their licence was fairly broad, but restricted to organisations allied with CERN (ISTR I had to get some sort of authorisation to get the MINUIT sources). This was well before the GPL (or at least before it became popular)  maybe they've changed to that nowadays. In any case, I use fullblown Cygwin when I'm not using Scientific Linux CERN so I'm not able to offer MinGW libs unless someone gives me a few pointers. I'm pretty sure it'd all be g77, too. The modern Fortrans didn't appear until SLC 4.0; most people are still at 3.0.6, though this will change in the next six months or so.  Ivan Reid, School of Engineering & Design, _____________ CMS Collaboration, Brunel University. Ivan.Reid@[brunel.ac.ukcern.ch] Room 401B12, CERN KotPT  "for stupidity above and beyond the call of duty".
yesterday i saw that mistake.. i wrote:
program matrice implicit none real(8), dimension(20,20)::a real(8), dimension(20)::b integer::i,j,ifail dimension IR(20) do i=1,20 do j=1,20 if (i==j) then a(i,j)=real(i) else if (j==(i1)) then a(i,j)=0.5*sqrt(real(i+1)) else if (j==(i+1)) then a(i,j)=0.5*sqrt(real(i+1)) else a(i,j)=0.0 end if end do end do b(1)=1.0 do i=2,20 b(i)=0.0 end do call deqn(20,a,20,IR,IFAIL,1,b) print*,b(2) end program and i get 0.811863376101259 i hope that it is the right answer for the solution of x2
"Dr Ivan D. Reid" <Ivan.R@brunel.ac.uk> wrote in message news:slrnf4uchg.3co.Ivan.Reid@loki.brunel.ac.uk... > When I first started using CERNLIB in anger (back about 1990 at PSI) > their licence was fairly broad, but restricted to organisations allied > with > CERN (ISTR I had to get some sort of authorisation to get the MINUIT > sources). > This was well before the GPL (or at least before it became popular)  > maybe > they've changed to that nowadays. In any case, I use fullblown Cygwin > when I'm not using Scientific Linux CERN so I'm not able to offer MinGW > libs unless someone gives me a few pointers.
That was just before I used CERNLIB, including MINUIT and GEANT, to test NAG's first f90 compiler. After NAG's bugs had been ironed out, I had 250,000 lines of code working with it. Of course, CERNLIB never was converted to f90, but that's a (very) long story. Regards, Mike Metcalf
On May 19, 3:47 pm, "fake" <a@a.a> wrote: > yesterday i saw that mistake.. > i wrote: > program matrice > implicit none > real(8), dimension(20,20)::a > real(8), dimension(20)::b > integer::i,j,ifail
IR is untyped given you have specified implicit none integer:: IR
> dimension IR(20) > do i=1,20 > do j=1,20 > if (i==j) then > a(i,j)=real(i) > else if (j==(i1)) then > a(i,j)=0.5*sqrt(real(i+1)) > else if (j==(i+1)) then > a(i,j)=0.5*sqrt(real(i+1)) > else > a(i,j)=0.0 > end if > end do > end do > b(1)=1.0 > do i=2,20 > b(i)=0.0 > end do > call deqn(20,a,20,IR,IFAIL,1,b) > print*,b(2) > end program > and i get 0.811863376101259 > i hope that it is the right answer for the solution of x2
Within the limitations of floating point calculations, of course. :). Compiling with g95 (4.1) on XP, my output is: 0.8118633413147692 Although the calculation is carried out in double precision, the result may only be good to single precision. As a check, multiplying A * X (in Excel) gives for B: 1 2.9976E15 2.52576E15 9.88792E16 6.00214E16 7.80626E17 1.0842E17 4.11997E18 1.08759E18 2.3484E19 2.76874E20 1.31224E20 6.00533E22 2.92305E22 1.12962E23 3.6383E24 5.51319E25 4.50345E26 8.70902E28 1.21169E27  email: epc8 at juno dot com





