#Written by Vera Lindsay, Feb.2005 #BEGINNING OF SCRIPT: qc.stn<- function(Station,FILE,type=1){ print(type) if(type == 1){ dat<-read.table(file=FILE,header=F, na.strings="-999", col.names=c("stn","year","mo","day","hr","tmp","rh","wspd","wdir","ppt")) }else if (type == 2){ dat<-read.table(file=FILE,header=F, na.strings="-999", col.names=c("year","mo","day","hr","wspd","wdir")) }else if (type == 3){ dat<-read.table(file=FILE,header=F, na.strings="-999", col.names=c("year","mo","day","hr","tmp","wdir","wspd")) }else{ stop("Unknowen station type, please specify 1 for mof,2 for ec or 3 for mwlep.") } #Correct wind speed and direction so that: #If wind speed is 0 the direction is also 0 i<-1 for(i in 1:length(dat$wdir)){ if (!is.na(dat$wspd[i]) & dat$wspd[i]==0){ dat$wdir[i]<-0 } } #If wind speed is not 0 and wind direction is 0 the wind direction is changed to 360 i<-1 for(i in 1:length(dat$wdir)) if (!is.na(dat$wspd[i]) & !is.na(dat$wdir[i])&(dat$wspd[i]!=0) &&(dat$wdir[i]==0)){ dat$wdir[i]<-360 } #If wind direction is 0 then wind speed is also 0 - this change must be made after the above. i<-1 for(i in 1:length(dat$wdir)) if (!is.na(dat$wdir[i]) & dat$wdir[i]==0) { dat$wspd[i]<-0 } #View plot to ensure quality controll was achived: plot(dat$wdir,dat$wspd) #split data into 3 days: i<-1 a<-1 b<-length(dat$wdir) c<-((b/24/3)-1) for (i in 1:c){ for (a in a:(a+24)) dat$day[a]<-1 for (a in a:(a+24)) dat$day[a]<-2 for (a in a:(a+24)) dat$day[a]<-3 #print(a) a<-(72*i+1) } #Write the corected data to a file: NAME<-paste(FILE,".qc",sep="") if(type == 1){ write.table(dat,file=NAME,col.names=F, append=F,row.names=F) }else if (type == 2){ write.table(dat,file=NAME,col.names=F, row.names=F, append=F) }else if(type == 3){ write.table(dat,file=NAME,col.names=F, row.names=F,append=F) } } #END OF SCRIPT