This is an incomplete example, because I am using the Java-IDL Export Bridge, not the COM-IDL Export Bridge, and because I am using the 'java_IDL_connect' object, not an object of a custom class built with the IDL Bridge Assistant. However, I bet, if you were to change your 'helloworldex2::HelloFrom' method to execute 'message = BSTATS1_FUNCTION( )' that you would not get an error. Here, I think, are two critical elements to the Java-IDL-Export-Bridge/ENVI interface:
1) ENVI code in this interface will not run until initial calls to:
ENVI, /RESTORE_BASE_SAVE_FILES
and:
ENVI_BATCH_INIT
are made. These calls should ideally be made in the 'Init' method of any custom export bridge class you create. But they can just as well be made in the ENVI-based procedures or functions that you call from methods in your custom class. (There is no harm in redundant calls to these ENVI procedures; they return doing nothing, if they detect that the ENVI libraries are already loaded.)
2) Contrary to ENVI documentation, do NOT call ENVI_BATCH_EXIT in any ENVI-based routines you write or in the body of any export bridge class methods you implement.
The example below is the simplest possible modification of an example ENVI programming app that Tech Support frequently uses for demonstration, called by the simplest possible modification to the IDL Connectivity Bridges manual Java-IDL Connect Object example, 'hello_example.java'.
The ENVI+IDL source code example:
; Just demonstrates ENVI_STATS_DO_IT text output using the built-in
; ENVI example data file 'bhtmref.img'
FUNCTION bstats1_function
; Restore the core file and initialize ENVI
envi, /RESTORE_BASE_SAVE_FILES
envi_batch_init
; Routine file-opening calls
envi_open_file, filepath('bhtmref.img', SUBDIR=['products', 'envi43', 'data']), $
R_FID = fid ; NOTE: THE FILEPATH IS VALID ONLY FOR ENVI 4.3!!!
if (fid eq -1) then return, -1
envi_file_query, fid, NS=ns, NL=nl, NB=nb
; Set the DIMS and POS to process all bands of the image
dims = [-1, 0, ns-1 , 0, nl-1]
pos = lindgen(nb)
; Calculate the basic statistics
envi_doit, 'envi_stats_doit', FID=fid, POS=pos, DIMS=dims, DMIN=dmin, $
DMAX=dmax, MEAN=mean, STDV=stdv, COMP_FLAG=1
print, dmin, dmax, mean, stdv
return, stdv ; Just to demonstrate returning a value to the Bridge
; DO NOT UNCOMMENT - DO NOT EXIT ENVI!!!
;ENVI_BATCH_EXIT, /NO_CONFIRM
END
The Java Class that can run the above:
NOTE: MUST USE IDL 6.3's 'javaidlb.jar' ARCHIVE!
import com.idl.javaidl.*;
public class ExJavaEnviExportBridge implements JIDLOutputListener {
java_IDL_connect ostock;
public ExJavaEnviExportBridge( ) {
ostock = new java_IDL_connect( );
ostock.createObject( );
ostock.addIDLOutputListener( this );
ostock.executeString("stdv = bstats1_function()");
ostock.executeString("print, stdv");
}
// cleanup
private void destroyWrapper( ) {
ostock.destroyObject( );
}
public void IDLoutput(JIDLObjectI arg0, String sMessage) {
System.out.println( sMessage );
}
public static void main(String[] args) {
ExJavaEnviExportBridge example = new ExJavaEnviExportBridge( );
example.destroyWrapper( );
}
}
|