#!/bin/tcsh # # tab3 [conc3_output [element [start_concentration]]] # # This C-Shell script processes output files from "conc3", # based on EQ3NR run series performed by the program suite # scan_ph, scan_eh, scan_conc, scan_log, scan_gas and scan_t or # based on MINTEQA2 runs processed with "minsweep". # # The final output generated by this script is a table with: # - the 1st column giving the X-Axis stepping variable (C, pH, or Eh), # - all following columns giving the element speciation (in %). # It is necessary to restrict the species to only those containing a # given (user-defined) element. The stoichiometric coefficents of this # element in each species are not automatically determined, # so the user has to provide them. # # The name of the output file is the same as its corresponding input file, # but instead of the extension ".[3M]c" it has ".[3M]d". # # The output can be post-processed to create graphs on the screen with # the program 'nplot' (default) or 'mplot'. # # Author: Dr.Vinzenz Brendler, Forschungszentrum Dresden-Rossendorf e.V. # Institute of Radiochemistry # # Version: 1.71 Date: 13-Jun-2006 onintr FINISH stty icanon if ($#argv < 1) then echo " " ls *.[3M]c >& /dev/null && ls *.[3M]c echo " " echo "Specify the name of the concentration file: " echo " " echo -n " < " set argv = (`gets`) endif if ($#argv > 3) then echo "Error: No more than three arguments are allowed: " echo " conc3_output [ element [ start_concentration ] ]" exit endif if (! -r $argv[1]) then echo "Error: Input file $argv[1] is not existent or not readable! " exit endif if (-z $argv[1]) then echo "Error: Input file $argv[1] is empty! " exit endif set CONC = $argv[1] # File with Concentration Table set TEMP = $CONC:r.$$ # Temporary Output File # Determine which speciation code was used # and if the output file is already existent set CODE = `sed -n '1s/^#\([36M]\).*/\1/p' $CONC` set DIST = $CONC:r.${CODE}d # Table of Species Distribution (Percentages) if (-e $DIST) then echo -n "Output file $DIST already exists, overwrite y/(n) ? " set rr = (`gets`) if ($rr != y && $rr != Y) exit endif # Specify the element for which the species concentration is looked for set SYMBOL = U # Uranium as Default Species Selected for Distribution if ($#argv > 1) then set ELEMENT = $argv[2] else echo " " echo -n "Element wanted for distribution ( = $SYMBOL ) : " set ELEMENT = (`gets`) if ( ! $#ELEMENT) set ELEMENT = $SYMBOL endif # Determine stepping mode for scanned variable (logarithmic or equally spaced) set SPC = `sed -n '1s/^#[3M]\([LE#]\).*/\1/p' $CONC` if ($SPC == "L") then set PLOT = "nlogplot" else set PLOT = "nplot" endif # Determine scanned variable and appropriate output format. # Check if the selected element is part of a concentration-scanned species. set SCAN = `sed -n '1s/#[3M][LE]*#\([^ ]*\).*/\1/p' $CONC` @ VARY = 0 @ TOTAL = 0 switch ($SCAN) case "T": set SCAN_FOUT = '%-6.1f' ; breaksw case "pH": set SCAN_FOUT = '%-6.2f' ; breaksw case "Eh": set SCAN_FOUT = '%-6.3f' ; breaksw default: set SCAN_FOUT = '%-8.3g' if ($SCAN =~ *$ELEMENT*) @ VARY = 1 breaksw endsw # Specify the total start analytical concentration of the above element # if it is not part of a concentration-scanned species. if ($VARY == 0) then if ($#argv > 2) then set TOTAL = $argv[3] else echo " " echo -n "Total analytical start concentration of $ELEMENT : " set TOTAL = (`gets`) if ( ! $#TOTAL) exit echo " " endif endif # Normalize to the total analytical concentration of the wanted element, # skip first four columns (scaned variable, pH, two ionic strengths) # and remove also all solids. awk 'BEGIN { total = '$TOTAL' ; vary = '$VARY' } \ NR == 1 { printf "%s ", $1 \ for (i = 5; i <= NF; i++) { \ solid[i] = index($i, "(s)") \ if (solid[i] == 0) printf "%s ", $i } \ printf "\n" ; next } \ { printf "'$SCAN_FOUT'" , $1 \ if (vary == 1) total = $1 \ for (i = 5; i <= NF; i++) \ if (solid[i] == 0) printf " %10.4f", (100 * $i / total) \ printf "\n" } \ ' $CONC > $TEMP # Dimension the vector of the stoichiometric coefficents and ask for them set COEFFS = `head -1 $TEMP` echo "Stoichiometric coeffcients of $ELEMENT ( = 1 ) in" @ COUNTER = 0 foreach entry ($COEFFS) @ COUNTER++ if ($COUNTER == 1) continue echo -n " $entry : " set rr = (`gets`) if ( ! $#rr) set rr = 1 if ($rr < 0) set rr = 0 set COEFFS[$COUNTER] = $rr end # Multiplication of concentrations with stoichiometric coefficents # Change all space sequences into tabs echo $COEFFS | cat - $TEMP | \ awk 'NR == 1 { for (i = 2; i <= NF; i++) coeff[i] = $i ; next } \ NR == 2 { print ; next } \ { printf "'$SCAN_FOUT'" , $1 \ for (i = 2; i <= NF; i++) printf " %8.2f", $i * coeff[i] \ printf "\n" } \ ' | sed 's/ */ /g' > $DIST && echo " Successfully created: $DIST" # Ask the user if further data treatment, namely graph preparation # (gnuplot & postscript) is wanted echo " " echo -n "Continue with the plot routine y/(n) ? " set rr = (`gets`) echo " " if ($rr == y || $rr == Y) $PLOT $DIST $ELEMENT # Delete all temporary files FINISH: /bin/rm -f $TEMP exit # Future enhancements: #