#Revise to get root
filroot<- "ProbeVectImg0286"
require(pixmap)
XXa<-attributes(read.pnm(paste(filroot,"a.pgm",sep='')))
XXb<-attributes(read.pnm(paste(filroot,"b.pgm",sep='')))
XXc<-attributes(read.pnm(paste(filroot,"c.pgm",sep='')))
XXd<-attributes(read.pnm(paste(filroot,"d.pgm",sep='')))
XXe<-attributes(read.pnm(paste(filroot,"e.pgm",sep='')))
XXf<-attributes(read.pnm(paste(filroot,"f.pgm",sep='')))

XXgry<- (XXa$grey+XXb$grey+XXc$grey+XXd$grey+XXe$grey+XXf$grey)/6
#XXred<- (XXa$red+XXb$red+XXc$red+XXd$red+XXe$red+XXf$red)/6
#XXblu<- (XXa$blue+XXb$blue+XXc$blue+XXd$blue+XXe$blue+XXf$blue)/6
#XXgre<- (XXa$green+XXb$green+XXc$green+XXd$green+XXe$green+XXf$green)/6
dat<- array(XXgry, c(attributes(XXgry)$dim,3))
XX<- pixmapGrey(dat)

write.pnm(XX, file=paste(filroot,"avg.pgm",sep=''))
cat("Done\n") 