################################################################################ ####### function to open an IMP file and put it in an array structure ########## ################################################################################ # store the array coordinate in a matrix read.IMP=function (file.name,open.file=T) { if (open.file==T) {IMP.file=read.table(file.name)} else {IMP.file=file.name} # numb of specimen n=length(IMP.file[,1]) # numb of dimension k=2 # numb of landmarks p=(length(IMP.file[1,])-1)/k # create an array coordinates<-array(NA, dim=c(p, k, n)) # calculate total number of coordinate coord=p*k even=vector(length=(coord/2)) odd=vector(length=(coord/2)) for (i in 1:(coord/2)) { odd[i]=i*2-1 even[i]=i*2 } # fill the array for (i in 1:n) { coordinates[,1,i]=as.numeric(IMP.file[i,odd]) coordinates[,2,i]=as.numeric(IMP.file[i,even]) } # save the centroid size in a vector called centroid centroid=IMP.file[,p*k+1] output=list(coordinates=coordinates,scales=centroid) output }