comp.lang.ada
 help / color / mirror / Atom feed
* unconstrained subtype in component declaration, tagged OO
@ 2011-03-26 20:24 Nasser M. Abbasi
  2011-03-26 20:42 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 6+ messages in thread
From: Nasser M. Abbasi @ 2011-03-26 20:24 UTC (permalink / raw)


I am learning a bit about Ada OO, and I have simple problem,
hopefully with simple answer, but not able to find one so far.

I want to make an object, but the declaration of the tagged record
would include an array in it. The size of this array, at the
time of declaration is not know. But will be when the
object is created.

So, what is the correct way to declare such an object?

Here is my ads package for the object:

-------------------foo.ads-------
package foo is
    type foo_t is tagged private;
    -- primitive operations
    function make(n:natural) return foo_t;
private
     type u_t is array(natural range<>) of float;

     type foo_t is tagged record
          u : u_t:= (others=>0.0);  -- problem here
     end record;
end foo;
----------------------------

Later on, (when I can get this to compile :), I wanted
to write

with foo; use foo;
...
o : foo_t := make(100);   


I can solve this problem by making a generic package,
and use the size as the generic of the package, but
I really do not want to do that. I want to keep
things very simple for now, as I am just learning
this, and wanted the most simple solution.

As I am now learning Ada again, I am sure I will be back here
with more questions to the experts.

thanks
--Nasser






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: unconstrained subtype in component declaration, tagged OO
  2011-03-26 20:24 unconstrained subtype in component declaration, tagged OO Nasser M. Abbasi
@ 2011-03-26 20:42 ` Dmitry A. Kazakov
  2011-03-26 22:50   ` Nasser M. Abbasi
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry A. Kazakov @ 2011-03-26 20:42 UTC (permalink / raw)


On Sat, 26 Mar 2011 13:24:37 -0700, Nasser M. Abbasi wrote:

> I am learning a bit about Ada OO, and I have simple problem,
> hopefully with simple answer, but not able to find one so far.
> 
> I want to make an object, but the declaration of the tagged record
> would include an array in it. The size of this array, at the
> time of declaration is not know. But will be when the
> object is created.
> 
> So, what is the correct way to declare such an object?
> 
> Here is my ads package for the object:
> 
> -------------------foo.ads-------
> package foo is
>     type foo_t is tagged private;

   type foo_t (<>) is tagged private;

>     -- primitive operations
>     function make(n:natural) return foo_t;
> private
>      type u_t is array(natural range<>) of float;
> 
>      type foo_t is tagged record
>           u : u_t:= (others=>0.0);  -- problem here
>      end record;

   type foo_t (Length : Natural) is tagged record
      u : u_t (1..Length) := (others=>0.0);
   end record;


   function make(n:natural) return foo_t is
   begin
      return (n, (others => 0.0));
   end make;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: unconstrained subtype in component declaration, tagged OO
  2011-03-26 20:42 ` Dmitry A. Kazakov
@ 2011-03-26 22:50   ` Nasser M. Abbasi
  2011-03-27  3:23     ` John B. Matthews
  2011-03-27  9:42     ` Dmitry A. Kazakov
  0 siblings, 2 replies; 6+ messages in thread
From: Nasser M. Abbasi @ 2011-03-26 22:50 UTC (permalink / raw)


On 3/26/2011 1:42 PM, Dmitry A. Kazakov wrote:

>> -------------------foo.ads-------
>> package foo is
>>      type foo_t is tagged private;

>
>     type foo_t (<>) is tagged private;
>

Thanks Dmitry, that is one I did not find, the use of (<>) there.

It is now all working well.

I also like that I can write  o.method() now in Ada and do not
have to write method(o) as before.

I am converting some of my Matlab functions and scripts for
solving PDE's to Ada to see how it works out. So far, it is
working very well. I really like the Ada array predefined
operators, very useful. Also I like that I can define my array
to start from 0 or other index values and not only from 1.

Some numerical schemes I use are more natural when using starting
anindex other than from 1.

Only problem is plotting the solution. So far, I write the
data from one simulation run to one text file and then use Matlab
to load and plot the data at the end of the simulation. Works well,
but data size can get very large, and when I load it to Matlab, it
requires lots of RAM.

This is because I have to save the data for each time step to be able
to create all the plots.

In Matlab, I do not need to save all the data, since I can plot each
frame as I go, and then throw the current data away, and hence only
need the data (solution) for the current time step.

I might figure a way to improve this, as may be using one text file to
save the output for each time step. But then I will get huge number
of files created on my disk each time I run the program. Sometimes I
run it for 2000 or 3000 time steps, each time step can generate 1000
data points.

If Only Ada had plotting in it, it will be just perfect :)

--Nasser



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: unconstrained subtype in component declaration, tagged OO
  2011-03-26 22:50   ` Nasser M. Abbasi
@ 2011-03-27  3:23     ` John B. Matthews
  2011-03-27  9:42     ` Dmitry A. Kazakov
  1 sibling, 0 replies; 6+ messages in thread
From: John B. Matthews @ 2011-03-27  3:23 UTC (permalink / raw)


In article <imlqjf$b7m$1@speranza.aioe.org>,
 "Nasser M. Abbasi" <nma@12000.org> wrote:

> If Only Ada had plotting in it, it will be just perfect :)

Don't overlook <http://plplot.sourceforge.net/>.

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: unconstrained subtype in component declaration, tagged OO
  2011-03-26 22:50   ` Nasser M. Abbasi
  2011-03-27  3:23     ` John B. Matthews
@ 2011-03-27  9:42     ` Dmitry A. Kazakov
  2011-03-27 20:58       ` Nasser M. Abbasi
  1 sibling, 1 reply; 6+ messages in thread
From: Dmitry A. Kazakov @ 2011-03-27  9:42 UTC (permalink / raw)


On Sat, 26 Mar 2011 15:50:17 -0700, Nasser M. Abbasi wrote:

> Only problem is plotting the solution. So far, I write the
> data from one simulation run to one text file and then use Matlab
> to load and plot the data at the end of the simulation. Works well,
> but data size can get very large, and when I load it to Matlab, it
> requires lots of RAM.

Hmm, is it Simulink actually? For Simulink you could write a custom a
S-function in Ada and feed it with data at each simulation step.
 
> If Only Ada had plotting in it, it will be just perfect :)

It can:

http://libre.adacore.com/wp-content/files/auto_update/gtkada-docs/gtkada_rm/gtkada_rm/screenshots.html 

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: unconstrained subtype in component declaration, tagged OO
  2011-03-27  9:42     ` Dmitry A. Kazakov
@ 2011-03-27 20:58       ` Nasser M. Abbasi
  0 siblings, 0 replies; 6+ messages in thread
From: Nasser M. Abbasi @ 2011-03-27 20:58 UTC (permalink / raw)


On 3/27/2011 2:42 AM, Dmitry A. Kazakov wrote:
> On Sat, 26 Mar 2011 15:50:17 -0700, Nasser M. Abbasi wrote:
>
>> Only problem is plotting the solution. So far, I write the
>> data from one simulation run to one text file and then use Matlab
>> to load and plot the data at the end of the simulation. Works well,
>> but data size can get very large, and when I load it to Matlab, it
>> requires lots of RAM.
>

> Hmm, is it Simulink actually? For Simulink you could write a custom a
> S-function in Ada and feed it with data at each simulation step.
>

Simulink? No, meant just simulation. Run code, generate data,
make plots of the result. That is all.

Any way, I made a small note of this exercise on using Ada
for solving simple 1D PDE (advection PDE using lax-wendroff
scheme) using OO notation. Here it is

http://12000.org/my_notes/solve_advection_1D_in_Ada/index.htm

This is my very first attempt at using Ada OO, but I like
Ada OO so far.

--Nasser



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-03-27 20:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-26 20:24 unconstrained subtype in component declaration, tagged OO Nasser M. Abbasi
2011-03-26 20:42 ` Dmitry A. Kazakov
2011-03-26 22:50   ` Nasser M. Abbasi
2011-03-27  3:23     ` John B. Matthews
2011-03-27  9:42     ` Dmitry A. Kazakov
2011-03-27 20:58       ` Nasser M. Abbasi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox