FIX: C code (double, float, ...) + wrapper (read/write data, get medoids)
[epclust.git] / code / stage1 / wrapper.R
index 524fc90..0a957d8 100644 (file)
@@ -1,4 +1,5 @@
-ppam_exe = function(path=".", np=parallel::detectCores(), data=NULL, args="DontLetMeEmpty")
+ppam_exe = function(path=".", np=parallel::detectCores(), data=NULL,
+       args="DontLetMeEmptyPlease!")
 {
        command_line = paste("mpirun -np ",np," ",path,"/ppam.exe cluster",sep="")
 
@@ -7,8 +8,9 @@ ppam_exe = function(path=".", np=parallel::detectCores(), data=NULL, args="DontL
        {
                if (!is.character(data))
                {
-                       #assuming matrix or data.frame, WITH row names (identifiers; could be line number...)
-                       write.csv(data, "/tmp/data_csv", row.names=TRUE, col.names=FALSE)
+                       #assuming matrix or data.frame, WITH row names
+                       #( identifiers; could be line number... e.g. data <- cbind(1:nrow(data),data) )
+                       write.table(data, "/tmp/data_csv", sep=",", row.names=FALSE, col.names=FALSE)
                        system(paste(path,"/ppam.exe serialize /tmp/data_csv /tmp/data_bin 0 0",sep=""))
                } else
                {
@@ -20,3 +22,14 @@ ppam_exe = function(path=".", np=parallel::detectCores(), data=NULL, args="DontL
        command_line = paste(command_line," ",args,sep="")
        system(command_line)
 }
+
+#NOTE: identifiers in first column
+getMedoids = function(path=".", xmlResult = "ppamResult.xml",
+       finalSeries = "ppamFinalSeries.bin")
+{
+       system(paste(path,"/ppam.exe deserialize ",finalSeries," ppamFinalSeries.csv -1",sep=""))
+       curves = read.table("ppamFinalSeries.csv", sep=",")
+       library(XML)
+       ranks = as.integer( xmlToList( xmlParse(xmlResult) )$ranks )
+       return ( curves[ranks,] ) # == medoids
+}