Clam is one my favorite piece of software. Designed by Maarten Blaauw, it allows to draw age-depth model of stratigraphic cores, using the software R. It uses a csv file containing your radiocarbon dates’ results, stored in a specific folder. To avoid mistake and save time, I wrote an AppleScript to use with Alfred (my favorite Mac app!).
In Alfred window, I type the command clam (or whatever you choose) followed by the name of the new core for which I want to draw age-depth model. Alfred passes the core name to my script, which then does several things:
It creates a folder named by the core name, in the folder …/clam/Cores (as clam requires); It creates a csv file ready to fill in with the 14C results; And it creates a R script including the commands necessary for a basic age-depth model. Here is the AppleScript:
-- Create folder
tell application "Finder"
set CoresPath to "Macintosh HD:Users:--your:path:here--:clam:Cores"
make new folder at CoresPath with properties {name:q}
end tell
-- Create .csv file
-- Credit goes to member regular6633 (http://macscripter.net/viewtopic.php?pid=143425#p143425)
set filePath to "Macintosh HD:Users:--your:path:here--:clam:Cores:" & q & ":" & q & ".csv"
set theString to "ID,C14_age,cal_BP,error,reservoir,depth
surface,,,1,,0"
set theResult to writeTo(filePath, theString, text, false)
if not theResult then display dialog "There was an error writing the data!"
on writeTo(targetFile, theData, dataType, apendData)
-- targetFile is the path to the file you want to write
-- theData is the data you want in the file.
-- dataType is the data type of theData and it can be text, list, record etc.
-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
try
set targetFile to targetFile as text
set openFile to open for access file targetFile with write permission
if apendData is false then set eof of openFile to 0
write theData to openFile starting at eof as dataType
close access openFile
return true
on error
try
close access file targetFile
end try
return false
end try
end writeTo
-- Create R script
set filePath to "Macintosh HD:Users:--your:path:here--:clam:Cores:" & q & ":" & q & ".R"
set theString to "# This script is designed to generate an age-depth model of the core " & q & " thanks to clam R software. For any help on clam, see documentation provided by author Maarten Blaauw, or original publication (Blaauw, M., 2010. Methods and code for \"classical\"age-modelling of radiocarbon sequences. Quaternary Geochronology, 5(5), pp.512–518.)
# Author: Benjamin Dietre, benjamin.dietre [at] uibk.ac.at
# Load workspace and source code
setwd(\"/Users/your/path/here/clam\") # On Macs
setwd(\"C:/your/path/her'/clam\") # On PCs
source(\"clam.R\")
# Age-depth models
clam(\"" & q & "\")
# You might like some more options, e.g., clam(\"" & q & "\", yrlab=\"Age (years cal. BP)\", hiatus=123, outlier=123, yrmin=0, yrmax=12000, dmin=0, dmax=200)"
set fRef to (open for access file filePath with write permission)
try
set eof of file filePath to 0
write theString to fRef
do shell script "afplay /System/Library/Sounds/Glass.aiff"
end try
close access fRef
You can download the Alfred workflow here. When you don’t want to use Alfred (although I definitely recommend), you can modify this script to use a prompt dialog, for instance.