Close This Window

Merci de télécharger les logos officiels de l'ILL ici


Pour utiliser sur le web

Pour imprimer en haute résolution


Télécharger PNG

Télécharger TIF


Télécharger JPG

Télécharger EPS



Computing for Science

The Computing for Science (CS) group supports ILL scientists, students and visitors in a number of activities including data analysis, instrument simulation and sample simulation.

Back to ILL Homepage
English French Deutsch 

All Software

8. LAMP Macros

1. Command Files

Command files are simply a list of functions or commands written into a file as they would be typed in the formula-entry area. The file can then be called up in the formula-entry and Do input text area and the functions it contains will be executed, line by line.

Files can be written in a window which is opened by pressing User Macros? button and selecting the Create a new: Batch option, the filename should be given a *.prox form, select Write new file to save it in your directory.

  • An Example Command File: demo.prox

    w1=w1(*,61:95)/total(n1)
    w2=w2(*,61:95)/total(n2)
    w3=w3(*,61:95)/total(n3)
    w3=w3-w2
    w1=w1-w2
    w3=vnorm(w3,w1,200,300)

This would be executed by entering @demo in the formula-entry or Do input text area.

To top

2. Command Files with Loops using the XBU interpreter

You have access to the XBU interpreter from item "Lamp/Layout" in the menu-bar of Lamp.
You will be able to execute a command file in which you can insert statements like While , for , if. This tool is very usefull for writing simple codes without programming and compiling. You also write some conditionnal codes in the runtime version of Lamp (see the Help in the XBU interface).

To top

3. Compileable Macros (*.pro files)

More elaborate IDL functions and commands (such as t2eused to convert time-of-flight channels into energy units) can be written, compiled and saved as macros using LAMP. They can then be executed in the formula-entry area.

A macro procedure can be written by pressing the User Macros? button and selecting the Create a new: Macro option, the filename should be given a *.proform. After writing the file pressing Write new file will compile and save it, any compile errors will appear in the shell window from which LAMP was started.

3.1. IDL Basics

The main things to be aware of are:-

  • IDL works on entire arrays.
  • The separator is always a comma (not a space) for procedures and parameters.
  • The default for integers is 2 bytes.
  • Indices start at 0. For example if w1 is dimensioned at 512 this means w1[0...511].
  • Changes to common block @lamp.cbk is dangerous.

To top

3.2. INTERNALS accessible functions

Lot of internal functions are accessible and can be called by user. Their descriptions can be visualised from "Internal ROUTINES" in item "Info" of the main Menu-bar. (i.e take_datp , give_datp , mod_datp , etc...)

To top

3.3. Passing of Common Variables

All variables relating to a workspace are available. There are two ways to get them :

- by including the parameter : datp in a user defined macro.
- by invoking the TAKE_DATP procedure with datp as the only parameter, i.e : take_datp, datp
  If you use this way and have changed datp, you have to end your procedure or function by give_datp, datp

In both cases, datp variable attached to the workspace invoked in the command line will be internally set by lamp with the following structure :

datp= {x:                    x,              (vector of x coordinates.)
              y:                    y,              (vector of y coordinates.)
              z:                    z,               (vector of z coordinates.)
              e:                    e,               (the errors associated to DATA, same size as DATA)
              n:                    n,              (monitor spectra)
              p:                    p,              (vector of parameter values)
              pv:                  pv,            (a table of any dimensions containing other parameter values)
              par_txt:         par_txt,    (string array of text associated to DATP.P)
              w_tit:            w_tit,       (main title)
              x_tit:             x_tit,        (x axis title)
              y_tit:             y_tit,        (y axis title)
              z_tit:             z_tit,         (z axis title)
              other_tit:      other_tit,  (subtitle)
              time:              date }       (string date of the experiment.)

In fact, this structure allows one to modify all the parameters of a single workspace.
If you want to resize a parameter variable, you have to use the mod_datp procedure.
Its calling sequence is mod_datp, datp, 'tag_name',value. For example, to replace datp.x, you should use
mod_datp, datp 'x' , new_x_value.

In case of a function, i.e : w1=f(w2,datp) or w1=f(w2), w2 parameters (and eventual modifications) are reaffected by lamp to w1. W2 parameters are not modified.

  • Calls accepted using or not datp parsing (Function or procedure)

    W1 = f(W2,W3[,datp])    W1 parameters will receive W2 parameters
    a = f(W2[,datp])        W2 parameters might be changed
    W1 = f(a[,datp])        W1 parameters might be changed
    proc,W1[,datp]          W1 parameters might be changed

  • An Example Macro with datp parsing: demo.pro

    function demo,w,datp     ; (program line, demonstrates use of function)
    ;** The call is w1=demo(w2,datp)
            wret=w(10:* , *)
            mod_datp,datp, 'X', datp.x(10:*)
            datp.y=datp.y^2
            datp.p(9)=123  
    return, wret             ;return result
    end
    In this example entering w1=demo(w2,datp) in the formula entry window would result in workspace w1 equal to w2 cleared of its first 10 channels, its y scale, y1, equal y2 squared (Qsquared for example) and parameter, p1(9), being changed to 123 (for TOF instruments this is the elastic peak channel).
    Note that mod_datp is used to resize the X parameter.
    All other w1 parameters will have the w2 parameters unchanged.

  • Same example as above without parsing datp:

    function demo,w
    ;** The call is w1=demo(w2)
        take_datp,datp
            wret=w(10:* , *)
            mod_datp,datp,'X',datp.x(10:*)
            datp.y=datp.y^2
            datp.p(9)=123
        give_datp,datp
    return,wret
    end

  • How LAMP deals with macros

    When LAMP parses the formula entry it stores the number of the target workspace on the line in a variable (let's say target) and the second in another variable (let's say source). LAMP transfers all variables associated with the source workspace into datp variables. after the call, all datp parameters are copied into target parameters. If there is only one workspace in the command line, source and target are the same, the standalone workspace.
    If you use a function call, as in example above, you must return the w array. If you use a procedure the return has no argument.

  • Statistics errors handling

    To each workspace is associated a variable, named e, which should contain the statistics errors. "w" and "e" must have the same dimensions, and user might fill the "e" variable if needed. The updating of this variable is a user responsability when you manipulate workspaces using many operators or a function.

To top

3.4. Getting Common Variables from RDRUN, RDAND, RDOPR used in macros

All variables relating to a workspace are available.
When used in macros you can add the keyword DATP= datp to get all data parameters in the structure variable datp
ex: w1=rdand(1234,1237,DATP=datp).

To top

3.5. Simple IDL programming

Loops
    for i=1,n do begin
    a=a+1
    endfor
;alternatively
    while a lt b do begin
    a=a+1
    endwhile

If then
    if a eq b then c=d

If then begin
    if a ne b then begin
    c=d
    e=f
    endif

If then else
    if a lt b then begin
    c=d
    endif else begin
    e=f
    endelse

Case
    case i of
    1: j=7
    2: j=6
    3: j=5
    4: j=4
    else:
    endcase

Declaring arrays
    To declare an integer array, say 'i', of dimensions 3x4:
        i=intarr(3,4)
    To declare an long array, say 'k', of dimensions 5x6x10:
        k=lonarr(5,6,10)
    To declare a floating array, say 'r', of dimensions 3x3x2:
        r=fltarr(3,3,2)
    To declare a string array, say 's', of dimensions 5x5:
        s=strarr(5,5)


see Changing Data-type for methods of changing between these.

To top

Previous - 8. LAMP Macros - Next