[Prev] [Next] [TOC] [Chapters]
22 Appendix D: NED Functions
The functions that can be used in NED expressions and ini files are the
following. The question mark (as in “rng?”) marks optional arguments.
22.1 Category "conversion":
- double : quantity double(any x)
Converts x to double, and returns the result. A boolean argument becomes 0 or 1; a string is interpreted as number; an XML argument causes an error. Units are preserved.
- int : intquantity int(any x)
Converts x to int, and returns the result. A boolean argument becomes 0 or 1; a double is converted using floor(); a string is interpreted as number; an XML argument causes an error. Units are preserved.
- string : string string(any x)
Converts x to string, and returns the result.
22.2 Category "math":
- acos : double acos(double)
Trigonometric function; see standard C function of the same name
- asin : double asin(double)
Trigonometric function; see standard C function of the same name
- atan : double atan(double)
Trigonometric function; see standard C function of the same name
- atan2 : double atan2(double, double)
Trigonometric function; see standard C function of the same name
- ceil : double ceil(double)
Rounds down; see standard C function of the same name
- cos : double cos(double)
Trigonometric function; see standard C function of the same name
- exp : double exp(double)
Exponential; see standard C function of the same name
- fabs : quantity fabs(quantity x)
Returns the absolute value of the quantity.
- floor : double floor(double)
Rounds up; see standard C function of the same name
- fmod : quantity fmod(quantity x, quantity y)
Returns the floating-point remainder of x/y; unit conversion takes place if needed.
- hypot : double hypot(double, double)
Length of the hypotenuse; see standard C function of the same name
- log : double log(double)
Natural logarithm; see standard C function of the same name
- log10 : double log10(double)
Base-10 logarithm; see standard C function of the same name
- max : quantity max(quantity a, quantity b)
Returns the greater one of the two quantities; unit conversion takes place if needed.
- min : quantity min(quantity a, quantity b)
Returns the smaller one of the two quantities; unit conversion takes place if needed.
- pow : double pow(double, double)
Power; see standard C function of the same name
- sin : double sin(double)
Trigonometric function; see standard C function of the same name
- sqrt : double sqrt(double)
Square root; see standard C function of the same name
- tan : double tan(double)
Trigonometric function; see standard C function of the same name
22.3 Category "misc":
- firstAvailable : string firstAvailable(...)
Accepts any number of strings, interprets them as NED type names (qualified or unqualified), and returns the first one that exists and its C++ implementation class is also available. Throws an error if none of the types are available.
- select : any select(int index, ...)
Returns the <index>th item from the rest of the argument list; numbering starts from 0.
- simTime : quantity simTime()
Returns the current simulation time.
22.4 Category "ned":
- ancestorIndex : int ancestorIndex(int numLevels)
Returns the index of the ancestor module numLevels levels above the module or channel in context.
- fullName : string fullName()
Returns the full name of the module or channel in context.
- fullPath : string fullPath()
Returns the full path of the module or channel in context.
- parentIndex : int parentIndex()
Returns the index of the parent module, which has to be part of module vector.
22.5 Category "random/continuous":
- beta : double beta(double alpha1, double alpha2, int rng?)
Returns a random number from the Beta distribution
- cauchy : quantity cauchy(quantity a, quantity b, int rng?)
Returns a random number from the Cauchy distribution
- chi_square : double chi_square(int k, int rng?)
Returns a random number from the Chi-square distribution
- erlang_k : quantity erlang_k(int k, quantity mean, int rng?)
Returns a random number from the Erlang distribution
- exponential : quantity exponential(quantity mean, int rng?)
Returns a random number from the Exponential distribution
- gamma_d : quantity gamma_d(double alpha, quantity theta, int rng?)
Returns a random number from the Gamma distribution
- lognormal : double lognormal(double m, double w, int rng?)
Returns a random number from the Lognormal distribution
- normal : quantity normal(quantity mean, quantity stddev, int rng?)
Returns a random number from the Normal distribution
- pareto_shifted : quantity pareto_shifted(double a, quantity b, quantity c, int rng?)
Returns a random number from the Pareto-shifted distribution
- student_t : double student_t(int i, int rng?)
Returns a random number from the Student-t distribution
- triang : quantity triang(quantity a, quantity b, quantity c, int rng?)
Returns a random number from the Triangular distribution
- truncnormal : quantity truncnormal(quantity mean, quantity stddev, int rng?)
Returns a random number from the truncated Normal distribution
- uniform : quantity uniform(quantity a, quantity b, int rng?)
Returns a random number from the Uniform distribution
- weibull : quantity weibull(quantity a, quantity b, int rng?)
Returns a random number from the Weibull distribution
22.6 Category "random/discrete":
- bernoulli : int bernoulli(double p, int rng?)
Returns a random number from the Bernoulli distribution
- binomial : int binomial(int n, double p, int rng?)
Returns a random number from the Binomial distribution
- geometric : int geometric(double p, int rng?)
Returns a random number from the Geometric distribution
- intuniform : int intuniform(intquantity a, intquantity b, int rng?)
Returns a random integer uniformly distributed over [a, b]
- negbinomial : int negbinomial(int n, double p, int rng?)
Returns a random number from the Negbinomial distribution
- poisson : int poisson(double lambda, int rng?)
Returns a random number from the Poisson distribution
22.7 Category "strings":
- choose : string choose(int index, string list)
Interprets list as a space-separated list, and returns the item at the given index. Negative and out-of-bounds indices cause an error.
- contains : bool contains(string s, string substr)
Returns true if string s contains substr as substring
- endsWith : bool endsWith(string s, string substr)
Returns true if s ends with the substring substr.
- expand : string expand(string s)
Expands $ variables ($configname, $runnumber, etc.) in the given string, and returns the result.
- indexOf : int indexOf(string s, string substr)
Returns the position of the first occurrence of substring substr in s, or -1 if s does not contain substr.
- length : int length(string s)
Returns the length of the string
- replace : string replace(string s, string substr, string repl, int startPos?)
Replaces all occurrences of substr in s with the string repl. If startPos is given, search begins from position startPos in s.
- replaceFirst : string replaceFirst(string s, string substr, string repl, int startPos?)
Replaces the first occurrence of substr in s with the string repl. If startPos is given, search begins from position startPos in s.
- startsWith : bool startsWith(string s, string substr)
Returns true if s begins with the substring substr.
- substring : string substring(string s, int pos, int len?)
Return the substring of s starting at the given position, either to the end of the string or maximum len characters
- substringAfter : string substringAfter(string s, string substr)
Returns the substring of s after the first occurrence of substr, or the empty string if s does not contain substr.
- substringAfterLast : string substringAfterLast(string s, string substr)
Returns the substring of s after the last occurrence of substr, or the empty string if s does not contain substr.
- substringBefore : string substringBefore(string s, string substr)
Returns the substring of s before the first occurrence of substr, or the empty string if s does not contain substr.
- substringBeforeLast : string substringBeforeLast(string s, string substr)
Returns the substring of s before the last occurrence of substr, or the empty string if s does not contain substr.
- tail : string tail(string s, int len)
Returns the last len character of s, or the full s if it is shorter than len characters.
- toLower : string toLower(string s)
Converts s to all lowercase, and returns the result.
- toUpper : string toUpper(string s)
Converts s to all uppercase, and returns the result.
- trim : string trim(string s)
Discards whitespace from the start and end of s, and returns the result.
22.8 Category "units":
- convertUnit : quantity convertUnit(quantity x, string unit)
Converts x to the given unit.
- dropUnit : double dropUnit(quantity x)
Removes the unit of measurement from quantity x.
- replaceUnit : quantity replaceUnit(quantity x, string unit)
Replaces the unit of x with the given unit.
- unitOf : string unitOf(quantity x)
Returns the unit of the given quantity.
22.9 Category "units/conversion":
- A : quantity A(quantity x)
Converts to A (ampere) from a compatible unit or a dimensionless number.
- Ah : quantity Ah(quantity x)
Converts to Ah (ampere-hour) from a compatible unit or a dimensionless number.
- As : quantity As(quantity x)
Converts to As (ampere-second) from a compatible unit or a dimensionless number.
- B : quantity B(quantity x)
Converts to B (byte) from a compatible unit or a dimensionless number.
- C : quantity C(quantity x)
Converts to C (coulomb) from a compatible unit or a dimensionless number.
- GB : quantity GB(quantity x)
Converts to GB (gigabyte) from a compatible unit or a dimensionless number.
- GHz : quantity GHz(quantity x)
Converts to GHz (gigahertz) from a compatible unit or a dimensionless number.
- etc.
A similar NED function exists for all registered measurement units.
Units are listed in section [19.5.9].
22.10 Category "xml":
- xml : xml xml(string xmlstring, string xpath?)
Parses the given XML string into a cXMLElement tree, and returns the root element. When called with two arguments, it returns the first element from the tree that matches the expression given in simplified XPath syntax.
- xmldoc : xml xmldoc(string filename, string xpath?)
Parses the given XML file into a cXMLElement tree, and returns the root element. When called with two arguments, it returns the first element from the tree that matches the expression given in simplified XPath syntax.
[Prev] [Next] [TOC] [Chapters]