schiff

Estimate the radiative properties of soft particless
git clone git://git.meso-star.com/schiff.git
Log | Files | Refs | README | LICENSE

test_schiff_sphere.sh (2802B)


      1 #!/bin/bash
      2 # Copyright (C) 2015-2016 CNRS
      3 #
      4 # This program is free software: you can redistribute it and/or modify
      5 # it under the terms of the GNU General Public License as published by
      6 # the Free Software Foundation, either version 3 of the License, or
      7 # (at your option) any later version.
      8 #
      9 # This program is distributed in the hope that it will be useful,
     10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12 # GNU General Public License for more details.
     13 #
     14 # You should have received a copy of the GNU General Public License
     15 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
     16 
     17 tmpfile=schiff_result
     18 tmppipe=schiff_pipe
     19 tmpprefix=xxschiff
     20 
     21 nrealisations=1000
     22 nangles=1000
     23 ninvcum=100
     24 ndirs=100
     25 wavelength=0.6 # in micron (in vacuum)
     26 N=1.4666666666666666666666666 # Real refractive index
     27 K=0.0053333333333333333333333 # Imaginary refractive index
     28 Ne=1.3333333333333333333333333 # Refractive index of the medium
     29 sigma=1.18
     30 mean_radius=(1.0 3.22 5.44 7.67 9.89 12.1 14.3 16.6 19.0 21.0)
     31 
     32 # Extinction Absorption Scattering
     33 references=(
     34   "8.39 0.484 7.90"
     35   "69.3 13.4 55.9"
     36   "197 54.6 143"
     37   "392 131 261"
     38   "651 243 408"
     39   "975 393 582"
     40   "1370 578 787"
     41   "1820 799 1020"
     42   "2390 1080 1310"
     43   "2930 1350 1580"
     44 )
     45 
     46 # print whether or not the $1 is equal to $2 +/- 4*$3
     47 eq_eps(){
     48   echo -e\
     49     "scale=20\n"\
     50     "dst = $1 - $2\n"\
     51     "if(dst <0) dst = -dst\n"\
     52     "dst < 4*$3\n" | bc -l
     53 }
     54 
     55 set -e
     56 cd `mktemp -d`
     57 pwd
     58 
     59 if [ ! -e $tmppipe ]; then mkfifo $tmppipe; fi
     60 
     61 if [ ! -f $tmpfile ]
     62 then
     63   for mu in ${mean_radius[*]}
     64   do
     65     # Generate the geometry distribution into the pipe
     66     echo -e \
     67       "sphere:\n" \
     68       "  radius: { lognormal: { mu: $mu, sigma: $sigma } }" \
     69       > $tmppipe &
     70 
     71     # invoke the schiff command
     72     echo $wavelength $N $K $Ne | \
     73     schiff -q \
     74       -a $nangles \
     75       -A $ninvcum \
     76       -l $mu \
     77       -i $tmppipe \
     78       -w $wavelength \
     79       -g $nrealisations \
     80       -d $ndirs >> $tmpfile \
     81       || true # inhibit the "set -e" comportment on failure
     82   done
     83 fi
     84 
     85 err=0 # error code
     86 
     87 # Check the estimated cross sections against the references
     88 for ((i=0; i < ${#mean_radius[@]}; ++i))
     89 do
     90   iline=$(($i*(2*$nangles+$ninvcum+7)+1))
     91   xsection=(`sed -n "$(($iline))p" $tmpfile | sed 's/^\S*\(.*\)$/\1/g'`)
     92   reference=(`echo ${references[$i]}`)
     93 
     94   extinction=$(eq_eps ${reference[0]} ${xsection[0]} ${xsection[1]})
     95   absorption=$(eq_eps ${reference[1]} ${xsection[2]} ${xsection[3]})
     96   scattering=$(eq_eps ${reference[2]} ${xsection[4]} ${xsection[5]})
     97 
     98   echo -n "${mean_radius[$i]} "
     99   if [ $extinction -eq 0 -o $absorption -eq 0 -o $scattering -eq 0 ]
    100   then
    101     echo FAILURE
    102     err=1 # notify the error
    103   else
    104     echo OK
    105   fi
    106 done
    107 
    108 rm $tmppipe
    109 
    110 exit $err