swarm-support
[Top][All Lists]
Advanced

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

Re: swarm-1.2 and Drone [command-line arguments]


From: Steve Emsley
Subject: Re: swarm-1.2 and Drone [command-line arguments]
Date: Thu, 27 Aug 1998 16:52:21 +0100

Sven,

I've recently been leaning towards a DRONE solution to experiment
management with the Swarm command-line manager.

I'll summarize my solution using a subclassed Argument class.
--------------------
APEXArguments.h

#import <objectbase/Arguments.h>
#import <objectbase.h>

@interface APEXArguments: Arguments {
  const char *paramFileArg;
}

+createBegin: (id) aZone;
-(const char *)getParamFileArg;

@end

--------------------
APEXArguments.m

#import "APEXArguments.h"

@implementation APEXArguments

+ createBegin: aZone
{
  static struct argp_option options[] = {
    {"params", 'p', "FILENAME", 0, "Set parameter file", 4},
    { 0 }
  };
  APEXArguments *obj = [super createBegin: aZone];
  [obj addOptions: options];

  return obj;
}

- (int)parseKey: (int)key arg: (const char *)arg
{
  switch (key){
  case 'p': paramFileArg = arg;
    return 0;
  default: 
    return [super parseKey: key arg: arg];
  }
}

- (const char *)getParamFileArg { return paramFileArg; }

@end

---------------------
main.m

#import "APEXArguments.h"

int
main (int argc, const char **argv)
{
  [APEXArguments createBegin: globalZone];

  initSwarmArguments(argc, argv, [APEXArguments class]);

...

 return 0;
}

---------------------

O.K. the above creates your subclass and registers the command-line
arguments so that typing 'app --help' shows all. Note the call to
'initSwarmArguments' rather than 'initSwarm'. The APEXArguments class
is accessed using the object id 'arguments' that is initialized by the
Arguments class (not you). So, I then have a method in ModelSwarm that
I call during the modelSwarm creation phase (in BatchSwarm in my
case).

 -parseArgs {
  // if command-line arguments have been used parse them
  char *tmp;

  if (arguments) {
    if ( [arguments getParamFileArg] ) 
      filePARAM =  [arguments getParamFileArg];
    if ( [arguments getBiotaFileArg] ) 
      fileBIOTA =  [arguments getBiotaFileArg];
    if ( [arguments getLatitudeArg] ) {
      latitude = strtod([arguments getLatitudeArg], &tmp);
      if (!strcmp(tmp,"S")) latitude *= -1;
    }
    if ( [arguments getDepthArg] )
      depth = strtod([arguments getDepthArg], &tmp);
    if ( [arguments getLayerArg] )
      layers = atoi([arguments getLayerArg]);
  }
  return self;
}

----------------
As you can see I actually have more command-line parameters than I
have shown in the APEXArgument examples but have included them here to
illustrate how you deal wiht string, double and int.

So that works O.K. However, there are problems incorporating this into
DRONE. All DRONE parameters seem to require -Dparam=value. Although I
haven't tested it yet it looks like Swarm command-line arguments can
only be single characters. The simple solution is to just have one
parameter i.e. the string value of a parameter filename. Then use a
wrapper similar to the gawrap in the DRONE example directory to write
that parameter file.

Another problem I've had occured using command-line parameters with a
GraphicSwarm. ElectricFence objected to various memory problems in
respect to Probes... but I guess the whole point of using a parameter
manager is for batch jobs so I'm ignoring that for now.

Anyway, hope this helps you set up the Swarm command-line parser. I
agree that the documentation omits several important details. If this
works for you perhaps it could go to the FAQ.

Once you can get command-line parameters, including the random-seed, I
guess (hope) that you can write a warapper to use all the drone
functionality or a simpler customized script to provide the same
functionality that Ginger has hand-crafted into Gecko.

Good luck
-- 

  Steve Emsley
-----------------------------------------------------------------
  address@hidden                    www.oikos.ac.uk/~sme

                  ==================================
   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]