- Timestamp:
- Dec 3, 2009, 10:01:34 AM (15 years ago)
- Location:
- trunk/examples/objects/app-fermi
- Files:
-
- 15 added
- 5 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/objects/app-fermi/c/fermi4.c
r1615 r1620 19 19 #include <unistd.h> 20 20 21 #include "fermi_io.c" 22 21 23 int main(int argc, char * argv[]) { 22 24 23 Rp_Library *lib = NULL; 24 Rp_Number *T = NULL; 25 // declare variables to interact with Rappture 26 double T = 0.0; 27 double Ef = 0.0; 28 Rp_Table *result = NULL; 25 29 26 double Ef = 0.0; 30 31 // declare program variables 27 32 double E = 0.0; 28 33 double dE = 0.0; … … 35 40 double fArr[nPts]; 36 41 37 Rp_Plot *p1 = NULL; 42 // initialize the global interface 43 Rp_InterfaceInit(argc,argv,&fermi_io); 38 44 39 // create a rappture library from the file filePath 40 lib = Rp_LibraryInit(); 41 Rp_LibraryLoadFile(lib,argv[1]); 42 43 if (Rp_LibraryError(lib) != 0) { 44 // cannot open file or out of memory 45 Rp_Outcome *o = Rp_LibraryOutcome(lib); 45 // check the global interface for errors 46 if (Rp_InterfaceError() != 0) { 47 // there were errors while setting up the interface 48 // dump the traceback 49 Rp_Outcome *o = Rp_InterfaceOutcome(); 46 50 fprintf(stderr, "%s", Rp_OutcomeContext(o)); 47 51 fprintf(stderr, "%s", Rp_OutcomeRemark(o)); 48 return(Rp_ LibraryError(lib));52 return(Rp_InterfaceError()); 49 53 } 50 54 51 Rp_Connect(lib,"temperature",T); 52 Rp_LibraryValue(lib,"Ef",&Ef,1,"units=eV"); 55 // connect variables to the interface 56 // look in the global interface for an object named 57 // "temperature", convert its value to Kelvin, and 58 // store the value into the address of T. 59 // look in the global interface for an object named 60 // "Ef", convert its value to electron Volts and store 61 // the value into the address of Ef. 62 // look in the global interface for an object named 63 // factorsTable and set the variable result to 64 // point to it. 65 Rp_InterfaceConnect("temperature",&T,"units=K",NULL); 66 Rp_InterfaceConnect("Ef",&Ef,"units=eV",NULL); 67 Rp_InterfaceConnect("factorsTable",result,NULL); 53 68 54 if (Rp_LibraryError(lib) != 0) { 69 // check the global interface for errors 70 if (Rp_InterfaceError() != 0) { 55 71 // there were errors while retrieving input data values 56 // dump the trace pack57 Rp_Outcome *o = Rp_ LibraryOutcome(lib);72 // dump the traceback 73 Rp_Outcome *o = Rp_InterfaceOutcome(); 58 74 fprintf(stderr, "%s", Rp_OutcomeContext(o)); 59 75 fprintf(stderr, "%s", Rp_OutcomeRemark(o)); 60 return(Rp_ LibraryError(lib));76 return(Rp_InterfaceError()); 61 77 } 62 78 63 kT = 8.61734e-5 * Rp_NumberValue(T,"K"); 64 Emin = Ef - 10*kT; 65 Emax = Ef + 10*kT; 79 // do science calculations 80 kT = 8.61734e-5 * T; 81 Emin = Ef - (10*kT); 82 Emax = Ef + (10*kT); 66 83 67 84 dE = (1.0/nPts)*(Emax-Emin); … … 76 93 } 77 94 78 // do it the easy way, 79 // create a plot to add to the library 80 // plot is registered with lib upon object creation 81 // p1->add(nPts,xArr,yArr,format,name); 95 // store results in the results table 96 // add data to the table pointed to by the variable result. 97 // put the fArr data in the column named "Fermi-Dirac Factor" 98 // put the EArr data in the column named "Energy" 99 // 100 Rp_TableAddData(result,"Fermi-Dirac Factor",nPts,fArr); 101 Rp_TableAddData(result,"Energy",nPts,EArr); 82 102 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"); 90 91 Rp_LibraryResult(lib); 103 // close the global interface 104 // signal to the graphical user interface that science 105 // calculations are complete and to display the data 106 // as described in the views 107 Rp_InterfaceClose(); 92 108 93 109 return 0; -
trunk/examples/objects/app-fermi/cpp/fermi4.cc
r1615 r1620 19 19 #include <unistd.h> 20 20 21 #include "fermi_io.c" 22 21 23 int main(int argc, char * argv[]) { 22 24 23 // create a rappture library from the file filePath 24 Rappture::Library lib; 25 Rappture::Number *T; 25 // declare variables to interact with Rappture 26 double T = 0.0; 27 double Ef = 0.0; 28 Rappture::Table *result = NULL; 26 29 27 double Ef = 0.0;30 // declare program variables 28 31 double E = 0.0; 29 32 double dE = 0.0; … … 36 39 double fArr[nPts]; 37 40 38 lib.loadFile(argv[1]); 39 if (lib.error() != 0) { 40 // cannot open file or out of memory 41 Rappture::Outcome o = lib.outcome(); 41 // initialize the global interface 42 Rappture::Interface(argc,argv,&fermi_io); 43 44 //check the global interface for errors 45 if (Rappture::Interface::error() != 0) { 46 // there were errors while setting up the interface 47 // dump the traceback 48 Rappture::Outcome o = Rappture::Interface::outcome(); 42 49 fprintf(stderr, "%s",o.context()); 43 50 fprintf(stderr, "%s",o.remark()); 44 return ( lib.error());51 return (Rappture::Interface::error()); 45 52 } 46 53 47 Rappture::Connect(&lib,"temperature",T); 48 lib.value("Ef", &Ef, 1, "units=eV"); 54 // connect variables to the interface 55 // look in the global interface for an object named 56 // "temperature", convert its value to Kelvin, and 57 // store the value into the address of T. 58 // look in the global interface for an object named 59 // "Ef", convert its value to electron Volts and store 60 // the value into the address of Ef 61 // look in the global interface for an object named 62 // factorsTable and set the variable result to 63 // point to it. 64 Rappture::Interface::connect("temperature",&T,"units=K",NULL); 65 Rappture::Interface::connect("Ef",&Ef,"units=eV",NULL); 66 Rappture::Interface::connect("factorsTable",result,NULL); 49 67 50 if (lib.error() != 0) { 68 // check the global interface for errors 69 if (Rappture::Interface::error() != 0) { 51 70 // there were errors while retrieving input data values 52 71 // dump the tracepack 53 Rappture::Outcome o = lib.outcome();72 Rappture::Outcome o = Rappture::Interface::outcome(); 54 73 fprintf(stderr, "%s",o.context()); 55 74 fprintf(stderr, "%s",o.remark()); 56 return( lib.error());75 return(Rappture::Interface::error()); 57 76 } 58 77 59 kT = 8.61734e-5 * T->value("K"); 78 // do science calculations 79 kT = 8.61734e-5 * T; 60 80 Emin = Ef - 10*kT; 61 81 Emax = Ef + 10*kT; … … 72 92 } 73 93 74 // do it the easy way,75 // create a plot to add to the library76 // p lot is registered with lib upon object creation77 // p 1.add(nPts,xArr,yArr,format,name);94 // store results in the results table 95 // add data to the table pointed to by the variable result. 96 // put the fArr data in the column named "Fermi-Dirac Factor" 97 // put the EArr data in the column named "Energy" 78 98 79 Rappture::Plot p1(lib); 80 p1.add(nPts,fArr,EArr,"","fdfactor"); 81 p1.propstr("label","Fermi-Dirac Curve"); 82 p1.propstr("desc","Plot of Fermi-Dirac Calculation"); 83 p1.propstr("xlabel","Fermi-Dirac Factor"); 84 p1.propstr("ylabel","Energy"); 85 p1.propstr("yunits","eV"); 99 result->addData("Fermi-Dirac Factor",nPts,fArr); 100 result->addData("Energy",nPts,EArr); 86 101 87 lib.result(); 102 // close the global interface 103 // signal to the graphical user interface that science 104 // calculations are complete and to display the data 105 // as described in the views 106 Rappture::Interface::close(); 88 107 89 108 return 0; -
trunk/examples/objects/app-fermi/matlab/fermi4.m
r1615 r1620 13 13 % ====================================================================== 14 14 15 % get out input file from the command line 16 % invoke this script with the following command: 17 % matlab -nodisplay -r infile=\'driver1234.xml\',fermi 18 % the above command sets variable infile to the name 'driver1234.xml' 15 function fermi4(argv) 19 16 20 % infile = 'driver31619.xml' 17 % declare variables to interact with Rappture 18 T = 0.0; 19 Ef = 0.0; 20 result = 0; 21 21 22 % open our xml input file. 23 lib = Rp_LibraryInit(); 24 Rp_LibraryLoadFile(lib, infile); 22 % declare program variables 23 E = 0.0; 24 dE = 0.0; 25 kT = 0.0; 26 Emin = 0.0; 27 Emax = 0.0; 28 f = 0.0; 29 nPts = 200; 25 30 26 nPts = 200; 31 % initialize the global interface 32 Rp_InterfaceInit(argv,@fermi_io); 27 33 28 if (Rp_LibraryError(lib) != 0)) { 29 % cannot open file or out of memory 30 o = Rp_LibraryOutcome(lib); 31 fprintf(stderr, '%s', Rp_LibraryContext(o)); 32 fprintf(stderr, '%s', Rp_LibraryRemark(o)); 33 return; 34 % check that global interface for errors 35 if (Rp_InterfaceError() != 0)) { 36 % there were errors while setting up the interface 37 % dump the traceback 38 o = Rp_InterfaceOutcome(); 39 fprintf(2, '%s', Rp_OutcomeContext(o)); 40 fprintf(2, '%s', Rp_OutcomeRemark(o)); 41 return(Rp_InterfaceError()); 34 42 } 35 43 36 T = Rp_Connect(lib,'temperature'); 37 Ef = Rp_LibraryValue(lib,'Ef','units=eV'); 44 % connect variables to the interface 45 % look in the global interface for an object named 46 % 'temperature', convert its value to Kelvin, and 47 % store the value into the variable T. 48 % look in the global interface for an object named 49 % 'Ef', convert its value to electron Volts and store 50 % the value into the variable Ef. 51 % look in the global interface for an object named 52 % factorsTable and store a handle to it in the 53 % variable result. 38 54 39 if (Rp_LibraryError(lib) != 0) { 55 T = Rp_InterfaceConnect('temperature','units=K') 56 Ef = Rp_InterfaceConnect('Ef','units=eV') 57 result = Rp_InterfaceConnect('factorsTable') 58 59 % check the global interface for errors 60 if (Rp_InterfaceError() != 0) { 40 61 % there were errors while retrieving input data values 41 62 % dump the tracepack 42 o = Rp_ LibraryOutcome(lib);43 fprintf(stderr, '%s', Rp_ LibraryContext(o));44 fprintf(stderr, '%s', Rp_ LibraryRemark(o));45 return ;63 o = Rp_InterfaceOutcome(); 64 fprintf(stderr, '%s', Rp_OutcomeContext(o)); 65 fprintf(stderr, '%s', Rp_OutcomeRemark(o)); 66 return(Rp_InterfaceError()); 46 67 } 47 68 48 69 % do fermi calculations (science)... 49 kT = 8.61734e-5 * Rp_NumberValue(T,'K');50 Emin = Ef - 10*kT;51 Emax = Ef + 10*kT;70 kT = 8.61734e-5 * T; 71 Emin = Ef - (10*kT); 72 Emax = Ef + (10*kT); 52 73 53 74 EArr = linspace(Emin,Emax,nPts); 54 75 fArr = 1.0 ./ (1.0 + exp((EArr - Ef)/kT)); 55 76 56 % do it the easy way,57 % create a plot to add to the library58 % p lot is registered with lib upon object creation59 % p 1->add(nPts,xArr,yArr,format,name);77 % store results in the results table 78 % add data to the table pointed to by the variable result 79 % put the fArr data in the column named 'Fermi-Dirac Factor' 80 % put the EArr data in the column named 'Energy' 60 81 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'); 82 Rp_TableAddData(result,'Fermi-Dirac Factor',fArr); 83 Rp_TableAddData(result,'Energy',EArr); 68 84 69 Rp_LibraryResult(lib); 85 % close the global interface 86 % signal to the graphical user interface that science 87 % calculations are complete and to display the data 88 % as described in the views 70 89 71 return; 90 Rp_InterfaceClose(); 91 92 return 0; -
trunk/examples/objects/app-fermi/python/fermi4.py
r1615 r1620 21 21 from math import * 22 22 23 from fermi_io import fermi_io 23 24 24 25 def help(argv=sys.argv): … … 34 35 def main(argv=None): 35 36 36 if argv is None: 37 argv = sys.argv 37 # declare variables to interact with Rappture 38 T = 0.0 39 Ef = 0.0 38 40 39 if len(argv) < 1: 40 msg = "%(prog)s requires at least 0 argument" % {'prog':argv[0]} 41 print >>sys.stderr, msg 42 print >>sys.stderr, help() 43 return 2 44 45 longOpts = ["help"] 46 shortOpts = "h" 47 try: 48 opts,args = getopt.getopt(argv[1:],shortOpts,longOpts) 49 except getopt.GetOptError, msg: 50 print >>sys.stderr, msg 51 print >>sys.stderr, help() 52 return 2 53 54 55 56 # create a rappture library from the file filePath 57 lib = Rappture.Library() 58 41 # declare program variables 59 42 nPts = 200; 60 43 EArr = list() # [nPts] 61 44 fArr = list() # [nPts] 62 45 63 lib.loadFile(sys.argv[1]) 64 if (lib.error() != 0) { 65 # cannot open file or out of memory 66 o = lib.outcome() 46 # initialize the global interface 47 Rappture.Interface(sys.argv,fermi_io) 48 49 # check the global interface for errors 50 if (Rappture.Interface.error() != 0) { 51 # there were errors while setting up the interface 52 # dump the traceback 53 o = Rappture.Interface.outcome() 67 54 print >>sys.stderr, "%s", o.context() 68 55 print >>sys.stderr, "%s", o.remark() 69 return ( lib.error());56 return (Rappture.Interface.error()) 70 57 } 71 58 72 T = Rappture.Connect(lib,"temperature") 73 Ef = lib.value("Ef","units=eV") 59 # connect variables to the interface 60 # look in the global interface for an object named 61 # "temperature", convert its value to Kelvin, and 62 # store the value into the address of T. 63 # look in the global interface for an object named 64 # "Ef", convert its value to electron Volts and store 65 # the value into the address of Ef 66 # look in the global interface for an object named 67 # factorsTable and set the variable result to 68 # point to it. 74 69 75 if (lib.error() != 0) { 70 T = Rappture.Interface.connect(name="temperature", 71 hints=["units=K"]) 72 Ef = Rappture.Interface.connect(name="Ef", 73 hints=["units=eV"]); 74 result = Rappture.Interface.connect(name="factorsTable"); 75 76 # check the global interface for errors 77 if (Rappture.Interface.error() != 0) { 76 78 # there were errors while retrieving input data values 77 79 # dump the tracepack 78 o = lib.outcome()80 o = Rappture.Interface.outcome() 79 81 print >>sys.stderr, "%s", o.context() 80 82 print >>sys.stderr, "%s", o.remark() 81 return ( lib.error())83 return (Rappture.Interface.error()) 82 84 } 83 85 84 kT = 8.61734e-5 * T.value("K") 85 Emin = Ef - 10*kT 86 Emax = Ef + 10*kT 86 # do science calculations 87 kT = 8.61734e-5 * T 88 Emin = Ef - (10*kT) 89 Emax = Ef + (10*kT) 87 90 88 91 dE = (1.0/nPts)*(Emax-Emin) … … 97 100 } 98 101 99 # do it the easy way,100 # create a plot to add to the library101 # p lot is registered with lib upon object creation102 # p 1->add(nPts,xArr,yArr,format,name);102 # store results in the results table 103 # add data to the table pointed to by the variable result. 104 # put the fArr data in the column named "Fermi-Dirac Factor" 105 # put the EArr data in the column named "Energy" 103 106 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 result.addData(name="Fermi-Dirac Factor",data=fArr) 108 result.addData(name="Energy",data=EArr) 111 109 112 lib.result() 110 # close the global interface 111 # signal to the graphical user interface that science 112 # calculations are complete and to display the data 113 # as described in the views 114 Rappture.Interface.close() 113 115 114 116 return 0 115 }116 117 117 118 118 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.