next up previous contents index
Next: 6.2.4 Alternatives to nemo_main Up: 6.2 The NEMO Macro Previous: 6.2.2 getparam.h   Contents   Index


6.2.3 Advanced User Interface and String Parsing

Here we describe setparam to add some interactive capabilities in a standard way to NEMO. Values of keywords should only be accessed and modified this way. Since keywords are initialized/stored within the source code, most compilers will store their values in a read-only part of data area in the executable image. Editing them may cause unpredictable behavior.

If a keyword string contains an array of items of the same type, one can use either nemoinpX or getXrange, depending if you know how many items to expect in the string. The getXrange routines will allocate a new array which will contain the items of the parsed string. If you do already have a declared array, and know that all items will fit in there, the nemoinpX routines will suffice.

An example of usage:

    double *x = NULL;
    double y[NYMAX];
    int nxret, nyret;
    int nxmax=0;

    nyret = nemoinpd(getparam("y"), y, NYMAX);

    nxret = getdrange(getparam("x"), &x, &nxmax);

In the first call the number of elements to be parsed from an input keyword y= is limited to NYMAX, and is useful when the number of elements is expected to be small or more or less known. The actual number of elements returned in the array y[] is nyret.

When the number of elements to be parsed is not known at all, or one needs complete freedom, the dynamic allocation feature of getdrange can be used. The pointer x is initialized to NULL, as well as the item counter nxmax. After calling getdrange, x will point to an array of length nxmax, in which the first nxret element contain the parsed values of the input keyword x=. Proper re-allocation will be done when a larger space is need on subsequent calls.

Both routines return negative error return codes, see nemoinp(3NEMO).

More complex parsing is also done by calling burststring first to break a string in pieces, followed by a variety of functions.


next up previous contents index
Next: 6.2.4 Alternatives to nemo_main Up: 6.2 The NEMO Macro Previous: 6.2.2 getparam.h   Contents   Index
(c) Peter Teuben