1 Rappture with C and Fortran Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration This work licensed under Creative Commons.

Slides:



Advertisements
Similar presentations
Slicer3 for developers – Sonia Pujol, Ph.D. -1- National Alliance for Medical Image Computing Programming into Slicer3 Sonia Pujol, Ph.D. Surgical Planning.
Advertisements

CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
CSC241 Object-Oriented Programming (OOP) Lecture No. 9.
Adding Rappture to MATLAB Applications
Review of Scientific Programming in C and Fortran Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
1 What’s Under the Hood? Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See.
Using workspaces on nanoHUB.org Michael McLennan Software Architect Network for Computational Nanotechnology.
Rappture with C and Fortran Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
C Primer CAS CS210 Ying Ye Boston University. Outline Hello, world Basics in C Comparison of C and Java.
Exercise 10 Review: pointers, strings and recursion.
1 Using Workspaces to Develop Simulation Tools Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration This work licensed under.
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
1 Uploading and Publishing New Tools Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration This work licensed under Creative.
1 More Rappture Objects Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration This work licensed under Creative Commons See.
CS470/570 Lecture 5 Introduction to OpenMP Compute Pi example OpenMP directives and options.
Initialization of Clang
University of Calgary – CPSC 441. C PROGRAM  Collection of functions  One function “main()” is called by the operating system as the starting function.
1 More Rappture Objects Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See.
GNU gcov (1/4) [from Wikipedia] gcov is a source code coverage analysis and statement- by-statement profiling tool. gcov generates exact counts of the.
Strlen() implementation /* strlen : return length of string s */ int strlen(char *s) { int n; for (n = 0 ; s[n] != ‘\0’ ; n++) ; return n; } /* strlen.
Regression Testing Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See license.
LINUX Tuesday, 5 July :00 pm. Remote Login l Use Secure Shell (ssh) l Machine name/IP address E.g. ssh hydra.sma.nus.edu.sg Or ssh
1 Advanced Visualization Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See.
Week 2 - Friday.  What did we talk about last time?  Base systems  C literals  Representations in memory.
Advanced Rappture Concepts and Tips Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
Lecture 3: Getting Started & Input / Output (I/O) “TRON” Copyright 1982 (Walt Disney Productions)
Introducing the Rappture Toolkit Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
1 Introducing the Rappture Toolkit Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative.
What’s Under the Hood? Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See.
1 CSC2100B Data Structure Tutorial 1 Online Judge and C.
C. C ? K & R C – The Kernighan and Richie classic ANCI C -- started 1983 – ANSI X and ISO/IEC 9899:1990 – Standard C, C89, C90 C90 –
Using Simulation Workspaces Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University 1 This work licensed under Creative Commons.
1 Introducing the Rappture Toolkit Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration This work licensed under Creative.
CSCI 330 UNIX and Network Programming
CS429 Computer Architecture Topics Simple C program Basic structure, functions, separate files Compilation Phases, options Assembler GNU style, byte ordering,
3/12/2013Computer Engg, IIT(BHU)1 MPI-1. MESSAGE PASSING INTERFACE A message passing library specification Extended message-passing model Not a language.
Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008.
Multi-dimensional Arrays and other Array Oddities Rudra Dutta CSC Spring 2007, Section 001.
1 Regression Testing Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See license.
Advanced Visualization Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See.
ZyBooks /12/16. Exam I 2/19/16 Review next week.
Week 4 – Functions Coding Functions. Purpose of Coding Functions A function is written to perform a well-defined task; rather than having all logic in.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
OPERATING SYSTEMS COURSE THE HEBREW UNIVERSITY SPRING FUSE File System.
Using Subversion for Source Code Control Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Rappture with Fortran Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See license.
Lecture 3: Getting Started & Input / Output (I/O)
Eclipse.
Arithmetic Expressions
Using simulation workspaces to “submit” jobs and workflows
A bit of C programming Lecture 3 Uli Raich.
Command Line Arguments
Command line arguments
Agenda Make Utility Command Line Arguments in Unix
CS 201 A Whirlwind Tour of C Programming
C Stuff CS 2308.
Program Control Structures
GNU gcov (1/4) [from Wikipedia]
The Designer.
sscanf()- string scan function
GNU gcov (1/4) [from Wikipedia]
ENERGY 211 / CME 211 Lecture 28 December 1, 2008.
Administrative things
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
SPL – PS1 Introduction to C++.
Presentation transcript:

1 Rappture with C and Fortran Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration This work licensed under Creative Commons See license online: by-nc-sa/3.0

2 tool.xml Example: app-fermi executable Rappture GUI Press Simulate to … … Press Simulate to … … See example codeexample code

3 tool.xml Example: app-fermi Rappture GUI executable #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; } #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; }

4 #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; } #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; } Starting Point fermi.c (simulator written in C) Input Output Physics

5 #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; } #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; } Starting Point fermi.c (simulator written in C) Input Output Physics

6 Rappture Inputs fermi.c (simulator written in C) #include "rappture.h" #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; int err; RpLibrary *lib; const char* data; lib = rpLibrary(argv[1]); rpGetString(lib,"input.(temperature).current",&data); T = rpConvertDbl(data, "K", &err); rpGetString(lib,"input.(Ef).current",&data); Ef = rpConvertDbl(data, "eV", &err); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; … #include "rappture.h" #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; int err; RpLibrary *lib; const char* data; lib = rpLibrary(argv[1]); rpGetString(lib,"input.(temperature).current",&data); T = rpConvertDbl(data, "K", &err); rpGetString(lib,"input.(Ef).current",&data); Ef = rpConvertDbl(data, "eV", &err); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; … “72F” … … 72F … … … 72F …

7 Rappture Inputs fermi.c (simulator written in C) #include "rappture.h" #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; int err; RpLibrary *lib; const char* data; lib = rpLibrary(argv[1]); rpGetString(lib,"input.(temperature).current",&data); T = rpConvertDbl(data, "K", &err); rpGetString(lib,"input.(Ef).current",&data); Ef = rpConvertDbl(data, "eV", &err); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; … #include "rappture.h" #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; int err; RpLibrary *lib; const char* data; lib = rpLibrary(argv[1]); rpGetString(lib,"input.(temperature).current",&data); T = rpConvertDbl(data, "K", &err); rpGetString(lib,"input.(Ef).current",&data); Ef = rpConvertDbl(data, "eV", &err); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; … “2.4eV” 2.4 “72F”

8 Rappture Outputs fermi.c (simulator written in C) … E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); sprintf(line,"%f %f\n",f, E); rpPutString(lib,"output.curve(f12).component.xy", line, RPLIB_APPEND); E = E + dE; } rpResult(lib); return 0; } … E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); sprintf(line,"%f %f\n",f, E); rpPutString(lib,"output.curve(f12).component.xy", line, RPLIB_APPEND); E = E + dE; } rpResult(lib); return 0; } “x y \n” … … … …

9 Compiling the Rappturized Code From your workspace... % cd tooldir % ls tool.xml fermi.c % gcc -g fermi.c –o fermi –I/apps/rappture/current/include –L/apps/rappture/current/lib –lrappture -lm % ls tool.xml fermi.c fermi % rappture % cd tooldir % ls tool.xml fermi.c % gcc -g fermi.c –o fermi –I/apps/rappture/current/include –L/apps/rappture/current/lib –lrappture -lm % ls tool.xml fermi.c fermi % rappture

10 How does the program get invoked? tool.xml Press Simulate to … … Press Simulate to … … Replaced with name of driver file Ex: driver327.xml Replaced with directory containing tool.xml file Ex: /apps/yourtool/current Invoke the C program… …with the driver file as the first argument

11 How does the program get /apps/yourtool/current/fermi driver327.xml #include "rappture.h" … int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; RpLibrary *lib; const char* data; lib = rpLibrary(argv[1]); … rpResult(lib); return 0; }

12 Not Much Overhead It’s easy to add Rappture to your new tools: Fermi Level eV 0eV Fermi Level eV 0eV Instead of this…Do this… Documentation scanf("%lg",&Ef); rpGetString(lib, path, &data); Ef = rpConvertDbl(data, “eV", &err); rpGetString(lib, path, &data); Ef = rpConvertDbl(data, “eV", &err); printf(“%g”,Ef); rpPutString(lib, path, val, RPLIB_APPEND); … rpResult(lib); rpPutString(lib, path, val, RPLIB_APPEND); … rpResult(lib);

13 tool.xml Example: app-fermi Rappture GUI executable program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi

14 Starting Point fermi.f (simulator written in Fortran) program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi Input Output Physics

15 Starting Point fermi.f (simulator written in Fortran) program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi Input Output Physics

16 Rappture Inputs fermi.f (simulator written in Fortran) program fermi … call getarg(1,inFile) driver = rp_lib(inFile) call rp_lib_get(driver, + "input.number(temperature).current“, str) okay = rp_units_convert_dbl(str, “K”, T) call rp_lib_get(driver, + "input.number(Ef).current“, str) okay = rp_units_convert_dbl(str, “eV”, Ef) kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) … program fermi … call getarg(1,inFile) driver = rp_lib(inFile) call rp_lib_get(driver, + "input.number(temperature).current“, str) okay = rp_units_convert_dbl(str, “K”, T) call rp_lib_get(driver, + "input.number(Ef).current“, str) okay = rp_units_convert_dbl(str, “eV”, Ef) kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) … “72F” “2.4eV” 2.4

17 Rappture Outputs fermi.f (simulator written in Fortran) … dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(xy,'(E20.12, F13.9, A)') f, E, char(10) call rp_lib_put_str(driver, + "output.curve(f12).component.xy", xy, 1) 10 continue call rp_result(driver) end program fermi … dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(xy,'(E20.12, F13.9, A)') f, E, char(10) call rp_lib_put_str(driver, + "output.curve(f12).component.xy", xy, 1) 10 continue call rp_result(driver) end program fermi “x y \n”

18 Compiling the Rappturized Code % cd tooldir % ls tool.xml fermi.f % g77 -g fermi.f –o fermi –L/apps/rappture/current/lib –lrappture % ls tool.xml fermi.f fermi % rappture % cd tooldir % ls tool.xml fermi.f % g77 -g fermi.f –o fermi –L/apps/rappture/current/lib –lrappture % ls tool.xml fermi.f fermi % rappture From your workspace...

19 Reference Documentation Documentation Rappture-C/C++ API Rappture-Fortran API Examples: app-fermi in C app-fermi in Fortran

20 Exercise #3: Build a Spirograph Program #include int main(int argc, char **argv) { double n1, n2, n3, t; double complex z; printf("Enter value: n1 = "); scanf("%lg", &n1); printf("Enter value: n2 = "); scanf("%lg", &n2); printf("Enter value: n3 = "); scanf("%lg", &n3); for (t=0.0; t < 1.0; t += 0.001) { z = cexp(I*2*M_PI*n1*t) + cexp(I*2*M_PI*n2*t) + cexp(I*2*M_PI*n3*t); printf("%g %g\n", creal(z), cimag(z)); } return 0; } #include int main(int argc, char **argv) { double n1, n2, n3, t; double complex z; printf("Enter value: n1 = "); scanf("%lg", &n1); printf("Enter value: n2 = "); scanf("%lg", &n2); printf("Enter value: n3 = "); scanf("%lg", &n3); for (t=0.0; t < 1.0; t += 0.001) { z = cexp(I*2*M_PI*n1*t) + cexp(I*2*M_PI*n2*t) + cexp(I*2*M_PI*n3*t); printf("%g %g\n", creal(z), cimag(z)); } return 0; } n 1 = 13 n 2 = -7 n 3 = -3 n 1 = 19 n 2 = -13 n 3 = 3 n 1 = 7 n 2 = -5 n 3 = 2 Try these values: Download assignment: ex3.zip