Macro examples

This appendix gives you some examples of macros. You may use the macros that appear here or write your own. For more detailed information on working with macros, see Chapter 4. Macros.


4dv.mac


; Macro manufactures a simple 4D (16x16x16x16)
; matrix with synthetic cross peaks located
; at (D1,D2,D3,D4) indices (8,8,8,4),
; (8,8,8,8), and at (8,8,8,13).
;
;
tim z ; start chronograph
;
bun 0 ; initialize bundle mode
;
; initialize matrix values
ty Initializing matrix &matfil
def count 0
def limit 1000
bun 1
for d1vec 1 &vector
lwb
ze
swb
nex
bun 0
ty
; make cross peaks
ty Creating crosspeak at (8,8,8,4)...
for loop1 7 9
for loop2 7 9
for loop3 7 9
for loop4 3 5
mpv &loop1 &loop2 &loop3 &loop4 1000000
nex
nex
nex
nex
mpv 8 8 8 4 2500000
;
ty Creating crosspeak at (8,8,8,8)...
for loop1 7 9
for loop2 7 9
for loop3 7 9
for loop4 7 9
mpv &loop1 &loop2 &loop3 &loop4 1000000
nex
nex
nex
nex
mpv 8 8 8 8 5000000
;
ty Creating crosspeak at (8,8,8,13)...
for loop1 7 9
for loop2 7 9
for loop3 7 9
for loop4 12 14
mpv &loop1 &loop2 &loop3 &loop4 1000000
nex
nex
nex
nex
mpv 8 8 8 13 2500000
;
ty -done-
time r time
ty Elapsed time was &time seconds.
end


diag.mac


; Macro extracts the diagonal plane out of a
; square-cube 3D matrix and stores diagonal
; as a 2D matrix. Caution, macro will overwrite
; matrix defined as 'mx2d'.
;
; Macro employs vector shuttle which effectively
; exploits FELIX bricks.
;
get '3D matrix -->' mx3d
get '2D extract -->' mx2d
;
inq mat &mx3d exist
if &exist eq 0 then
ty Matrix &mx3d not found!
go scram
eif
inq mat &mx2d exist
if &exist eq 0 then
ty Matrix &mx2d not found!
go scram
eif
;
mat &mx3d r
def nd1 &d1size
def nd3 &d3size
bld &mx2d 2 &nd1 &nd1 0 y
mat &mx2d r
def brk &b2size
ty brick=&brk
eva npass (&nd3/&brk)
eva nbuff (&brk+1)
ty nbuff=&nbuff
def vec 0
;
cmx
;
dat 0
cfg &nd1 &nbuff
ty buffers=&buffers
for pass 1 &npass
ty pass=&pass
mat &mx2d r
for xbuff 1 &brk
eva nvec (&vec+&xbuff)
loa 0 &nvec &nvec
stb &xbuff
ty loading vector=&nvec
next
mat &mx2d w
for xbuff 1 &brk
eva nvec (&vec+&xbuff)
lwb &xbuff
sto 0 &nvec
ty storing vector=&nvec
next
eva vec (&vec+&brk)
next
cmx
scram:
end


dss.mac


; Macro generates a so-called `doubly-phase-shifted'
; window function. Shows that as expected, anything is
; possible. For cognoscente only...
;
; Initial phase is 90-degrees, final phase is 165-degrees.
;
def begin 90
def end 165
def size 512
eva incre (1.0*(&begin-&end)/&size)
ze
stb 1
def animat 1
ty ' '
for point 1 &size
esc out
if &out ne 0 scram
eva shift (&begin-(&point-1)*&incre)
set 1
ty shift=&shift $
ss &size &shift
dr
gv &point value
ldb 1
pv &point &value
stb 1
next
scram:
def animat 0
end


eval_point.mac


; Macro evaluates a particular point in each
; vector of a serial 2D data file and stores
; output in a FELIX macro file. Macro presents
; example of using one macro to build another
; macro.
;
get 'Input Data File -->' inpdata
get 'Output Data File -->' outdata
get 'Data Point to Measure -->' point
get 'Number of Exps -->' num_exp
opn txt &outdata 0
for loop 1 &num_exp
re &inpdata
gv &point dataval
put &dataval
next
cls
end


lpf_d2.mac

; Simple macro to adjust the 1st point in a
; D2(t1)-vector of a transformed 2D matrix
; using LP. Removes missampling artifact in
; virtual acqisition. Caution, original
; matrix is overwritten.
;
get 'Specify matrix -->' mat
inq mat &mat exist
if &exist eq 0 then
ty Matrix &mat not found!!!
go scram
eif
;
cmx
mat &mat w
;
for row 1 &d1size
loa &row 0
hft
ift
lpf
ft
mul 2
red
sto &row 0
ty col=&row $
next
scram:
end


madd.mac


; Macro sums two matrices in a D1-vector-wise
; fashion. Macro exploits the FELIX matrix format
; to improve efficiency. Caution, macro will
; overwrite 'sum matrix'.
;
get 'Matrix 1 --> ' mat1
get 'Matrix 2 -->' mat2
get 'Sum Matrix --> ' mat3
;
inq mat &mat1 exist
if &exist eq 0 then
ty Matrix &mat1 not found!
go scram
eif
inq mat &mat2 exist
if &exist eq 0 then
ty Matrix &mat2 not found!
go scram
eif
;
mat &mat1
if &dimen ne 2 not2d
def ncol &d1size
def nrow &d2size
def brick &b2size
mat &mat2
if &dimen ne 2 not2d
if &d1size ne &ncol badsize
if &d2size ne &nrow badsize
ty Building matrix &mat3...
bld &mat3 2 &ncol &nrow 0 y
cmx
eval ccol (&ncol/2)
eva nbuf (&brick+1)
cfg &ccol &nbuf
mat &mat1 r
mat &mat2 r
mat &mat3 w
ty Adding &mat1 and &mat2 to store in &mat3
def count 0
loop:
if &count ge &nrow done
mat &mat1
for ibuf 1 &buffers
eva row (&count+&ibuf)
loa 0 &row
stb &ibuf
ty loading= &row $
next
mat &mat2
for ibuf 1 &buffers
eva row (&count+&ibuf)
loa 0 &row
adb &ibuf
ty adding= &row $
next
mat &mat3
for ibuf 1 &buffers
ldb &ibu
eva row (&count+&ibuf)
sto 0 &row
ty storing= &row $
next
eva count (&count+&buffers)
go loop
done:
cmx
end
not2d:
ty Matrix must be 2-D.
end
badsize:
ty Matrices must be same size.
scram:
end


msub.mac


; Macro subtracts two matrices in a D1-vector-wise
; fashion. Macro exploits the FELIX matrix format
; to improve efficiency. Caution, macro will
; overwrite 'difference matrix'.
;
get 'Matrix 1 -->' mat1
get 'Matrix 2 -->' mat2
get 'Difference Matrix -->' mat3
;
inq mat &mat1 exist
if &exist eq 0 then
ty Matrix &mat1 not found!
go scram
eif
inq mat &mat2 exist
if &exist eq 0 then
ty Matrix &mat2 not found!
go scram
eif
;
mat &mat1
if &dimen ne 2 not2d
def ncol &d1size
def nrow &d2size
def brick &b2size
mat &mat2
if &dimen ne 2 not2d
if &d1size ne &ncol badsize
if &d2size ne &nrow badsize
ty Building matrix &mat3...
bld &mat3 2 &ncol &nrow 0 y
cmx
eval ccol (&ncol/2)
eval nbuf (&brick+1)
cfg &ccol &nbuf
mat &mat1 r
mat &mat2 r
mat &mat3 w
ty Subtracting &mat2 from &mat1 to store in &mat3
def count 0
loop:
if &count ge &nrow done
mat &mat1
for ibuf 1 &nframe
eva row (&count+&ibuf)
loa 0 &row
stb &ibuf
ty Loading= &row $
next
mat &mat2
for ibuf 1 &nframe
eva row (&count+&ibuf)
loa 0 &row
mul -1.0
adb &ibuf
ty Subtract= &row $
next
mat &mat3
for ibuf 1 &nframe
ldb &ibuf
eva row (&count+&ibuf)
sto 0 &row
ty Storing= &row $
next
eva count (&count+&nframe)
go loop
done:
cmx
end
not2d:
ty Matrix must be 2-D.
end
badsize:
ty Matrices must be same size.
scram:
end


mult.mac


; Complex data point in work is multiplied by a
; user-specified value (real number or integer).
;
get 'Specify point to vary -->' point
get 'Specify point multiplier -->' mult
gv &point rvalue
exc
gv &point ivalue
exc
eva real (&mult*&rvalue)
eva imag (&mult*&ivalue)
srv &point &point &real &imag
end


old2new.mac

; Macro converts old serial FELIX data file to
; new data file format.
;
get 'old data file --> ' fil1
get 'new data file --> ' fil2
def count 0
loop:
re &fil1
if &status ne 0 scram
wn &fil2
eval count (&count+1)
ty count= &count$
go loop
scram:
ty &count records converted.
end


psi.mac

; Macro conducts the imaginary-part of a D1 hypercomplex
; transform on data acquired in separate real and
; imaginary data files- for antiquaries only!
cl
for row 1 400
loa 0 &row
stb 1
re imagpart.ser
bc 0.05
ss 400 90
zf 2048
bft
def phase0 89.95
def phase1 -21.43
ph
pol 4
exc
zr
adb 1
ldb 1
exc
sto 0 &row
ty row=&row $
next
end


psr.mac

; Macro conducts the real-part of a D1 hypercomplex
; transform on data acquired in separate real and
; imaginary data files- for antiquaries only!
cl
for row 1 400
re realpart.dat
bc 0.05
ss 400 90
zf 2048
bft
def phase0 89.9
def phase1 -21.43
ph
pol 4
zi
sto 0 &row
ty row=&row $
next
end


rev_bundle.mac

; Reverse vectors of a ND matrix using bundle-mode
; access. Note that original matrix is overwritten!!!
;
get 'Specify matrix -->' mat
inq mat &mat exist
if &exist eq 0 then
ty Matrix &mat not found!!!
go scram
eif
;
get 'Specify dimension to reverse -->' revd
;
cmx
mat &mat w
def count 0
;
bun 0
tim z
for vec 1 &vector
bun &revd
ty There are &vector vectors to process...
lwb
rev
swb
ty Vector=&vector $
next
;
tim r time
ty Elapsed time was &time seconds.
;
scram:
end


zap.mac

; Original macro written by Dr. Walter Massefski.
; Macro conducts a 'circular-shift' on data to place
; 'solvent' peak at exact center, then applies the
; convolution-based (cnv) solvent suppression and back
; shifts the data.
;
ty Specify window type
get '(Sinebell=0, Gaussian=1) -->' wintyp
if &wintyp ne 0 or &wintyp ne 1 then
ty Invalid window-type selection.
go scram
eif
get 'Window size -->' zaparg
eva midpt (&datsiz/2+1)
cur 1 1 2 1
if &x0pnt lt &first or &x0pnt gt &last scram
eva getpt (&midpt-&x0pnt)
csl &getpt
ift
cnv &wintyp &zaparg
ft
csr &getpt
dr
scram:
cur 0 1 1 1
end