| 1 | #!/bin/sh |
|---|
| 2 | # |
|---|
| 3 | # This file is part of the McStas neutron ray-trace simulation package |
|---|
| 4 | # Copyright (C) 1997-2004, All rights reserved |
|---|
| 5 | # Risoe National Laborartory, Roskilde, Denmark |
|---|
| 6 | # Institut Laue Langevin, Grenoble, France |
|---|
| 7 | # |
|---|
| 8 | # This program is free software; you can redistribute it and/or modify |
|---|
| 9 | # it under the terms of the GNU General Public License as published by |
|---|
| 10 | # the Free Software Foundation; version 2 of the License. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, |
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | # GNU General Public License for more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License |
|---|
| 18 | # along with this program; if not, write to the Free Software |
|---|
| 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | # |
|---|
| 21 | # compiletest.sh - Developer tool / simple shell script for compilation |
|---|
| 22 | # check of all example instruments. To be used/checked before release of |
|---|
| 23 | # new 'stable' releases of McStas |
|---|
| 24 | # |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | if [ $MCSTAS ] |
|---|
| 28 | then |
|---|
| 29 | echo "McStas environment var set" |
|---|
| 30 | else |
|---|
| 31 | MCSTAS="/usr/local/lib/mcstas" |
|---|
| 32 | fi |
|---|
| 33 | |
|---|
| 34 | EXAMPLES="$MCSTAS/examples" |
|---|
| 35 | export EXMPLES |
|---|
| 36 | EXECDIR=`mktemp -d -t McRun` |
|---|
| 37 | export EXECDIR |
|---|
| 38 | |
|---|
| 39 | echo "Example folder used is $EXAMPLES - compiling in $EXECDIR" |
|---|
| 40 | |
|---|
| 41 | for file in `find $MCSTAS -name \*.comp | grep -v obsolete | grep -v Adapt | grep -v Res_mon | grep -v PreMonitor_nD | grep -v Monitor_Optimizer | grep -v Pol `; |
|---|
| 42 | do |
|---|
| 43 | comp=`basename $file .comp` |
|---|
| 44 | instr=`echo $EXECDIR/cTest_$comp.instr` |
|---|
| 45 | export comp |
|---|
| 46 | export instr |
|---|
| 47 | echo Creating $instr |
|---|
| 48 | # Extract parameter names and set to 0... |
|---|
| 49 | # DEFINITION PARMS: |
|---|
| 50 | echo "DEFINE INSTRUMENT Test_$comp()" > $instr |
|---|
| 51 | echo "TRACE" >> $instr |
|---|
| 52 | echo "COMPONENT Test = $comp(" >> $instr |
|---|
| 53 | first=1 |
|---|
| 54 | export first |
|---|
| 55 | for parm in `grep SETTING -A 100 $file | grep -B 100 OUTPUT | sed -e 's/\"/\\\\"/g' | xargs echo | cut -f1 -d \) | cut -f2 -d \( | sed -e 's/int //g' | sed -e 's/double //g' | sed -e 's/string //g' | sed -e 's/char //g' | sed -e 's/\*//g' | sed -e 's/ =/=/g' | sed -e 's/= /=/g' | sed -e 's/ //g' | sed -e 's/,/ /g'`; |
|---|
| 56 | do |
|---|
| 57 | if [ "$first" != "1" ]; then |
|---|
| 58 | echo ", " >> $instr |
|---|
| 59 | else |
|---|
| 60 | first=0 |
|---|
| 61 | export first |
|---|
| 62 | fi |
|---|
| 63 | eq=`echo $parm | grep -c \=` |
|---|
| 64 | if [ "$eq" == "0" ]; then |
|---|
| 65 | echo `echo $parm` = 1 >> $instr |
|---|
| 66 | else |
|---|
| 67 | echo `echo $parm` >> $instr |
|---|
| 68 | fi |
|---|
| 69 | done |
|---|
| 70 | for parm in `grep DEFINITION -A 100 $file | grep -B 100 SETTING | sed -e 's/\"/\\\\"/g' | xargs echo | cut -f1 -d \) | cut -f2 -d \( | sed -e 's/int //g' | sed -e 's/double //g' | sed -e 's/string //g' | sed -e 's/char //g' | sed -e 's/\*//g' | sed -e 's/ =/=/g' | sed -e 's/= /=/g' | sed -e 's/ //g' | sed -e 's/,/ /g'`; |
|---|
| 71 | do |
|---|
| 72 | if [ "$first" != "1" ]; then |
|---|
| 73 | echo ", " >> $instr |
|---|
| 74 | else |
|---|
| 75 | first=0 |
|---|
| 76 | export first |
|---|
| 77 | fi |
|---|
| 78 | eq=`echo $parm | grep -c \=` |
|---|
| 79 | if [ "$eq" == "0" ]; then |
|---|
| 80 | echo `echo $parm ` = 1 >> $instr |
|---|
| 81 | else |
|---|
| 82 | echo `echo $parm` >> $instr |
|---|
| 83 | fi |
|---|
| 84 | done |
|---|
| 85 | echo ") AT (0,0,0) ABSOLUTE" >> $instr |
|---|
| 86 | echo END >> $instr |
|---|
| 87 | done |
|---|
| 88 | |
|---|
| 89 | if [ -e $EXAMPLES ] |
|---|
| 90 | then |
|---|
| 91 | echo "Copying example instruments to $EXECDIR" |
|---|
| 92 | cp $EXAMPLES/*.instr $EXECDIR |
|---|
| 93 | cd $EXECDIR |
|---|
| 94 | NUMINSTR=`ls *.instr | wc -l` |
|---|
| 95 | echo Test-compiling $NUMINSTR instrument files... |
|---|
| 96 | for instr in `ls *.instr` |
|---|
| 97 | do |
|---|
| 98 | mcrun -n0 $instr > /dev/null |
|---|
| 99 | echo $instr done |
|---|
| 100 | done |
|---|
| 101 | else |
|---|
| 102 | echo "Sorry, $EXAMPLES did not exist" |
|---|
| 103 | return 1 |
|---|
| 104 | fi |
|---|