Skip to content

Instantly share code, notes, and snippets.

@davidchall
Last active May 22, 2016 15:11
Show Gist options
  • Save davidchall/40c2514658243f043bb17c0d79a1be2e to your computer and use it in GitHub Desktop.
Save davidchall/40c2514658243f043bb17c0d79a1be2e to your computer and use it in GitHub Desktop.
Script to (partially) convert TOPAS parameter files from v2.0 to v3.0
#!/bin/sh
# This script will (partially) convert TOPAS parameter files from v2.0 to v3.0.
# A backup of the original file is created with a .bak extension.
# WARNING: using this script twice on the same file will delete the backup file.
if [ "$#" -eq 0 ]; then
echo "Usage: $0 filename"
fi
for file in "$@"; do
sed -i.bak \
-e 's,"G4Box","TsBox",g' \
-e 's,"G4Tubs","TsCylinder",g' \
-e 's,"G4Sphere","TsSphere",g' \
-e 's,"Water","G4_WATER",g' \
-e 's,"Flourine","Fluorine",g' \
-e 's,"Dipole","DipoleMagnet",g' \
-e 's,"Quadrupole","QuadrupoleMagnet",g' \
-e 's,"\([A-Za-z0-9/][A-Za-z0-9/]*\)/PlusPhiSurface","\1/PhiPlusSurface",g' \
-e 's,"\([A-Za-z0-9/][A-Za-z0-9/]*\)/MinusPhiSurface","\1/PhiMinusSurface",g' \
-e 's,"\([A-Za-z0-9/][A-Za-z0-9/]*\)/PlusThetaSurface","\1/ThetaPlusSurface",g' \
-e 's,"\([A-Za-z0-9/][A-Za-z0-9/]*\)/MinusThetaSurface","\1/ThetaMinusSurface",g' \
-e 's,Ph/\([A-Za-z0-9/][A-Za-z0-9/]*\)/LamdaBins,Ph/\1/LambdaBins,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/HUtoMaterialConversionMethod,Ge/\1/ImagingToMaterialConverter,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/MagneticField,Ge/\1/Field,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/Strength,Ge/\1/MagneticFieldStrength,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/DirectionX,Ge/\1/MagneticFieldDirectionX,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/DirectionY,Ge/\1/MagneticFieldDirectionY,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/DirectionZ,Ge/\1/MagneticFieldDirectionZ,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/GradientX,Ge/\1/MagneticFieldGradientX,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/GradientY,Ge/\1/MagneticFieldGradientY,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/3DTable,Ge/\1/MagneticField3DTable,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/Stepper,Ge/\1/FieldStepper,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/StepMinimum,Ge/\1/FieldStepMinimum,g' \
-e 's,Ge/\([A-Za-z0-9/][A-Za-z0-9/]*\)/DeltaChord,Ge/\1/FieldDeltaChord,g' \
-e 's,Sc/\([A-Za-z0-9/][A-Za-z0-9/]*\)/PhaseSpaceBufferSize,Sc/\1/OutputBufferSize,g' \
-e 's,So/\([A-Za-z0-9/][A-Za-z0-9/]*\)/BeamXYDistribution,So/\1/BeamPositionDistribution,g' \
-e 's,So/\([A-Za-z0-9/][A-Za-z0-9/]*\)/BeamShape,So/\1/BeamPositionCutoffShape,g' \
-e 's,So/\([A-Za-z0-9/][A-Za-z0-9/]*\)/BeamHWX,So/\1/BeamPositionCutoffX,g' \
-e 's,So/\([A-Za-z0-9/][A-Za-z0-9/]*\)/BeamHWY,So/\1/BeamPositionCutoffY,g' \
-e 's,So/\([A-Za-z0-9/][A-Za-z0-9/]*\)/BeamStandardDeviationX,So/\1/BeamPositionSpreadX,g' \
-e 's,So/\([A-Za-z0-9/][A-Za-z0-9/]*\)/BeamStandardDeviationY,So/\1/BeamPositionSpreadY,g' \
"$file"
# remove backup if no modifications
diff -q "$file" "${file}.bak" > /dev/null 2>&1
if [ $? -eq 0 ]; then
rm "${file}.bak"
fi
done
@jiperl
Copy link

jiperl commented May 16, 2016

Looks like this is missing
MinusPhiSurface
MinusThetaSurface

@jiperl
Copy link

jiperl commented May 16, 2016

Also need
Stepper->MagneticFieldStepper
StepMinimum->MagneticFieldStepMinimum
DeltaChord->MagneticFieldDeltaChord

Attaching new version to the git issue

@davidchall
Copy link
Author

You should be able to directly edit this gist document. Better to keep everything in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment