meso-web

Sources of the |Méso|Star> website
git clone git://git.meso-star.fr/meso-web.git
Log | Files | Refs | README | LICENSE

schiff_pretty_results.sh (4132B)


      1 #!/bin/bash
      2 #
      3 # Copying and distribution of this file, with or without modification, are
      4 # permitted in any medium without royalty provided the copyright notice and
      5 # this notice are preserved. This file is offered as-is, without any warranty.
      6 
      7 set -e
      8 
      9 # Check command usage
     10 if [ -z $1 ] || [ $# -ge 2 ]
     11 then
     12   echo "Usage: $0 SCHIFF-OUTPUT"
     13   exit 1
     14 fi
     15 
     16 # Ensure that the submitted file exists
     17 schiff_output=$1
     18 if [ ! -f $schiff_output ]
     19 then
     20   echo "Can't find the \"$schiff_output\" file"
     21   exit 1
     22 fi
     23 
     24 # Create a temporary directory
     25 tmpdir=`mktemp -d`
     26 
     27 # Split the schiff-output at each empty line. Save the resulting "scratch"
     28 # files in the temporary directory.
     29 csplit $schiff_output -q -z /^$/ {*} -f $tmpdir/scratch -b %d
     30 
     31 nwlens=`cat $tmpdir/scratch0 | wc -l` # Number of wavelength
     32 wlens=() # List of wavelengths
     33 
     34 # Check that all scratch files exist
     35 for ((i=0; i < $(($nwlens*3 + 2)); ++i ))
     36 do
     37   if [ ! -f $tmpdir/scratch$i ]
     38   then
     39     echo "The file \"$schiff_output\" is not a valid schiff-output."
     40     exit 1
     41   fi
     42   sed -i '/^$/d' $tmpdir/scratch$i # Remove empty line
     43 done
     44 
     45 ################################################################################
     46 # Cross sections
     47 ################################################################################
     48 echo "Write xsections.txt"
     49 echo -e \
     50 "# Cross sections and average projected area.\n"\
     51 "# \n"\
     52 "# line format: \"W E e A a S s P p\"\n"\
     53 "# - \"W\" the wavelength in vacuum (expressed in micron);\n"\
     54 "# - \"E\", \"A\" and \"S\" the expected value of the extinction, absorption and\n"\
     55 "#   scattering cross sections, respectively, in square microns per particle;\n"\
     56 "# - \"P\" the estimated average projected area in square microns per particle;\n"\
     57 "# - \"e\", \"a\", \"s\" and \"p\" the standard error of the aforementioned\n"\
     58 "#   estimations." > xsections.txt
     59 cat $tmpdir/scratch0 >> xsections.txt
     60 
     61 ################################################################################
     62 # Phase function descriptors
     63 ################################################################################
     64 echo "Write descs.txt"
     65 for ((i=0; i < $nwlens; ++i))
     66 do
     67   desc=(`sed -n "$(($i+1))p" $tmpdir/scratch1`)
     68   str="wavelength = ${desc[0]} micron\n"\
     69 "theta-limit = ${desc[1]} radians\n"\
     70 "Ws(theta-limit) = ${desc[2]} +/- ${desc[3]}\n"\
     71 "Wc(theta-limit) = ${desc[4]} +/- ${desc[5]}\n"\
     72 "n = ${desc[6]}\n"\
     73 "scattering angles count = ${desc[7]}\n"\
     74 "invcum phase function entries = ${desc[8]}\n"\
     75 
     76   if [ $i -eq 0 ]
     77   then
     78     echo -e $str > descs.txt
     79   else
     80     echo -e $str >> descs.txt
     81   fi
     82 
     83   wlens+=(${desc[0]}) # Append the wavelength in the wlens array
     84 done
     85 
     86 ################################################################################
     87 # Phase functions
     88 ################################################################################
     89 for ((i=0; i < $nwlens; ++i))
     90 do
     91   filename=func_${wlens[$i]}.txt
     92   echo "Write $filename"
     93   echo -e \
     94 "# Phase functions for the wavelength ${wlens[$i]} microns\n"\
     95 "# line format: \"angle(radians) expected-value standard-error\"" > ${filename}
     96   cat $tmpdir/scratch$((2+$i)) >> ${filename}
     97 done
     98 
     99 ################################################################################
    100 # Cumulative phase functions
    101 ################################################################################
    102 for ((i=0; i < $nwlens; ++i))
    103 do
    104   filename=cumul_${wlens[$i]}.txt
    105   echo "Write $filename"
    106   echo -e \
    107 "# Cumulative phase functions for the wavelength ${wlens[$i]} microns\n"\
    108 "# line format: \"angle(radians) expected-value standard-error\"" > ${filename}
    109   cat $tmpdir/scratch$((2+$nwlens+$i)) >> ${filename}
    110 done
    111 
    112 ################################################################################
    113 # Inverse cumulative phase functions
    114 ################################################################################
    115 for ((i=0; i < $nwlens; ++i))
    116 do
    117   filename=invcumul_${wlens[$i]}.txt
    118   echo "Write $filename"
    119   echo -e \
    120 "# Inverse cumulative phase functions for the wavelength ${wlens[$i]} microns\n"\
    121 "# line format: \"probability angle(radians)\"" > ${filename}
    122   cat $tmpdir/scratch$((2+2*$nwlens+$i)) >> ${filename}
    123 done
    124 
    125 exit 0