ns2::Parser Class Reference


Detailed Description

class for parsing command line arguments
Author:
Thimor Bohn <bohn@itm.uni-luebeck.de>

Definition at line 8 of file ns2/Parser.java.


Static Public Member Functions

static Parameter parse (String[] args) throws IllegalArgumentException

Member Function Documentation

static Parameter ns2::Parser::parse ( String[]  args  )  throws IllegalArgumentException [inline, static]

method for parsing command line arguments

Parameters:
args command line arguments
Returns:
parsed arguments
Exceptions:
IllegalArgumentException 

Definition at line 15 of file ns2/Parser.java.

00015                                                                                  {
00016         String net         = "";
00017         String trace       = "";
00018         String activity    = "";
00019         String mobility    = "";
00020         String config      = "";
00021         double begin       = 0;
00022         double end         = 0;
00023         double penetration = 0;
00024         long   seed        = 0;
00025         
00026         boolean hasNet         = false;
00027         boolean hasTrace       = false;
00028         boolean hasActivity    = false;
00029         boolean hasMobility    = false;
00030         boolean hasConfig      = false;
00031         boolean hasBegin       = false;
00032         boolean hasEnd         = false;
00033         boolean hasPenetration = false;
00034         
00035         for (int i=0; i<args.length; i++) {
00036             if ("ns2".equals(args[i].toLowerCase())) {
00037             }
00038             
00039             if ("-n".equals(args[i])) {
00040                 // net file
00041                 if (++i<args.length) {
00042                     if (!args[i].startsWith("-")) {
00043                         net = args[i];
00044                         hasNet = true;
00045                     }
00046                 }
00047             }
00048             
00049             if ("-t".equals(args[i])) {
00050                 // trace file
00051                 if (++i<args.length) {
00052                     if (!args[i].startsWith("-")) {
00053                         trace = args[i];
00054                         hasTrace = true;
00055                     }
00056                 }
00057             }
00058             
00059             if ("-a".equals(args[i])) {
00060                 // activity file
00061                 if (++i<args.length) {
00062                     if (!args[i].startsWith("-")) {
00063                         activity = args[i];
00064                         hasActivity = true;
00065                     }
00066                 }
00067             }
00068             
00069             if ("-m".equals(args[i])) {
00070                 // mobility file
00071                 if (++i<args.length) {
00072                     if (!args[i].startsWith("-")) {
00073                         mobility = args[i];
00074                         hasMobility = true;
00075                     }
00076                 }
00077             }
00078             
00079             if ("-c".equals(args[i])) {
00080                 // config file
00081                 if (++i<args.length) {
00082                     if (!args[i].startsWith("-")) {
00083                         config = args[i];
00084                         hasConfig = true;
00085                     }
00086                 }
00087             }
00088             
00089             if ("-b".equals(args[i])) {
00090                 // begin time
00091                 if (++i<args.length) {
00092                     begin = Double.parseDouble(args[i]);
00093                     if (begin >= 0) {
00094                         hasBegin = true;
00095                     }
00096                 }
00097             }
00098             
00099             if ("-e".equals(args[i])) {
00100                 // begin time
00101                 if (++i<args.length) {
00102                     end = Double.parseDouble(args[i]);
00103                     if (begin < end) { 
00104                         hasEnd = true;
00105                     }
00106                 }
00107             }
00108             
00109             if ("-p".equals(args[i])) {
00110                 // penetration factor
00111                 if (++i<args.length) {
00112                     if (!args[i].startsWith("-")) {
00113                         penetration = Double.parseDouble(args[i]);
00114                         if (penetration>=0 && penetration<=1) {
00115                             hasPenetration = true;
00116                         } else {
00117                             penetration = 0;
00118                         }
00119                     }
00120                 }
00121             }
00122             
00123             if ("-s".equals(args[i])) {
00124                 // seed value
00125                 if (++i<args.length) {
00126                     seed = Long.parseLong(args[i]);
00127                     //hasSeed = true;
00128                 }
00129             }
00130         }
00131         
00132         // must have net file argument
00133         if (!hasNet) {
00134             throw new IllegalArgumentException("no netfile specified!");
00135         }
00136         
00137         // must have trace file argument
00138         if (!hasTrace) {
00139             throw new IllegalArgumentException("no tracefile specified!");
00140         }
00141         
00142         // must have activity file argument
00143         if (!hasActivity) {
00144             throw new IllegalArgumentException("no activity specified!");
00145         }
00146         
00147         // must have mobility file argument
00148         if (!hasMobility) {
00149             throw new IllegalArgumentException("no mobility specified!");
00150         }
00151         
00152         // must have config file argument
00153         if (!hasConfig) {
00154             throw new IllegalArgumentException("no config specified!");
00155         }
00156         
00157         // defaults to begin of sumo simulation
00158         if (!hasBegin) {
00159             begin = 0;
00160         }
00161         
00162         // defaults to end of sumo simulation
00163         if (!hasEnd) {
00164             // end not known yet
00165             end = begin;
00166         }
00167 
00168         // penetration argument: optional
00169         
00170         // seed argument: optional
00171                 
00172         return new Parameter(net, trace, activity, mobility, config, begin, end, penetration, seed, hasPenetration);
00173     }


The documentation for this class was generated from the following file:

Generated on Wed May 5 00:07:02 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6