######TWEAKING FOR WINDOWS ##SM: THIS IS WAHL-AMMNA BASE CASE ONLY #SM: downloaded from http://www.cgd.ucar.edu/ccr/ammann/millennium/codes/mann_masterfile.r #SM: There are undoubtedly other ways of tweaking for Windows, but these worked for me #SM: create a directory to host results #SM: Function to Create a directory and subdirectories if they do not exist. remove(list=ls()) #clean up this case before starting createsubdirs<-function(dirpath1) { if( ! file.exists(dirpath1) ) { if( ! file.exists(dirname(dirpath1)) ) { # If parent directory is missing, request its creation. createsubdirs( dirname(dirpath1) ) } # the parent directory exists but not this dir dir.create( dirpath1 ) } } master.directory<-"c:/climate/data/wahl" #SM added param.file<-"http://www.climateaudit.org/data/wa.2005/control_WA_original.tweaked.txt" #SM: tweaks are to directories to make Windows compatible #there may be a simpler way to do this other than just changing directory names but this worked and there were only a few to do createsubdirs(master.directory) #SM: make the subdirectory #temp.directory<-"c:/climate/data/wahl/case" #SM: this is where I located the case files. This can be user-determined #case.directory<-"c:/climate/data/wahl/base" #SM: this is where I located the scripts and masters #createsubdirs(temp.directory) #SM: make the subdirectory source(file.path("http://www.cgd.ucar.edu/ccr/ammann/millennium/codes","mann_Rfunctions.r")) #SM: tweaked a little from WA param.input<-read.control(param.file) #SM:file.path added in param.input$caselabel<-file.path(master.directory,"WA.basecase") #SM: this implements the WA comment #the following two commands will work under unix only; if under windows, #make a folder called as the caselabel and skip them ###system(paste("rm -r",param.input$caselabel)) #delete any directory that happens to be there called as the caselabel ####system(paste("mkdir",param.input$caselabel)) #make a new directory called as the caselabel createsubdirs(param.input$caselabel) #SM: this implements WA comment ###logfile<-paste(param.input$caselabel,"/logfile.",param.input$caselabel,sep="") #SM: commented out. This creates weird directory when I tried it logfile<-file.path(param.input$caselabel,"logfile.txt") #SM: this works much better write("log:",file=logfile) #loop over reconstruction networks: for(i in 1:param.input$proxy.periods){ print(i) write(paste("*******************************************************"),file=logfile,append=TRUE) write(paste("Proxy period number",i),file=logfile,append=TRUE) write(paste("----------------------",""),file=logfile,append=TRUE) data.objects<-format.datamatrices(param.input,i) #controldata<-param.input svdproduct<-get.svd(param.input,i,data.objects,logfile) proxyfit<-mann.fit(param.input,data.objects,svdproduct,logfile) writeout.res(param.input,data.objects,svdproduct,proxyfit,logfile) } #the following command will work under unix only, skip it if under windows... #then zip everything in the folder called as the caselabel up if you like ##system(paste("tar cvf ",param.input$caselabel,".tar ","mann* ",param.input$caselabel,"/",sep="")) #tar up everyting