[chronojump] RDotNet seem to work on MacOSX



commit 86780effd9d10b57566bdb74645147aaa723716c
Author: Xavier de Blas <chronojump Mac-Pro-de-chronojump local>
Date:   Mon Apr 7 18:03:21 2014 +0200

    RDotNet seem to work on MacOSX

 rdotnet/R.NET/Devices/CharacterDeviceAdapter.cs |    2 +-
 rdotnet/R.NET/REngine.cs                        |   10 +++++++-
 rdotnet/RDotNet.NativeLibrary/UnmanagedDll.cs   |   11 +++++++-
 src/chronojump.cs                               |   30 +++++++++++++++++++---
 4 files changed, 45 insertions(+), 8 deletions(-)
---
diff --git a/rdotnet/R.NET/Devices/CharacterDeviceAdapter.cs b/rdotnet/R.NET/Devices/CharacterDeviceAdapter.cs
index 8615320..15bffa1 100644
--- a/rdotnet/R.NET/Devices/CharacterDeviceAdapter.cs
+++ b/rdotnet/R.NET/Devices/CharacterDeviceAdapter.cs
@@ -258,4 +258,4 @@ namespace RDotNet.Devices
 
       #endregion Nested type: getValue
    }
-}
\ No newline at end of file
+}
diff --git a/rdotnet/R.NET/REngine.cs b/rdotnet/R.NET/REngine.cs
index 8d7ba76..eb51b8c 100644
--- a/rdotnet/R.NET/REngine.cs
+++ b/rdotnet/R.NET/REngine.cs
@@ -42,8 +42,10 @@ namespace RDotNet
       private REngine(string id, string dll)
          : base(dll)
       {
+Console.WriteLine("REngine 1");
          this.id = id;
          this.isRunning = false;
+Console.WriteLine("REngine 2");
       }
 
       /// <summary>
@@ -164,6 +166,7 @@ namespace RDotNet
       /// <returns>The engine.</returns>
       public static REngine CreateInstance(string id, string dll = null)
       {
+Console.WriteLine("Creating instance");
          if (id == null)
          {
             throw new ArgumentNullException("id", "Empty ID is not allowed.");
@@ -190,14 +193,17 @@ namespace RDotNet
 
                case PlatformID.Unix:
                   dll = "libR.so";
+                  //dll = "libR.dylib";
                   break;
 
                default:
                   throw new NotSupportedException();
             }
          }
+Console.WriteLine("Creating var engine");
          var engine = new REngine(id, dll);
          instances.Add(id, engine);
+Console.WriteLine("Created var engine");
          return engine;
       }
 
@@ -220,6 +226,7 @@ namespace RDotNet
       /// <param name="device">The IO device.</param>
       public void Initialize(StartupParameter parameter = null, ICharacterDevice device = null)
       {
+Console.WriteLine("at initialize");
          this.parameter = parameter ?? new StartupParameter();
          this.adapter = new CharacterDeviceAdapter(device ?? DefaultDevice);
          GetFunction<R_setStartTime>()();
@@ -238,6 +245,7 @@ namespace RDotNet
          }
          GetFunction<setup_Rmainloop>()();
          this.isRunning = true;
+Console.WriteLine("ended initialize");
       }
 
       /// <summary>
@@ -551,4 +559,4 @@ namespace RDotNet
 
       #endregion Nested type: _getDLLVersion
    }
-}
\ No newline at end of file
+}
diff --git a/rdotnet/RDotNet.NativeLibrary/UnmanagedDll.cs b/rdotnet/RDotNet.NativeLibrary/UnmanagedDll.cs
index 2fd769a..4c13001 100644
--- a/rdotnet/RDotNet.NativeLibrary/UnmanagedDll.cs
+++ b/rdotnet/RDotNet.NativeLibrary/UnmanagedDll.cs
@@ -37,9 +37,12 @@ namespace RDotNet.NativeLibrary
             throw new ArgumentException("dllName");
          }
 
+Console.Write("going to load"); 
          IntPtr handle = LoadLibrary(dllName);
+Console.Write("return from load"); 
          if (handle == IntPtr.Zero)
          {
+Console.Write("handle pointer is zero"); 
             throw new DllNotFoundException();
          }
          SetHandle(handle);
@@ -175,14 +178,18 @@ namespace RDotNet.NativeLibrary
 #if UNIX
       private static IntPtr LoadLibrary(string filename)
       {
+        //filename = "/Library/Frameworks/R.Framework/Libraries/libR.dylib";
          const int RTLD_LAZY = 0x1;
          if (filename.StartsWith("/"))
          {
+Console.Write("AT LoadLibrary preee"); 
             return dlopen(filename, RTLD_LAZY);
          }
          var searchPaths = (Environment.GetEnvironmentVariable("PATH") ?? "").Split(Path.PathSeparator);
          var dll = searchPaths.Select(directory => Path.Combine(directory, 
filename)).FirstOrDefault(File.Exists);
-         return dll == null ? IntPtr.Zero : dlopen(dll, RTLD_LAZY);
+        //var dll = "/Library/Frameworks/R.Framework/Libraries/libR.dylib";
+Console.Write("AT LoadLibrary, dll= " + dll); 
+       return dll == null ? IntPtr.Zero : dlopen(dll, RTLD_LAZY);
       }
 
       [DllImport("libdl")]
@@ -212,4 +219,4 @@ namespace RDotNet.NativeLibrary
 #endif
       private static extern IntPtr GetFunctionAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] 
string lpProcName);
    }
-}
\ No newline at end of file
+}
diff --git a/src/chronojump.cs b/src/chronojump.cs
index 0cb87fe..474aeba 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -29,6 +29,9 @@ using System.Reflection; // Read Version
 using System.Diagnostics; //Process
 
 using System.Collections; //ArrayList
+using System.Linq;
+using RDotNet;
+using RDotNet.NativeLibrary;
 
 
 public class ChronoJump 
@@ -101,11 +104,30 @@ public class ChronoJump
                        Environment.SetEnvironmentVariable ("R_HOME", baseDirectory);
                        Log.WriteLine("R_HOME:" + baseDirectory);
                } else {
-                       rBinPath = @"/usr/lib/R/lib";
-                       Environment.SetEnvironmentVariable ("R_HOME", @"/usr/lib/R");
-                       Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + rBinPath);
-               }
+                       switch (NativeUtility.GetPlatform()) {
+                               case PlatformID.MacOSX:
+                                       Log.WriteLine(Environment.GetEnvironmentVariable("R_HOME"));
+                                       rBinPath = "/Library/Frameworks/R.Framework/Libraries";
+                                               Environment.SetEnvironmentVariable ("R_HOME", 
"/Library/Frameworks/R.Framework/Resources");
+                                               Environment.SetEnvironmentVariable("PATH", rBinPath + 
Path.PathSeparator + envPath);
+                                       Log.WriteLine("environments");
+                                       Log.WriteLine(Environment.GetEnvironmentVariable("R_HOME"));
+                                       Log.WriteLine(Environment.GetEnvironmentVariable("PATH"));
+                                       break;
+                               case PlatformID.Unix:
+                                       rBinPath = @"/usr/lib/R/lib";
+                                       Environment.SetEnvironmentVariable ("R_HOME", @"/usr/lib/R");
+                                       Environment.SetEnvironmentVariable("PATH", envPath + 
Path.PathSeparator + rBinPath);
+                                       break;
+                       }
+               }
                
+               Log.WriteLine("Platform:" + Environment.OSVersion.Platform);
+               Log.WriteLine("Platform Mac:" + PlatformID.MacOSX);
+               Log.WriteLine("initializing rdotnet");
+               //REngine rengineProva = REngine.CreateInstance("RDotNet");
+
+               //Environment.Exit(1);
                
                Log.WriteLine("baseDir0:" + System.AppDomain.CurrentDomain.BaseDirectory);
                Log.WriteLine("baseDir1:" + baseDirectory);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]