######TWEAKING FOR WINDOWS: WAHL-AMMAN BASE CASE ONLY #SM: this is original WA script with annotations marked #SM: downloaded original script 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: script modified to collect results in an R-list instead of writing them out to Fortran-style log files remove(list=ls()) #clean up this case before starting #SM: Function to Create a directory and subdirectories if they do not exist. 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<-"d:/climate/data/wahl/benchmark" #SM added createsubdirs(master.directory) #SM added param.directory="http://www.climateaudit.org/data/wahl" #SM added param.file<-file.path(param.directory,"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 temp.directory<-file.path(master.directory,"case") #SM: this is where I located the case files. This can be user-determined case.directory<-file.path(master.directory,"base") #SM: this is where I located the scripts and masters createsubdirs(temp.directory) #SM: make the subdirectory createsubdirs(case.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 source("http://www.climateaudit.org/scripts/wahl/mann_Rfunctions_tweaked.txt") #SM: tweaked a little from WA to collect objects 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 below createsubdirs(param.input$caselabel) #SM: this implements 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 ###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) SM commented out #loop over reconstruction networks: wahlfit=list() #this is inserted by me to collect results of individual steps for(i in 1:param.input$proxy.periods){ #print(i) #write(paste("*******************************************************"),file=logfile,append=TRUE)#SM- commented out #write(paste("Proxy period number",i),file=logfile,append=TRUE) #SM commented out #write(paste("----------------------",""),file=logfile,append=TRUE) #SM commented out 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) #SM commented out #instead the results themselves are collected and saved step=list(data.objects,svdproduct,proxyfit) #insert SM wahlfit[[i]]=step #insert SM: this is key strategy in avoiding log files } names(wahlfit)=sapply(param.input[seq(17,67,5)],min) #1400 ....1820 #SM code #save(wahlfit,file=file.path(master.directory,"wahlfit.tab")) #I saved object into http://www.climateaudit.org/data/wahl/wahlfit.tab length(wahlfit) #11 length(wahlfit[[1]]) #3 #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