access to underlying libraries via Mc-V present in Mc-X

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
kbedka1
Posts: 428
Joined: Wed Jan 28, 2009 7:27 pm

access to underlying libraries via Mc-V present in Mc-X

Post by kbedka1 »

We need to be able to use the underlying McIDAS libraries/routines for manipulating various data in programming languages such as Fortran or C. We have a wealth of experience with this in McIDAS-X, but how would one call these libraries/routines in McIDAS-V? A current Mc-X based compile/link statement would be:

cc -c t2.c ; f77 -O t2.o readareafile.o -L/users/mcidas/lib -lmcidas -lm -o t2.k

Essentially we would not be using Mc-V for visualization, but we would be using data read/calibration or other tools that are “under the hood” of Mc-V. An template example of how to link to a library in a compile statement (C or fortran) and use then use this to read in and calibrate data (i.e. Brightness temperature) from an AREA file would be very useful.
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: access to underlying libraries via Mc-V present in Mc-X

Post by tomw »

The McV "libraries" (which consist of VisAD, IDV, McV, NetCDF and a whole lot more....) are all written in Java. While it is possible (not necessarily easy) to call Java routines from C -- please refer to this article: <http://java.sys-con.com/node/45840> -- I can't help wonder that if you're going to call new Java routines from C/Fortran, why not re-cast the program in Jython?

While I cannot answer the question about the "cc" command, this book contains the specifics of using the JNI:
<http://java.sun.com/docs/books/jni/html/titlepage.html>

Perhaps you could write a small (Java or Jython) program to fetch the data using the McV libraries and then use the file system to "pass" the data along to your C/Fortran program...it might be easier...

Let me add that at present, however, there is very little available in the Java (McV) library to support calibration. In addition, while geo navigation is "complete", the only polar navigation available is "lat-lon per pixel" as we are awaiting resources to develop "real" polar nav. At present, all this is being done with the ADDE servers (either locally or remotely)...which does not preclude you from using this.

I should add that several people have been using the McV (VisAD) library with Matlab and IDL to read, calibrate and navigate AREA data via the ADDE servers.
User avatar
kbedka1
Posts: 428
Joined: Wed Jan 28, 2009 7:27 pm

Re: access to underlying libraries via Mc-V present in Mc-X

Post by kbedka1 »

This is an established cloud property retrieval algorithm written in C and/or Fortranthat has years of legacy to it. I don't think it is feasible to to recode the algorithm in jython.

I would be very helpful to a number of people here if someone were to post the necessary code/commands that would use the McV (VisAD) library to read, calibrate and navigate AREA data via the ADDE servers. Matlab and IDL would be a good start. Are you suggesting that matlab and IDL have functionality to accomplish this, but Fortran and C do not?
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: access to underlying libraries via Mc-V present in Mc-X

Post by tomw »

Thanks for the additional information, Kris. I believe that these complex, legacy applications don't need to be recoded or recast unless there is a compelling reason to use the McV libraries. The "bridge" allows you to run these legacy applications inside Mc-X, while then viewing and interacting with the visual output in the McV environment.

Matlab and IDL have the ability to import and use Java code built-in....that is why they can easily make use of the VisAD library to access AREA data from ADDE servers. The only way I have found for C programs to "call" routines in a Java library is using the information in the link I posted previously -- I did not do an exhaustive search, however.

If you are using Jython (Matlab or IDL), the access to AREA files from ADDE is accomplished in this manner:

import edu.wise.ssec.mcidas.*
a = AreaFile(url)
d = a.getData()
n = a.getNavigation()

The AreaFile class is documented here:
<http://www.ssec.wisc.edu/visad-docs/javadoc/edu/wisc/ssec/mcidas/AreaFile.html>
and you'll find links to how to convert pixel coordinates into lat-lon using the AreaNav
class (see <http://www.ssec.wisc.edu/visad-docs/javadoc/edu/wisc/ssec/mcidas/AREAnav.html> )

All the "calibration" is handled in the server request (the "url" -- read on.....)

The "url" is the request to the ADDE server in this form:
"adde://your.adde.server.gov/imagedata?key1=value&key2=value&key3=value ...."

The "keys" are documented here:
<http://www.ssec.wisc.edu/visad-docs/javadoc/edu/wisc/ssec/mcidas/adde/AddeURLConnection.html>

In addition, if you use McV to make an ADDE request, you can look in the Dataset Properties (in the Field Selector, right click on the Dataset name, and choose "Properties" and then "Details". The "location" is the url string....looking something like this:

"adde://adde.ucar.edu/imagedata?&PORT=112&COMPRESS =gzip&USER=idv&PROJ=0&VERSION=1&DEBUG=false&TRACE =0&GROUP=RTIMAGES&DESCRIPTOR=GE-CO2&BAND=6&LINELE =700 864&PLACE=CENTER&SIZE=700 864&UNIT=BRIT&MAG= -2 -2&SPAC=1&NAV=X&AUX=YES&DOC=X&POS=0"

The actual syntax for Matlab or IDL is different. For example in Matlab, one user did this:

a=AreaFile(filename);
b=getData(a);
b2=squeeze(b);
[m,n]=size(b2);
[lonIndices,latIndices]=ind2sub([m n],1:m*n);
p=getNavigation(a);
lalo=tolatlon(p,[latIndices,lonIndicies]);

Hope that helps.....
Post Reply