Changeset 1727
- Timestamp:
- May 20, 2010 2:13:17 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/app-fermi/java/Fermi.java
r1722 r1727 1 /* 2 * EXAMPLE: Fermi-Dirac function in Java. 3 * 4 * This simple example shows how to use Rappture within a simulator 5 * written in Java. 6 * ====================================================================== 7 * AUTHOR: Ben Rafferty, Purdue University 8 * Copyright (c) 2010 Purdue Research Foundation 9 * 10 * See the file "license.terms" for information on usage and 11 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 12 * ====================================================================== 13 */ 1 14 2 15 class Fermi{ … … 4 17 public static void main(String args[]){ 5 18 19 // create a rappture library from the file path 6 20 rappture.Library driver = new rappture.Library(args[0]); 7 21 22 // read the input values and convert to correct units 8 23 String Tstr = driver.get("input.number(temperature).current"); 9 24 double T = Double.valueOf(rappture.Units.convert(Tstr, "K", false)); 10 11 25 String Efstr = driver.get("input.number(Ef).current"); 12 26 double Ef = Double.valueOf(rappture.Units.convert(Efstr, "eV", false)); 13 27 28 // Set the energy range and step size 14 29 double kT = 8.61734E-5 * T; 15 30 double Emin = Ef - 10*kT; 16 31 double Emax = Ef + 10*kT; 17 18 32 double E = Emin; 19 33 double dE = 0.005*(Emax-Emin); 20 34 21 double f; 22 String line; 23 35 // Add relevant information to the output curve 24 36 driver.put("output.curve(f12).about.label", "Fermi-Dirac Factor"); 25 37 driver.put("output.curve(f12).xaxis.label", "Fermi-Dirac Factor"); … … 27 39 driver.put("output.curve(f12).yaxis.units", "eV"); 28 40 41 // Calculate the Fermi-Dirac function over the energy range 42 // Add the results to the output curve 43 double f; 44 String line; 29 45 while (E < Emax){ 30 46 f = 1.0/(1.0 + Math.exp((E - Ef)/kT)); … … 35 51 } 36 52 53 // Finalize the results and inform rappture that the simulation has ended 37 54 driver.result(); 38 55 } -
trunk/examples/app-fermi/java/Makefile.in
r1722 r1727 36 36 37 37 clean: 38 $(RM) Fermi.class38 $(RM) Fermi.class 39 39 40 40 distclean: clean -
trunk/lang/java/Library.java
r1722 r1727 1 /* 2 * ====================================================================== 3 * AUTHOR: Ben Rafferty, Purdue University 4 * Copyright (c) 2010 Purdue Research Foundation 5 * 6 * See the file "license.terms" for information on usage and 7 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 8 * ====================================================================== 9 */ 10 11 /* 12 * This file defines a Java class that implemements the rappture XML library. 13 * The class methods call the corresponding native code through c++ glue code 14 * located in jRpLibrary.cc. 15 */ 16 1 17 package rappture; 2 18 … … 11 27 } 12 28 13 // Pseudo-Destructor ---------------------------------------------------------29 // Pseudo-Destructor. Called when the object is garbage collected.---------- 14 30 protected void finalize() throws Throwable { 15 31 try { … … 58 74 private native String jRpGetString(long libPtr, String path); 59 75 60 private native void jRpPut(long libPtr, String path, String value, boolean append); 76 private native void jRpPut(long libPtr, String path, 77 String value, boolean append); 61 78 62 79 private native void jRpResult(long libPtr, int exitStatus); 63 80 64 81 // Private Attributes-------------------------------------------------------- 65 private long libPtr; //pointer to c rpLibrary82 private long libPtr; //pointer to c++ RpLibrary 66 83 67 84 } 68 85 69 70 -
trunk/lang/java/Makefile.in
r1724 r1727 39 39 RM = rm -f 40 40 41 INCLUDES = $(JAVA_INCLUDES) -I $( includedir)-I .42 LIBS = -L $(LIB_SEARCH_DIRS)-lrappture41 INCLUDES = $(JAVA_INCLUDES) -I $(srcdir)/../../src/core -I . 42 LIBS = -L ../../src/core -lrappture 43 43 44 CXX_O_SWITCHES = -fpic -c $(INCLUDES) $(LIBS)44 CXX_O_SWITCHES = -fpic -c $(INCLUDES) 45 45 46 CXX_SO_SWITCHES = --shared $( LIBS)46 CXX_SO_SWITCHES = --shared $(INCLUDES) $(LIBS) 47 47 48 48 OBJS = \ -
trunk/lang/java/Units.java
r1722 r1727 1 /* 2 * ====================================================================== 3 * AUTHOR: Ben Rafferty, Purdue University 4 * Copyright (c) 2010 Purdue Research Foundation 5 * 6 * See the file "license.terms" for information on usage and 7 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 8 * ====================================================================== 9 */ 10 11 /* 12 * This file defines a java class that implemements the rappture units module. 13 * The class methods call the corresponding native code through c++ glue code 14 * located in jRpUnits.cc. 15 */ 16 17 1 18 package rappture; 2 19 -
trunk/lang/java/Utils.java
r1722 r1727 1 /* 2 * ====================================================================== 3 * AUTHOR: Ben Rafferty, Purdue University 4 * Copyright (c) 2010 Purdue Research Foundation 5 * 6 * See the file "license.terms" for information on usage and 7 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 8 * ====================================================================== 9 */ 10 11 /* 12 * This file defines a java class that implemements the rappture utils module. 13 * The class methods call the corresponding native code through c++ glue code 14 * located in jRpUtils.cc. 15 */ 16 1 17 package rappture; 2 18 -
trunk/lang/java/jRpLibrary.cc
r1722 r1727 1 /* 2 * ====================================================================== 3 * AUTHOR: Ben Rafferty, Purdue University 4 * Copyright (c) 2010 Purdue Research Foundation 5 * 6 * See the file "license.terms" for information on usage and 7 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 8 * ====================================================================== 9 */ 10 11 /* 12 * This file defines the native functions which are called by the java Library 13 * class methods, and in turn call the corresponding rappture RpLibrary methods. 14 */ 15 1 16 #include "jRpLibrary.h" 2 17 #include "rappture.h" 3 18 4 // constructor 19 /* 20 * Constructor. Returns the address of the newly created RpLibrary object to 21 * java as a long int. 22 */ 5 23 JNIEXPORT jlong JNICALL Java_rappture_Library_jRpLibrary 6 24 (JNIEnv *env, jobject obj, jstring javaPath){ … … 11 29 } 12 30 13 // Pseudo-destructor 31 /* 32 * Pseudo-destructor. This function is called by the java Library class's 33 * finalizer. 34 */ 14 35 JNIEXPORT void JNICALL Java_rappture_Library_jRpDeleteLibrary 15 36 (JNIEnv *env, jobject obj, jlong libPtr){ -
trunk/lang/java/jRpUnits.cc
r1722 r1727 1 /* 2 * ====================================================================== 3 * AUTHOR: Ben Rafferty, Purdue University 4 * Copyright (c) 2010 Purdue Research Foundation 5 * 6 * See the file "license.terms" for information on usage and 7 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 8 * ====================================================================== 9 */ 10 11 /* 12 * This file defines the native functions which are called by the java Units 13 * class methods, and in turn call the corresponding rappture RpUnits methods. 14 */ 15 1 16 #include "jRpUnits.h" 2 17 #include "rappture.h" 3 18 19 // convert 4 20 JNIEXPORT jstring JNICALL Java_rappture_Units_jRpUnitsConvert 5 21 (JNIEnv *env, jclass cls, jstring javaFromVal, jstring javaTo, jboolean units){ -
trunk/lang/java/jRpUtils.cc
r1722 r1727 1 /* 2 * ====================================================================== 3 * AUTHOR: Ben Rafferty, Purdue University 4 * Copyright (c) 2010 Purdue Research Foundation 5 * 6 * See the file "license.terms" for information on usage and 7 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 8 * ====================================================================== 9 */ 10 11 /* 12 * This file defines the native functions which are called by the java Utils 13 * class methods, and in turn call the corresponding rappture RpUtils methods. 14 */ 15 1 16 #include "jRpUtils.h" 2 17 #include "rappture.h" 3 18 19 // progress 4 20 JNIEXPORT void JNICALL Java_rappture_Utils_jRpUtilsProgress 5 21 (JNIEnv *env, jclass cls, jint percent, jstring javaText){ 6 const char* nativeText = env->GetStringUTFChars(javaText, 0);22 const char* nativeText = env->GetStringUTFChars(javaText, 0); 7 23 Rappture::Utils::progress(percent, nativeText); 8 24 env->ReleaseStringUTFChars(javaText, nativeText);
Note: See TracChangeset
for help on using the changeset viewer.