From: Vincent LAFAGE <lafage@ipno.in2p3.fr>
Subject: Re: small example, using complex variables in Ada
Date: Mon, 14 Jun 2010 15:00:40 +0200
Date: 2010-06-14T15:00:40+02:00 [thread overview]
Message-ID: <hv595l$hku$1@ccpntc8.in2p3.fr> (raw)
In-Reply-To: <hv57ap$m0l$1@speranza.aioe.org>
If we want not only compile-time warning but also run time check
-fbounds-check
like in
gfortran -Wall -Wsurprising -Wconversion -fbounds-check dft.f90 -o dft
It can be pretty useful, and close to some of the runtime checks of Ada.
So, if we remember some larger scale results I provided in a former
thread, with Ada and Fortran being equally good for coding numerical
application, Fortran 90 is still twice as fast with complex...
Vincent
PS: on a completely different level, we may use less UPPERCASE, as most
of us are more used to read lower-case or Capitalized.
Particularly for reserved words.
It's less work for our poor programmer's brain.
The same goes for the languages' names as Fortran is no more in
all-uppercase since Fortran 90, and ADA is the American Dental
Association. ;)
Le 14/06/2010 14:29, Nasser M. Abbasi a �crit :
> On 6/14/2010 2:33 AM, Vincent LAFAGE wrote:
>
>> For instance,
>> $ gfortran-4.3 -Wall -Wsurprising -Wconversion dft.f90 -o dft
>> will reveal 11 surprising implicit conversion such as
>> dft.f90:14.29:
>> COMPLEX, parameter :: J =(0,1)
>> 1
>> Warning: Conversion from INTEGER(4) to REAL(4) at (1)
>>
>> So "-Wall" is not the last word as far as warning are concerned.
>>
>
> Thanks, I did not know about these flags. I am impressed now with FORTRAN.
>
> The f90 compiler, with those flags added, became as annoying, opps, I
> mean as picky as the Ada compiler and complained about all the implicit
> conversions.
>
> Also, with the use of lbound and ubound in FORTRAN helped make the logic
> simpler by avoiding the 1-off problem.
>
> To update, below is the current version of the example in Ada and
> FORTRAN. I also made a small page where I kept these for reference.
>
> http://12000.org/my_notes/mma_matlab_control/KERNEL/node94.htm
>
> I think now it seems to me, from this simple example, that Ada and
> FORTRAN can be equally good languages for scientific applications.
>
> Thanks for everyone for the suggestions.
>
> ============= Ada ====================
> --
> -- dtf.adb, compiled with GNAT 4.3.4 20090804 (release) 1
> -- under CYGWIN 1.7.5
> -- $ gnatmake dft.adb
> -- gcc -c dft.adb
> -- gnatbind -x dft.ali
> -- gnatlink dft.ali
> -- $ ./dft.exe
> --
> -- ( 6.00000E+00, 0.00000E+00)
> -- (-1.50000E+00, 8.66026E-01)
> -- (-1.50000E+00,-8.66025E-01)
>
> with Ada.Text_IO; use Ada.Text_IO;
> with Ada.Numerics.Complex_Types; use Ada.Numerics.Complex_Types;
>
> with Ada.Numerics; use Ada.Numerics;
>
> with Ada.Numerics.Complex_Elementary_Functions;
> use Ada.Numerics.Complex_Elementary_Functions;
>
> with Ada.Complex_Text_IO; use Ada.Complex_Text_IO;
>
> procedure dft is
> N : constant := 3; -- named number, no conversion to Float needed
> X : array(0 .. N-1) of Complex := (others=>(0.0,0.0));
> data : constant array(0 .. N-1) of float :=(1.0,2.0,3.0);
> Two_Pi_Over_N : constant := 2 * Pi / N;
> -- named number, outside the loop, like in ARM 3.3.2(9)
> begin
> FOR k in X'range LOOP
> FOR m in data'range LOOP
> X(k) := X(k) + data(m)*exp(-J*Two_Pi_Over_N * float(m*k));
> END LOOP;
> put(X(k)); new_line;
> END LOOP;
> end dft;
>
> ====================== Fortran ======================
> ! dtf.f90, compiled with GCC 4.3.4
> ! under CYGWIN 1.7.5
> ! $ gfortran -Wall -Wsurprising -Wconversion dft.f90
> ! $ ./a.exe
> ! ( 6.0000000 , 0.0000000 )
> ! ( -1.4999999 , 0.86602557 )
> ! ( -1.5000005 ,-0.86602497 )
> ! $
>
> PROGRAM dft
>
> IMPLICIT NONE
>
> INTEGER, parameter :: N = 3
> COMPLEX, parameter :: J =(0.0,1.0)
> REAL, parameter :: Pi = ACOS(-1.0)
> INTEGER :: k,m
> COMPLEX, dimension(0:N-1) :: X
> REAL, dimension(0:N-1) :: data=(/1.0,2.0,3.0/)
> REAL, parameter :: Two_Pi_Over_N = 2.0*Pi/real(N)
>
> DO k = lbound(X, 1), ubound(X, 1)
> X(k)=(0.0,0.0)
> DO m = lbound(data, 1), ubound(data, 1)
> X(k) = X(k) + complex(data(m),0.0) &
> * EXP(-J*complex(Two_Pi_Over_N*real(m*k),0.0))
> END DO
> print *,X(k)
> END DO
>
> END PROGRAM dft
>
>
> --Nasser
prev parent reply other threads:[~2010-06-14 13:00 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-09 10:49 small example, using complex variables in Ada Nasser M. Abbasi
2010-06-09 11:26 ` Ludovic Brenta
2010-06-09 23:50 ` Jerry
2010-06-10 1:03 ` Jeffrey R. Carter
2010-06-10 15:48 ` Colin Paul Gloster
2010-06-10 14:54 ` Ludovic Brenta
2010-06-10 16:21 ` Colin Paul Gloster
2010-06-10 17:37 ` Adam Beneschan
2010-06-10 17:57 ` Jeffrey R. Carter
2010-06-10 22:32 ` Randy Brukardt
2010-06-11 12:42 ` Colin Paul Gloster
2010-06-11 18:59 ` Randy Brukardt
2010-06-14 19:19 ` Colin Paul Gloster
2010-06-14 19:48 ` Nasser M. Abbasi
2010-06-17 7:44 ` Gautier write-only
2010-06-17 10:33 ` Colin Paul Gloster
2010-06-17 14:39 ` Yannick Duchêne (Hibou57)
2010-06-17 16:36 ` Colin Paul Gloster
2010-06-09 12:43 ` Niklas Holsti
2010-06-10 7:23 ` Stephen Leake
2010-06-10 9:12 ` J-P. Rosen
2010-06-10 11:03 ` Yannick Duchêne (Hibou57)
2010-06-10 13:27 ` J-P. Rosen
2010-06-10 21:15 ` Yannick Duchêne (Hibou57)
2010-06-11 7:22 ` Dmitry A. Kazakov
2010-06-11 8:48 ` J-P. Rosen
2010-06-11 12:00 ` Brian Drummond
2010-06-10 9:34 ` Nasser M. Abbasi
2010-06-10 20:12 ` Simon Wright
2010-06-14 9:33 ` Vincent LAFAGE
2010-06-14 12:29 ` Nasser M. Abbasi
2010-06-14 13:00 ` Vincent LAFAGE [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox