Changeset 1615
- Timestamp:
- Nov 16, 2009, 3:03:37 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/app-fermi/matlab/compiled/fermi_main.m
r1222 r1615 13 13 fclose(fid); 14 14 append = 1; 15 rpLibPutString(lib,'output.log',lastmsg,append) 15 rpLibPutString(lib,'output.log',lastmsg,append); 16 16 rpLibResult(lib,1); 17 17 end -
trunk/examples/objects/app-fermi/fermi4.c
r1581 r1615 1 2 1 // ---------------------------------------------------------------------- 3 // EXAMPLE: Fermi-Dirac function in Python.2 // EXAMPLE: Fermi-Dirac function in C 4 3 // 5 4 // This simple example shows how to use Rappture within a simulator … … 22 21 int main(int argc, char * argv[]) { 23 22 24 R appture_Library *lib = NULL;25 R appture_Number *T = NULL;23 Rp_Library *lib = NULL; 24 Rp_Number *T = NULL; 26 25 27 26 double Ef = 0.0; … … 36 35 double fArr[nPts]; 37 36 38 const char *curveLabel = "Fermi-Dirac Curve" 39 const char *curveDesc = "Plot of Fermi-Dirac Calculation"; 40 41 Rappture::Plot *p1 = NULL; 37 Rp_Plot *p1 = NULL; 42 38 43 39 // create a rappture library from the file filePath 44 lib = Rappture_Library_init(argv[1]); 40 lib = Rp_LibraryInit(); 41 Rp_LibraryLoadFile(lib,argv[1]); 45 42 46 if (R appture_Library_error(lib) != 0) {43 if (Rp_LibraryError(lib) != 0) { 47 44 // cannot open file or out of memory 48 fprintf(stderr,Rappture_Library_traceback(lib)); 49 return(Rappture_Library_error(lib)); 45 Rp_Outcome *o = Rp_LibraryOutcome(lib); 46 fprintf(stderr, "%s", Rp_OutcomeContext(o)); 47 fprintf(stderr, "%s", Rp_OutcomeRemark(o)); 48 return(Rp_LibraryError(lib)); 50 49 } 51 50 52 R appture_connect(lib,"temperature",T);53 R appture_Library_value(lib,"Ef",&Ef,"units=eV");51 Rp_Connect(lib,"temperature",T); 52 Rp_LibraryValue(lib,"Ef",&Ef,1,"units=eV"); 54 53 55 if (R appture_Library_error(lib) != 0) {54 if (Rp_LibraryError(lib) != 0) { 56 55 // there were errors while retrieving input data values 57 56 // dump the tracepack 58 fprintf(stderr,Rappture_Library_traceback(lib)); 59 return(Rappture_Library_error(lib)); 57 Rp_Outcome *o = Rp_LibraryOutcome(lib); 58 fprintf(stderr, "%s", Rp_OutcomeContext(o)); 59 fprintf(stderr, "%s", Rp_OutcomeRemark(o)); 60 return(Rp_LibraryError(lib)); 60 61 } 61 62 62 kT = 8.61734e-5 * R appture_Number_value(T,"K");63 kT = 8.61734e-5 * Rp_NumberValue(T,"K"); 63 64 Emin = Ef - 10*kT; 64 65 Emax = Ef + 10*kT; 65 66 66 dE = 0.005*(Emax-Emin);67 dE = (1.0/nPts)*(Emax-Emin); 67 68 68 69 E = Emin; … … 72 73 fArr[idx] = f; 73 74 EArr[idx] = E; 74 R appture_Utils_Progress((int)((E-Emin)/(Emax-Emin)*100),"Iterating");75 Rp_UtilsProgress((int)((E-Emin)/(Emax-Emin)*100),"Iterating"); 75 76 } 76 77 … … 78 79 // create a plot to add to the library 79 80 // plot is registered with lib upon object creation 80 // p1->add(nPts,xArr,yArr,format, curveLabel,curveDesc);81 // p1->add(nPts,xArr,yArr,format,name); 81 82 82 p1 = Rappture_Plot_init(lib); 83 Rappture_Plot_add(p1,nPts,fArr,EArr,"",curveLabel,curveDesc); 84 Rappture_Plot_propstr(p1,"xlabel","Fermi-Dirac Factor"); 85 Rappture_Plot_propstr(p1,"ylabel","Energy"); 86 Rappture_Plot_propstr(p1,"yunits","eV"); 83 p1 = Rp_PlotInit(lib); 84 Rp_PlotAdd(p1,nPts,fArr,EArr,"","fdfactor"); 85 Rp_PlotPropstr(p1,"label","Fermi-Dirac Curve"); 86 Rp_PlotPropstr(p1,"desc","Plot of Fermi-Dirac Calculation"); 87 Rp_PlotPropstr(p1,"xlabel","Fermi-Dirac Factor"); 88 Rp_PlotPropstr(p1,"ylabel","Energy"); 89 Rp_PlotPropstr(p1,"yunits","eV"); 87 90 88 Rappture_Library_result(lib); 91 Rp_LibraryResult(lib); 92 89 93 return 0; 90 94 } -
trunk/examples/objects/app-fermi/fermi4.cc
r1581 r1615 14 14 #include "rappture.h" 15 15 16 #include < stdlib.h>17 #include < stdio.h>16 #include <cstdlib> 17 #include <cstdio> 18 18 #include <math.h> 19 19 #include <unistd.h> … … 22 22 23 23 // create a rappture library from the file filePath 24 Rappture::Library lib (argv[1]);24 Rappture::Library lib; 25 25 Rappture::Number *T; 26 26 … … 36 36 double fArr[nPts]; 37 37 38 lib.loadFile(argv[1]); 38 39 if (lib.error() != 0) { 39 40 // cannot open file or out of memory … … 41 42 fprintf(stderr, "%s",o.context()); 42 43 fprintf(stderr, "%s",o.remark()); 43 exit(lib.error());44 return (lib.error()); 44 45 } 45 46 46 Rappture:: connect(&lib,"temperature",T);47 Rappture::Connect(&lib,"temperature",T); 47 48 lib.value("Ef", &Ef, 1, "units=eV"); 48 49 … … 53 54 fprintf(stderr, "%s",o.context()); 54 55 fprintf(stderr, "%s",o.remark()); 55 exit(lib.error());56 return(lib.error()); 56 57 } 57 58 … … 68 69 fArr[idx] = f; 69 70 EArr[idx] = E; 70 rpUtilsProgress((int)((E-Emin)/(Emax-Emin)*100),"Iterating");71 Rappture::Utils::progress((int)((E-Emin)/(Emax-Emin)*100),"Iterating"); 71 72 } 72 73 const char *curveLabel = "Fermi-Dirac Curve"74 const char *curveDesc = "Plot of Fermi-Dirac Calculation";75 73 76 74 // do it the easy way, 77 75 // create a plot to add to the library 78 76 // plot is registered with lib upon object creation 79 // p1.add(nPts,xArr,yArr,format, curveLabel,curveDesc);77 // p1.add(nPts,xArr,yArr,format,name); 80 78 81 79 Rappture::Plot p1(lib); 82 p1.add(nPts,fArr,EArr,"",curveLabel,curveDesc); 80 p1.add(nPts,fArr,EArr,"","fdfactor"); 81 p1.propstr("label","Fermi-Dirac Curve"); 82 p1.propstr("desc","Plot of Fermi-Dirac Calculation"); 83 83 p1.propstr("xlabel","Fermi-Dirac Factor"); 84 84 p1.propstr("ylabel","Energy"); -
trunk/examples/objects/app-fermi/fermi4.m
r1581 r1615 21 21 22 22 % open our xml input file. 23 lib = Rappture_Library(infile); 23 lib = Rp_LibraryInit(); 24 Rp_LibraryLoadFile(lib, infile); 24 25 25 26 nPts = 200; 26 27 27 if (R appture_Library_error(lib) == 0)) {28 if (Rp_LibraryError(lib) != 0)) { 28 29 % cannot open file or out of memory 29 fprintf(stderr, Rappture_Library_traceback(lib)); 30 exit(Rappture_Library_error(lib)); 30 o = Rp_LibraryOutcome(lib); 31 fprintf(stderr, '%s', Rp_LibraryContext(o)); 32 fprintf(stderr, '%s', Rp_LibraryRemark(o)); 33 return; 31 34 } 32 35 33 T = R appture_connect(lib,'temperature');34 Ef = R appture_Library_value(lib,'Ef','units=eV');36 T = Rp_Connect(lib,'temperature'); 37 Ef = Rp_LibraryValue(lib,'Ef','units=eV'); 35 38 36 if (R appture_Library_error(lib) == 0) {39 if (Rp_LibraryError(lib) != 0) { 37 40 % there were errors while retrieving input data values 38 41 % dump the tracepack 39 fprintf(stderr,Rappture_Library_traceback(lib)); 42 o = Rp_LibraryOutcome(lib); 43 fprintf(stderr, '%s', Rp_LibraryContext(o)); 44 fprintf(stderr, '%s', Rp_LibraryRemark(o)); 45 return; 40 46 } 41 47 42 48 % do fermi calculations (science)... 43 kT = 8.61734e-5 * R appture_Number_value(T,'K');49 kT = 8.61734e-5 * Rp_NumberValue(T,'K'); 44 50 Emin = Ef - 10*kT; 45 51 Emax = Ef + 10*kT; 46 52 47 53 EArr = linspace(Emin,Emax,nPts); 48 fArr = 1.0 ./ (1.0 + exp((E - Ef)/kT)); 49 50 51 curveLabel = 'Fermi-Dirac Curve'; 52 curveDesc = 'Plot of Fermi-Dirac Calculation'; 54 fArr = 1.0 ./ (1.0 + exp((EArr - Ef)/kT)); 53 55 54 56 % do it the easy way, 55 57 % create a plot to add to the library 56 58 % plot is registered with lib upon object creation 57 % p1->add(nPts,xArr,yArr,format, curveLabel,curveDesc);59 % p1->add(nPts,xArr,yArr,format,name); 58 60 59 p1 = Rappture_Plot(lib); 60 Rappture_Plot_add(p1,nPts,fArr,EArr,"",curveLabel,curveDesc); 61 Rappture_Plot_propstr(p1,"xlabel","Fermi-Dirac Factor"); 62 Rappture_Plot_propstr(p1,"ylabel","Energy"); 63 Rappture_Plot_propstr(p1,"yunits","eV"); 61 p1 = Rp_PlotInit(lib); 62 Rp_PlotAdd(p1,nPts,fArr,EArr,'','fdfactor'); 63 Rp_PlotPropstr(p1,'label','Fermi-Dirac Curve'); 64 Rp_PlotPropstr(p1,'desc','Plot of Fermi-Dirac Calculation'); 65 Rp_PlotPropstr(p1,'xlabel','Fermi-Dirac Factor'); 66 Rp_PlotPropstr(p1,'ylabel','Energy'); 67 Rp_PlotPropstr(p1,'yunits','eV'); 64 68 65 R appture_Library_result(lib);69 Rp_LibraryResult(lib); 66 70 67 quit;71 return; -
trunk/examples/objects/app-fermi/fermi4.py
r1586 r1615 55 55 56 56 # create a rappture library from the file filePath 57 lib = Rappture.Library( argv[1])57 lib = Rappture.Library() 58 58 59 59 nPts = 200; 60 EArr = list() # [nPts] ;61 fArr = list() # [nPts] ;60 EArr = list() # [nPts] 61 fArr = list() # [nPts] 62 62 63 lib.loadFile(sys.argv[1]) 63 64 if (lib.error() != 0) { 64 65 # cannot open file or out of memory 65 print >>sys.stderr, lib.traceback() 66 exit(lib.error()); 66 o = lib.outcome() 67 print >>sys.stderr, "%s", o.context() 68 print >>sys.stderr, "%s", o.remark() 69 return (lib.error()); 67 70 } 68 71 69 T = Rappture. connect(lib,"temperature");70 Ef = lib.value("Ef","units=eV") ;72 T = Rappture.Connect(lib,"temperature") 73 Ef = lib.value("Ef","units=eV") 71 74 72 75 if (lib.error() != 0) { 73 76 # there were errors while retrieving input data values 74 77 # dump the tracepack 75 print >>sys.stderr, lib.traceback() 76 exit(lib.error()); 78 o = lib.outcome() 79 print >>sys.stderr, "%s", o.context() 80 print >>sys.stderr, "%s", o.remark() 81 return (lib.error()) 77 82 } 78 83 79 kT = 8.61734e-5 * T.value("K") ;80 Emin = Ef - 10*kT ;81 Emax = Ef + 10*kT ;84 kT = 8.61734e-5 * T.value("K") 85 Emin = Ef - 10*kT 86 Emax = Ef + 10*kT 82 87 83 dE = (1.0/nPts)*(Emax-Emin) ;88 dE = (1.0/nPts)*(Emax-Emin) 84 89 85 90 E = Emin; 86 91 for (size_t idx = 0; idx < nPts; idx++) { 87 E = E + dE ;88 f = 1.0/(1.0 + exp((E - Ef)/kT)) ;89 fArr.append(f) ;90 EArr.append(E) ;91 Rappture.Utils.progress((int)((E-Emin)/(Emax-Emin)*100),"Iterating") ;92 E = E + dE 93 f = 1.0/(1.0 + exp((E - Ef)/kT)) 94 fArr.append(f) 95 EArr.append(E) 96 Rappture.Utils.progress((int)((E-Emin)/(Emax-Emin)*100),"Iterating") 92 97 } 93 94 curveLabel = "Fermi-Dirac Curve"95 curveDesc = "Plot of Fermi-Dirac Calculation";96 98 97 99 # do it the easy way, 98 100 # create a plot to add to the library 99 101 # plot is registered with lib upon object creation 100 # p1->add(nPts,xArr,yArr,format, curveLabel,curveDesc);102 # p1->add(nPts,xArr,yArr,format,name); 101 103 102 p1 = Rappture.Plot(lib); 103 p1.add(nPts,fArr,EArr,"",curveLabel,curveDesc); 104 p1.propstr("xlabel","Fermi-Dirac Factor"); 105 p1.propstr("ylabel","Energy"); 106 p1.propstr("yunits","eV"); 104 p1 = Rappture.Plot(lib) 105 p1.add(nPts,fArr,EArr,"","fdfactor") 106 p1.propstr("label","Fermi-Dirac Curve") 107 p1.propstr("desc","Plot of Fermi-Dirac Calculation") 108 p1.propstr("xlabel","Fermi-Dirac Factor") 109 p1.propstr("ylabel","Energy") 110 p1.propstr("yunits","eV") 107 111 108 lib.result() ;112 lib.result() 109 113 110 return 0 ;114 return 0 111 115 } 112 116 -
trunk/examples/objects/app-fermi/fermi4.tcl
r1581 r1615 14 14 15 15 # open the XML file containing the run parameters 16 set lib [Rappture::Library [lindex $argv 0]] 16 set lib [Rappture::Library] 17 18 $lib loadFile [lindex $argv 0] 17 19 18 20 if {[$lib error] != 0} { 19 21 # cannot open file or out of memory 20 puts stderr [$lib traceback] 22 set o [$lib outcome] 23 puts stderr [$o context] 24 puts stderr [$o remark] 21 25 exit [$lib error] 22 26 } 23 27 24 set T [Rappture:: connect $lib "temperature"]25 set Ef [$lib value "Ef" "units =eV"]28 set T [Rappture::Connect $lib "temperature"] 29 set Ef [$lib value "Ef" "units eV"] 26 30 27 31 if {[$lib error != 0]} { 28 32 # there were errors while retrieving input data values 29 33 # dump the tracepack 30 puts stderr [$lib traceback] 34 set o [$lib outcome] 35 puts stderr [$o context] 36 puts stderr [$o remark] 31 37 exit [$lib error] 32 38 } … … 38 44 set Emax [expr {$Ef + 10*$kT}] 39 45 40 set dE [expr { 0.005*($Emax-$Emin)}]46 set dE [expr {(1.0/$nPts)*($Emax-$Emin)}] 41 47 42 48 set E $Emin … … 50 56 } 51 57 52 set curveLabel "Fermi-Dirac Curve"53 set curveDesc "Plot of Fermi-Dirac Calculation"54 55 58 # do it the easy way, 56 59 # create a plot to add to the library … … 59 62 60 63 set p1 [Rappture::Plot $lib] 61 $p1 add $nPts $fArr $EArr "" $curveLabel $curveDesc 64 $p1 add $fArr $EArr -name "fdfactor" 65 $p1 propstr "label" "Fermi-Dirac Curve" 66 $p1 propstr "desc" "Plot of Fermi-Dirac Calculation" 62 67 $p1 propstr "xlabel" "Fermi-Dirac Factor" 63 68 $p1 propstr "ylabel" "Energy" -
trunk/src/objects/RpLibObj.h
r1581 r1615 27 27 #ifdef __cplusplus 28 28 29 #include "RpBuffer.h"30 29 #include "RpOutcome.h" 31 30 #include "RpInt.h" -
trunk/src/objects/RpNumber.cc
r1581 r1615 229 229 } 230 230 231 if (_minSet) { 232 convertedVal = fromUnit->convert(toUnit,min(), &err); 233 if (err) { 234 _status.addError("undefined error while converting %s to %s", 235 (fromUnit->getUnitsName()).c_str(), 236 (toUnit->getUnitsName()).c_str()); 237 } else { 238 min(convertedVal); 239 } 240 } 241 242 if (_maxSet) { 243 convertedVal = fromUnit->convert(toUnit,max(), &err); 244 if (err) { 245 _status.addError("undefined error while converting %s to %s", 246 (fromUnit->getUnitsName()).c_str(), 247 (toUnit->getUnitsName()).c_str()); 248 } else { 249 max(convertedVal); 250 } 251 } 231 252 return _status; 232 253 }
Note: See TracChangeset
for help on using the changeset viewer.