################################################################################ ############# function to transform an array in a tps file ##################### ################################################################################ write.tps=function(array.file,name.file=NA,scale.val=F,picture=F,type.pic="TIF",images.lab=F,comment=F) { # calculate the numbers of landmarks p=length(array.file$coordinates[,1,1]) # find the number of specimen n=length(array.file$coordinates[1,1,]) ########### if (scale.val==F & picture==F & comment==F & images.lab==F) aux=2 if (scale.val==T | picture==T | comment==T | images.lab==T) aux=3 if (scale.val==T & picture==T | scale.val==T & images.lab==T | scale.val==T & comment==T | picture==T & comment==T | images.lab==T & comment==T) aux=4 if (scale.val==T & picture==T & comment==T | scale.val==T & images.lab==T & comment==T) aux=5 # create a vector with the names of the first line landmarks=vector(length=n) landmarks[]=paste(c("lm=",p),collapse="") # create a vecotor with the vector with the scale if (any(array.file$scales!=0)) { scales=vector(length=n) for (i in 1:n) {scales[i]=paste(c("scale=",array.file$scales[i]),collapse="")} } # create a vecotor with the vector with the picture if (any(array.file$pictures!=0)) { pictures=vector(length=n) for (i in 1:n) {pictures[i]=paste(c("image=",array.file$pictures[i],".",type.pic),collapse="")} } # create a vector with the vector images if (any(array.file$images!=0)) { images=vector(length=n) for (i in 1:n) {images[i]=paste(c("image=",array.file$images[i]),collapse="")} } # create a vecotor with the vector with the scale if (any(array.file$comments!=0)) { comments=vector(length=n) for (i in 1:n) {comments[i]=paste(c("comment=",array.file$comments[i]),collapse="")} } # create a vector with the ID ID=vector(length=n) for (i in 1:n) {ID[i]=paste(c("id=",c(0:(n-1))[i]),collapse="")} # create a matrix with the paired coordinate of every landmarks coordinates=matrix(NA,n,p) # fill this matrix for (i in 1:n) { for (j in 1:p) { coordinates[i,j]=paste(array.file$coordinates[j,,i],collapse=" ") } } # create a matrix with all the info that will go in the tps depending on what is available if (picture==F & scale.val==F & comment==F & images.lab==F) { tpsmtr=matrix(NA,n,(p+aux)) for (i in 1:n) { tpsmtr[i,]=c(landmarks[i],coordinates[i,],ID[i]) } } if (picture==T & scale.val==F & comment==F & images.lab==F) { tpsmtr=matrix(NA,n,(p+aux)) for (i in 1:n) { tpsmtr[i,]=c(landmarks[i],coordinates[i,],pictures[i],ID[i]) } } if (images.lab==T & scale.val==F & comment==F & picture==F) { tpsmtr=matrix(NA,n,(p+aux)) for (i in 1:n) { tpsmtr[i,]=c(landmarks[i],coordinates[i,],images[i],ID[i]) } } if (picture==F & scale.val==T & comment==F & images.lab==F) { tpsmtr=matrix(NA,n,(p+aux)) for (i in 1:n) { tpsmtr[i,]=c(landmarks[i],coordinates[i,],ID[i],scales[i]) } } if (picture==F & scale.val==F & comment==T & images.lab==F) { tpsmtr=matrix(NA,n,(p+aux)) for (i in 1:n) { tpsmtr[i,]=c(landmarks[i],coordinates[i,],ID[i],comments[i]) } } if (picture==T & scale.val==T & comment==F & images.lab==F) { tpsmtr=matrix(NA,n,(p+aux)) for (i in 1:n) { tpsmtr[i,]=c(landmarks[i],coordinates[i,],pictures[i],ID[i],scales[i]) } } if (images.lab==T & scale.val==T & comment==F & picture==F) { tpsmtr=matrix(NA,n,(p+aux)) for (i in 1:n) { tpsmtr[i,]=c(landmarks[i],coordinates[i,],images[i],ID[i],scales[i]) } } if (picture==F & scale.val==T & comment==T & images.lab==F) { tpsmtr=matrix(NA,n,(p+aux)) for (i in 1:n) { tpsmtr[i,]=c(landmarks[i],coordinates[i,],ID[i],scales[i],comments[i]) } } if (picture==T & scale.val==F & comment==T & images.lab==F) { tpsmtr=matrix(NA,n,(p+aux)) for (i in 1:n) { tpsmtr[i,]=c(landmarks[i],coordinates[i,],pictures[i],ID[i],comments[i]) } } if (scale.val==T & picture==T & comment==T & images.lab==F) { tpsmtr=matrix(NA,n,(p+aux)) for (i in 1:n) { tpsmtr[i,]=c(landmarks[i],coordinates[i,],pictures[i],ID[i],scales[i],comments[i]) } } if (scale.val==T & images.lab==T & comment==T & picture==F) { tpsmtr=matrix(NA,n,(p+aux)) for (i in 1:n) { tpsmtr[i,]=c(landmarks[i],coordinates[i,],images[i],ID[i],scales[i],comments[i]) } } # save this matrix in a file cat(paste(t(tpsmtr)),sep="\n",file=name.file) }