*********************************************************************************** * This is the "vec.kumac" macro for the KUIP interpreter of PAW * (Physics Analysis Workstation). Version 1.0. * It allows to manage arrays of global variables * Copyright (C) 2004 Pietro Cortese (Pietro Cortese at cern ch) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA macro vec * Configuration option quiet=1 | Almost no message when set to 1 themacro=[0] if [#] .lt. 1 then message * macro vec [ OPTION ] [ NAME ] [ CONTENTS ] message message Create a new array with: message exec vec NAME [ CONTENTS ] message message Create a new array or append to an existing array message exec vec + NAME [ CONTENTS ] message message Delete an existing array message exec vec - NAME1 [ NAME2 NAME3 ...] message exitm endif ***************************************************************** if [1] .eq. '+' then * Appending contents to an existing array if [#] .le. 1 then message exec vec + NAME [ CONTENTS ] exitm endif vecname=[2] * test if the array is defined macro/global/import [vecname]{0} a = "$defined([vecname]{0})" b = "''" if [a] .ne. [b] then * append data to the existing array do i=1,[#]-2 j=$sigma([[vecname]{0}]+[i]) macro/global/create [vecname]{[j]} [$sigma([i]+2)] enddo macro/global/create [vecname]{0} $sigma([[vecname]{0}]+[#]-2) if [quiet].eq.0 then message appended $sigma([#]-2) components to vector [vecname]{} Tot: [[vecname]{0}] endif else * create a new array do i=1,[#]-2 macro/global/create [vecname]{[i]} [$sigma([i]+2)] enddo macro/global/create [vecname]{0} $sigma([#]-2) if [quiet].eq.0 then message created [vecname]{[[vecname]{0}]} endif endif ***************************************************************** elseif [1] .eq. '-' then * Deleting array (if it exists) if [#] .le. 1 then message exec vec - NAME1 [ NAME2 NAME3 ...] exitm endif do j=2,[#] vecname = [[j]] * test if the array is defined macro/global/import [vecname]{0} a = "$defined([vecname]{0})" b = "''" if [a] .ne. [b] then * delete the array nend=[[vecname]{0}] do i=0,[nend] macro/global/delete [vecname]{[i]} enddo if [quiet].eq.0 then message deleted: [vecname]{} with $sigma([nend]) entries endif else message [0]: array [vecname]{} does not exists endif enddo ***************************************************************** else * Create a new array * if an array with the same name already exists it is overwritten * First test two common errors in vector name vecname=[1] if $substring([vecname],1,1).eq.'+' then message [0]: array name can not contain: ''+'' exitm endif if $substring([vecname],1,1).eq.'-' then message [0]: array name can not contain: ''-'' exitm endif * test if the array is defined macro/global/import [vecname]{0} a = "$defined([vecname]{0})" b = "''" if [a] .ne. [b] then * delete the old array do i=0,[[vecname]{0}] macro/global/delete [vecname]{[i]} enddo endif * create a new one if $sigma([#]).gt.1 then do i=1,[#]-1 macro/global/create [vecname]{[i]} [$sigma([i]+1)] enddo endif macro/global/create [vecname]{0} $sigma([#]-1) if [quiet].eq.0 then message created [vecname]{} with [[vecname]{0}] entries endif endif return