# Sample code to call the Head-Bang program from the command-line as a console application # Example 1: call Head-Bang directly without checking data: # ratesmooth<-dos(paste("c:\\progra~1\\headbang\\console\\headbang.exe","-n ", nn,"-t ",ntrip,"-i ", niter,"-a ",thetastar),rbind(lon,lat,rate,wgt)) # Example 2: use a function that verifies data before calling Head-Bang headbang <- "c:\\progra~1\\headbang\\console\\headbang.exe" #bang function definition # x=longitude, y=latitude, z=value to smooth, wgt=weight bang <- function(x,y,z,wgt,nn=10,ntrip=7,niter=10,thetastar=135) { n <- length(x) if (n != length(y) || n!= length(z) || n!= length(wgt)) stop("x,y,z,wgt must be of equal length") command <- paste(headbang,"-n ", nn,"-t ",ntrip,"-i ", niter,"-a ",thetastar) result <- dos(command,rbind(x,y,z,wgt)) if (!length(result)) stop("parameter problem") matrix(as.numeric(result)) } #sample function call: ratesmooth<-round(bang(lon,lat,rate,wgt),dig=3) # Please note that path names for the console application can not contain spaces. # This is a limitation of the DOS shell. # The default location for the HeadBang console version is # "C:\Program Files\Headbang\console". This path should be expressed with # its DOS short equivalent, "C:\Progra~1\Headbang\console". # Alternatively, the headbang console version can be installed to a directory # with no spaces in the path name. # For a listing of the options and arguments, headbang can simply # be called with one single parameter, -? # ResultNew<-dos(paste("c:\\progra~1\\headbang\\headbang.exe","-?")