swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Averager usage


From: Marcus G. Daniels
Subject: Re: Averager usage
Date: 22 Jun 1999 12:38:18 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.3.10

>>>>> "SME" == sme  <address@hidden> writes:

SME> I want to calculate the average of each separate pigment
SME> (chla..caro) for each individual species (phytoID) down the water
SME> column. i.e. the Averager object must iterate:

I think the Controller's -createEnd Averager creation answers your
question...

#import <simtools.h>
#import <analysis.h>
#import <random.h>
#import <objectbase/SwarmObject.h>

#define WATERCOUNT 100
#define PHYTOCOUNT 100
#define PIGMENTCOUNT 10

@interface Phyto: SwarmObject
{
  unsigned phytoIndex;
@public
  double pigments[PIGMENTCOUNT];
}
- setPhytoIndex: (unsigned)phytoIndex;
- createEnd;
@end

@implementation Phyto
- setPhytoIndex: (unsigned)thePhytoIndex
{
  phytoIndex = thePhytoIndex;
  return self;
}

- createEnd
{
  unsigned i;

  for (i = 0; i < PIGMENTCOUNT; i++)
    pigments[i] =
      (i + 1)
      * (phytoIndex + 1)
      * [uniformDblRand getDoubleWithMin: 0.0 withMax: 1.0];
  return self;
}

@end

@interface Water: SwarmObject
{
@public
  Phyto *phytos[PHYTOCOUNT];
}
- (double)getPhyto: (unsigned)phytoIndex pigment: (unsigned)pigmentIndex;
@end

@implementation Water
- createEnd
{
  unsigned i;
  id <Zone> aZone = [self getZone];

  for (i = 0; i < PHYTOCOUNT; i++)
    phytos[i] = [[[Phyto createBegin: aZone] setPhytoIndex: i] createEnd];

  return self;
}

- (double)getPhyto: (unsigned)phytoIndex pigment: (unsigned)pigmentIndex
{
  return phytos[phytoIndex]->pigments[pigmentIndex];
}
@end

@interface Controller: SwarmObject
{
  id <List> waterList;
  id averagers[PHYTOCOUNT][PIGMENTCOUNT];
}
+ createBegin: aZone;
- createEnd;
- (void)printAverages;
@end

@implementation Controller
+ createBegin: aZone
{
  Controller *obj = [super createBegin: aZone];
  id <List> l;
  unsigned i;

  l = [List create: aZone];
  for (i = 0; i < WATERCOUNT; i++)
    [l addLast: [Water create: aZone]];
  obj->waterList = l;
  
  return obj;
}

- createEnd
{
  unsigned i;

  for (i = 0; i < PHYTOCOUNT; i++)
    {
      char arg0[DSIZE (unsigned) + 1];
      unsigned j;
      
      sprintf (arg0, "%u", i);
      for (j = 0; j < PIGMENTCOUNT; j++)
        {
          char arg1[DSIZE (unsigned) + 1];
          id averager = [[[[Averager createBegin: globalZone]
                            setProbedSelector: M(getPhyto:pigment:)]
                           setCollection: waterList]
                          createEnd];
          
          sprintf (arg1, "%u", j);
          [averager setArg: 0 ToString: arg0];
          [averager setArg: 1 ToString: arg1];
          averagers[i][j] = averager;
        }
    }
  return self;
}

- (void)printAverages
{
  unsigned i;

  for (i = 0; i < PHYTOCOUNT; i++)
    {
      unsigned j;
      
      for (j = 0; j < PIGMENTCOUNT; j++)
        {
          id averager = averagers[i][j];
          
          [averager update];
          printf ("%u,%u: %f\n", i, j, [averager getAverage]);
        }
    }
}
@end

int
main (int argc, const char **argv)
{
  id controller;
  unsigned i;

  initSwarm (argc, argv);

  controller = [Controller create: globalZone];
  [controller printAverages];
  return 0;
}


/*
Local Variables:
compile-command: "/opt/gnu/bin/gcc -o averager -g -Wno-import 
-L/opt/SUNWtcl/8.0/sun4/lib -R/opt/SUNWtcl/8.0/sun4/lib -L/opt/SDGblt/2.4g/lib 
-R/opt/SDGblt/2.4g/lib -L/opt/SDGlibffi/1.20/lib -R/opt/SDGlibffi/1.20/lib 
-L/opt/SDGswarm/1.4.1/lib -L/opt/SDGzlib/1.1.3/lib -L/usr/local/X11/lib 
-R/usr/local/X11/lib -L/usr/openwin/lib -R/usr/openwin/lib 
-L/opt/SDGhdf5/1.0.1/lib -I/opt/SDGswarm/1.4.1/include averager.m -lanalysis 
-lsimtools -lsimtoolsgui -lactivity -ltkobjc -lrandom -lobjectbase  -ldefobj 
-lcollections -lmisc  -ltclobjc -ltk8.0 -ltcl8.0 -lBLT -lsocket -ldl -lnsl 
-L/usr/openwin/lib -lhdf5 -lpng -lz -lXpm -lX11 -lffi -lm -lobjc -lpthread 
-lposix4"
End:
*/

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]