ikarosilva / wfdb-app-toolbox

The WFDB Toolbox for MATLAB/Octave is a collection of functions for reading, writing, and processing physiologic signals in the formats used by PhysioNet (see README for details).
http://physionet.org/physiotools/matlab/wfdb-app-matlab/
GNU General Public License v3.0
93 stars 46 forks source link

Mac only: Matlab cannot find Rdsamp java class #106

Open dwuab opened 9 years ago

dwuab commented 9 years ago

Mac OS X 10.10.3, wfdb-toolbox version: 0-9-10 and onward, MATLAB 2015a. This will not happen on Linux. here is an output from wfdbdemo:

>> wfdbdemo
Reading samples ECG signal from MIT-BIH Arrhythmia Database
Warning: Downloaded WFDB cache file:
/Users/wudegang/wfdb-app-toolbox/database/mitdb/100.dat 
> In wfdbdownload (line 93)
  In rdsamp (line 111)
  In wfdbdemo (line 12) 
Warning: Downloaded WFDB cache file:
/Users/wudegang/wfdb-app-toolbox/database/mitdb/100.atr 
> In wfdbdownload (line 93)
  In rdsamp (line 111)
  In wfdbdemo (line 12) 
Warning: Downloaded WFDB cache file:
/Users/wudegang/wfdb-app-toolbox/database/mitdb/100.hea 
> In wfdbdownload (line 93)
  In rdsamp (line 111)
  In wfdbdemo (line 12) 
Error using javaObject
No class org.physionet.wfdb.jni.Rdsamp can be located on the Java class
path

Error in rdsamp (line 114)
    javaWfdbRdsamp=javaObject('org.physionet.wfdb.jni.Rdsamp');

Error in wfdbdemo (line 12)
[ecg,Fs,tm]=rdsamp('mitdb/100',1,N);
ikarosilva commented 9 years ago

I think this is related to the RDSAMP JNI version only (which was optimized for speed). As a temporary solution, try not using the JNI RDSAMP by running instead:

[ecg,Fs,tm]=rdsamp('mitdb/100',1,N,x);

Where x can be any value besides the default ==0.

dwuab commented 9 years ago

@ikarosilva using

x=1;
[ecg,Fs,tm]=rdsamp('mitdb/100',1,N,x);

still gives the same error message:

Error using javaObject
No class org.physionet.wfdb.jni.Rdsamp can be located on the Java class path

Error in rdsamp (line 114)
    javaWfdbRdsamp=javaObject('org.physionet.wfdb.jni.Rdsamp');

Error in wfdbdemo (line 14)
[ecg,Fs,tm]=rdsamp('mitdb/100',1,N,x);
ghost commented 9 years ago

Got the same error!

wfdbdemo Reading samples ECG signal from MIT-BIH Arrhythmia Database Error using javaObject No class org.physionet.wfdb.jni.Rdsamp can be located on the Java class path

Error in rdsamp (line 114) javaWfdbRdsamp=javaObject('org.physionet.wfdb.jni.Rdsamp');

Error in wfdbdemo (line 12) [ecg,Fs,tm]=rdsamp('mitdb/100',1,N);

sami10007 commented 8 years ago

How to do you set up your environment?

I can reproduce your problem if I initiate wrongly the environment. I do not know how you can restart your system without reinstallation.

My output is the same error messages as you have. My system OS X 10.11.4 and wfdb 0-9-10. This fact proposes me that if you have any mistakes in the initiation of the system such an output will result. I opened a new ticket #121 where I try to restore the system such that I can run more tests to reproduce your case.

dwuab commented 8 years ago

@sami10007 Now I'm using OS X 10.11.4 as well. What I did and what I do is changing the current directory to~/Documents/MATLAB/wfdb-app-toolbox-0-9-10/mcode and running wfdbdemo.

sami10007 commented 8 years ago

I deleted path/mcode directory and initiated the system again, but still, I get the error. I run wfdbdemo and get

Reading samples ECG signal from MIT-BIH Arrhythmia Database
Error using javaObject
No class org.physionet.wfdb.jni.Rdsamp can be located on the Java class path

Error in rdsamp (line 114)
    javaWfdbRdsamp=javaObject('org.physionet.wfdb.jni.Rdsamp');

Error in wfdbdemo (line 12)
[ecg,Fs,tm]=rdsamp('mitdb/100',1,N);

I extended the case to the ticket #123 where I try to restore the system without changing the directory. Did you change the directory in restoring your system?

cx1111 commented 8 years ago

I also got the error. I did manage to stop it but I still don't exactly understand what is going on. Backstory: A while ago, I first installed the stable release from physionet: https://physionet.org/physiotools/matlab/wfdb-app-matlab/

Running wfdbdemo I got:

Reading samples ECG signal from MIT-BIH Arrhythmia Database
Command exited with non-zero status!!
Error using rdsamp (line 178)
Java exception occurred:
java.lang.NullPointerException
    at
        org.physionet.wfdb.Wfdbexec.execToDoubleArray(Unknown
        Source)

Error in wfdbdemo (line 12)
[tm,ecg]=rdsamp('mitdb/100',1,N);

Running javaclasspath I get at the end:

DYNAMIC JAVA PATH

    /home/cx1111/Downloads/stable/wfdb-app-toolbox-0-9-9/mcode/wfdb-app-JVM7-0-9-9.jar

So it's not complaining about java objects or java class paths. I solved this by replacing the precompiled wfdb libraries in the mcode/nativelibs/linux/lib64 directory with ones I freshly compiled on my system from the wfdb software package:

cd mcode/nativelibs/linux/lib64/
rm *
cp /usr/local/lib/libwfdb* . 

Now wfdbdemo worked. The problem was that the compiled libraries distributed with the package were not suitable for my OS version.

Now I tried to install the latest github version:

git clone git@github.com:ikarosilva/wfdb-app-toolbox.git
cd wfdb-app-toolbox/mcode/

Running from matlab: wfdbdemo

Reading samples ECG signal from MIT-BIH Arrhythmia Database
Warning: Downloaded WFDB cache file:
/home/cx1111/Downloads/wfdb-app-toolbox/database/mitdb/100.dat 
> In wfdbdownload (line 93)
  In rdsamp (line 111)
  In wfdbdemo (line 12) 
Warning: Downloaded WFDB cache file:
/home/cx1111/Downloads/wfdb-app-toolbox/database/mitdb/100.atr 
> In wfdbdownload (line 93)
  In rdsamp (line 111)
  In wfdbdemo (line 12) 
Warning: Downloaded WFDB cache file:
/home/cx1111/Downloads/wfdb-app-toolbox/database/mitdb/100.hea 
> In wfdbdownload (line 93)
  In rdsamp (line 111)
  In wfdbdemo (line 12) 
Error using javaObject
No class org.physionet.wfdb.jni.Rdsamp can be located on the Java class path

Error in rdsamp (line 114)
    javaWfdbRdsamp=javaObject('org.physionet.wfdb.jni.Rdsamp');

Error in wfdbdemo (line 12)
[ecg,Fs,tm]=rdsamp('mitdb/100',1,N);

javaclasspath

DYNAMIC JAVA PATH

    /home/cx1111/Downloads/wfdb-app-toolbox/mcode/wfdb-app-JVM7-0-9-10.jar

So it is complaining about not finding the Rdsamp java class, but the dynamic java path has been set. I restart matlab and run wfdbdemo again:

Reading samples ECG signal from MIT-BIH Arrhythmia Database
Error using javaObject
No class org.physionet.wfdb.jni.Rdsamp can be located on the Java class path

Error in rdsamp (line 114)
    javaWfdbRdsamp=javaObject('org.physionet.wfdb.jni.Rdsamp');

Error in wfdbdemo (line 12)
[ecg,Fs,tm]=rdsamp('mitdb/100',1,N);

Still complaining about the java class. Once again I replace the precompiled libraries with the ones working on my system:

cd nativelibs/linux/lib64/
rm libwfdb*
cp /usr/local/lib/libwfdb* .

And now wfdbdemo works without complaints. So I don't really understand how replacing the libraries solved everything. I understand in my first case where at least it already got to running the compiled rdsamp and just failed to return a value to the java wrapper, so it was likely that the library file was faulty. But this time, the complaint comes before the rdsamp binary could be called. Does the JAR file have some errors in its class names or something? I don't know Java so I can't really investigate this now. Let me know if this helps anyone and if you manage to solve this.

dwuab commented 8 years ago

@cx1111 Intriguing! Actually I encountered the same problem described on CentOS (so it is not a Mac only problem any more) and I don't have root privilege on that machine. I did essentially the same thing as you described (I have no root privilege so I cannot install like you did), and it works!

However, wfdb software does not compile on Mac 10.11.5 (compilation error), so I cannot try the same thing on my Mac.

dwuab commented 8 years ago

@cx1111 I managed to compile wfdb software on Mac with --without-netfiles flag (libcurl causes the compilation to fail on Mac), and then I copied /usr/local/lib/libwfdb* to nativelibs/macosx/bin. Does not work.

phyrwork commented 7 years ago

@cx1111 @samuelandjw Same here. Compiled 10.5.24 on macOS 10.12.3. Works fine without --without-netfiles (Xcode CLI tools installed for libs). Copied files from /{bin,lib} across to nativelibs/macosx/bin, no effect - still broken with same error.

ikarosilva commented 7 years ago

Hey Guys,

You actually don't need the org.physionet.wfdb.jni.Rdsamp. That's an unstable class that I was working on to make RDSAMP much faster (order of magnitudes) by implementing it on the Java Native Interface instead of going through MATLAB/JAVA/System Processes. I got the class to work with Linux and some Mac, but was having trouble compiling on Windows, so its unstable ( we can remove from the branch code).

Quick Fix: If you want to have your code working right now modifu the following code in RDSAMP from:

if(isempty(javaWfdbRdsamp) && (rawUnits ==0)) javaWfdbRdsamp=javaObject('org.physionet.wfdb.jni.Rdsamp'); end

To the following: if(isempty(javaWfdbRdsamp) && (rawUnits ==0)) warning("Option not available") end

You may want to update the help on the function as well.

phyrwork commented 7 years ago

@ikarosilva Brilliant, thanks. Just to add for others' reference:

warning() will complain if you pass it a string ("...") instead of a char array ('...'). I also set the default rawUnits = 1 to avoid needing to pass in all the arguments.

Would be nice if these changes could be added to master until JNI is stable - or documented.

remolaz commented 6 years ago

@ikarosilva Replacing

if(isempty(javaWfdbRdsamp) && (rawUnits ==0)) javaWfdbRdsamp=javaObject('org.physionet.wfdb.jni.Rdsamp'); end

To the following: if(isempty(javaWfdbRdsamp) && (rawUnits ==0)) warning('Option not available') end

I get this error then: Struct contents reference from a non-struct array object. Error in rdsamp (line 197) data=double(conv_matrix(javaWfdbRdsamp.exec(wfdb_argument))); Error in wfdbdemo (line 12) [ecg,Fs,tm]=rdsamp('mitdb/100',1,N);

How can I solve this? Thanks in advance for your help!

hassanaqeelkhan commented 6 years ago

I am having a similar issue while trying to install WFDB for MATLAB on Ubuntu 16.04. I think this problem arises due to the MakeFile in the mcode/nativelibs folder. This Makefile runs partially and succesfully downloads curl and the file 'ecgpuwave-1.3.3.tar.gz' and 'wfdb-10.5.25pre1.tar.gz'. However, it exits at line 338 of Makefile and prints an error (snapshot given below). I seems that it cannot find locate librdsampjni header file.

I did try the Quickfix suggested by ikarosilva and changed the javaWfdbRdsamp=javaObject('org.physionet.wfdb.jni.Rdsamp'); line to warning("Option not available"). However, I still get an error (identical to that posted by remolaz). As a result the wfdbdemo still doesn't work for me.

Here are some of the messages i get before the make terminates

checking whether to build shared libraries... yes checking whether to build static libraries... no checking for java... java checking for javah... no checking for ... no checking jni.h usability... no checking jni.h presence... no checking for jni.h... no configure: error: JNI header files not found. Makefile:338: recipe for target '/home/hak/Documents/MATLAB/WFDB/wfdb-app-toolbox-0-10-0/mcode/nativelibs/custom/build/librdsampjni.isconfig' failed make: *** [/home/hak/Documents/MATLAB/WFDB/wfdb-app-toolbox-0-10-0/mcode/nativelibs/custom/build/librdsampjni.isconfig] Error 1

Any help will be highly appreciated.