2.2 Rappture with C and Fortran

Video thumbnail (Frame 0) Video thumbnail (Frame 2542) Video thumbnail (Frame 5248) Video thumbnail (Frame 6427) Video thumbnail (Frame 10354) Video thumbnail (Frame 15106) Video thumbnail (Frame 17485) Video thumbnail (Frame 18699) Video thumbnail (Frame 21708) Video thumbnail (Frame 23828) Video thumbnail (Frame 24745) Video thumbnail (Frame 26581) Video thumbnail (Frame 27859) Video thumbnail (Frame 29921) Video thumbnail (Frame 31245) Video thumbnail (Frame 32927) Video thumbnail (Frame 38363) Video thumbnail (Frame 39711) Video thumbnail (Frame 42393) Video thumbnail (Frame 43900) Video thumbnail (Frame 50855) Video thumbnail (Frame 51969) Video thumbnail (Frame 53211) Video thumbnail (Frame 56330) Video thumbnail (Frame 57488) Video thumbnail (Frame 58584) Video thumbnail (Frame 60999) Video thumbnail (Frame 63899)
Video in TIB AV-Portal: 2.2 Rappture with C and Fortran

Formal Metadata

2.2 Rappture with C and Fortran
Title of Series
Part Number
Number of Parts
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
00:09 Review of Scientific Programming in C and Fortran 00:33 Monte Carlo Simulator 03:08 Plinko Simulator in C 05:59 Plinko Simulator in C 09:57 Plinko Simulator in C 11:49 Plinko Simulator in C 14:56 Plinko Simulator in C 18:12 Compiling and Running C Code 21:02 C Language Cheat Sheet 23:30 Plinko Simulator in Fortran 28:59 Plinko Simulator in Fortran 31:29 Plinko Simulator in Fortran 33:52 Fortran Cheat Sheet 35:33 Compiling and Running Fortran Code 37:12 Makefiles 41:25 Debugging 43:16 Debugging 44:40 Debugging 45:49 Assignment #5: Simple C or Fortran Program
Point (geometry) Source code Simulation Sequel Computer file Sheaf (mathematics) Directory service Function (mathematics) Number Formal language Compiler Type theory Programmer (hardware) Radical (chemistry) Finite element method Computer animation Computer programming Internet forum output Energy level Right angle
Greatest element Game controller Building Computer file Range (statistics) Letterpress printing First-order logic Function (mathematics) Parameter (computer programming) Plastikkarte Food energy Arm Emulation Variance Formal language Neuroinformatik Revision control Goodness of fit Mathematics Different (Kate Ryan album) Computer programming Object-oriented programming Functional programming Computer-assisted translation Summierbarkeit Arc (geometry) Curve Twin prime Interface (computing) Computer program Electronic mailing list Physicalism Food energy Machine code Formal language Boltzmann constant Number Computer animation Personal digital assistant Calculation Octave Interface (computing) Statement (computer science) Physics output Right angle
Building Ferry Corsten Multiplication sign Source code Sheaf (mathematics) Parameter (computer programming) Machine code Formal language Programmer (hardware) Different (Kate Ryan album) Moving average Drum memory Arc (geometry) Exception handling Curve Electric generator Structural load Interior (topology) Skeleton (computer programming) Type theory Arithmetic mean Vector space Right angle Curve fitting Resultant Point (geometry) Mobile app Random number generation Computer file Maxima and minima Device driver Emulation Number Revision control Computer programming Computer-assisted translation Poisson-Klammer Computer program Exponential function Directory service Machine code Line (geometry) Device driver Sphere System call Compiler Word Computer animation Intrusion detection system Personal digital assistant Statement (computer science) Physics Library (computing)
Game controller Greatest element Mass flow rate Computer file Multiplication sign Execution unit Letterpress printing Parameter (computer programming) Mereology Food energy Formal language Revision control Goodness of fit Mathematics String (computer science) Computer programming Data conversion Form (programming) Curve Overhead (computing) Standard deviation Shift operator Touchscreen Computer program Physicalism Food energy Machine code Degree (graph theory) Number Benutzerhandbuch Computer animation Revision control Resultant
Personal identification number Computer file State of matter Multiplication sign Maxima and minima Device driver Machine code Formal language Array data structure Computer programming Moving average Drum memory Interface (computing) Computer program Graphische Programmierung Machine code Directory service Control flow Device driver Formal language Skeleton (computer programming) Computer animation Interface (computing) Physics Figurate number Resultant Library (computing)
Computer file Ferry Corsten Execution unit Device driver Parameter (computer programming) Subset Wave packet Formal language Different (Kate Ryan album) Term (mathematics) Computer programming Functional programming Data conversion Overhead (computing) Structural load Weight Computer program Parameter (computer programming) Machine code Device driver System call Equivalence relation Radical (chemistry) Computer animation String (computer science) Network topology Normed vector space output Resultant
Point (geometry) Histogram Wage labour Java applet Multiplication sign Execution unit Function (mathematics) Formal language Wave packet Word Computer programming String (computer science) Functional programming Histogram Interface (computing) Computer program System call Type theory Number Explosion Process (computing) Computer animation String (computer science) Function (mathematics) Interface (computing) output Arithmetic progression
Axiom of choice Web page Point (geometry) Histogram Sheaf (mathematics) Parameter (computer programming) Drop (liquid) Mereology Variance Element (mathematics) Formal language Number Computer configuration Different (Kate Ryan album) Term (mathematics) String (computer science) Green's function Curve Execution unit Counting Bit Line (geometry) Machine code Word Computer animation Personal digital assistant Interface (computing) Normal (geometry) Point cloud Figurate number
Histogram Building Computer file Common Information Model (computing) Execution unit Maxima and minima Function (mathematics) Number Formal language Word Computer configuration Computer programming String (computer science) Integer Metropolitan area network Descriptive statistics Area Histogram Metropolitan area network Default (computer science) Execution unit Interface (computing) Computer program Counting Machine code Line (geometry) Cartesian coordinate system System call Skeleton (computer programming) Type theory Number Word Explosion Process (computing) Computer animation Personal digital assistant String (computer science) Function (mathematics) Uniform resource name Interface (computing) output Right angle Maß <Mathematik> Spacetime Wide area network
Metropolitan area network MUD Computer file Online help Directory service Machine code Infinity Cartesian coordinate system Disk read-and-write head Emulation Number Skeleton (computer programming) Word Computer animation Computer programming Interface (computing) Hill differential equation Arithmetic progression Identity management Resultant Descriptive statistics Newton's law of universal gravitation
Greatest element MIDI Maxima and minima Function (mathematics) Ordinary differential equation Mereology Law of large numbers Value-added network Degree (graph theory) Declarative programming Uniformer Raum Computer programming Core dump Moving average Physical law Ranking Lipschitz-Stetigkeit Summierbarkeit Conditional-access module Compilation album Area Metropolitan area network Raw image format Information management NP-hard Interior (topology) Menu (computing) Bit Line (geometry) Machine code Modulare Programmierung Type theory Software development kit Computer animation Uniform resource name Interface (computing) output Convex hull Pattern language Quicksort
Software engineering Greatest element Multiplication sign Maxima and minima Function (mathematics) Dynamic random-access memory Mereology Bit Formal language Word Exploratory data analysis Mathematics Causality Arithmetic mean String (computer science) Computer programming Operator (mathematics) Intelligent Network Execution unit Standard deviation Touchscreen Poisson-Klammer Data storage device Bit Machine code Line (geometry) System call Type theory Software development kit Fermat's Last Theorem Pointer (computer programming) Loop (music) Computer animation Personal digital assistant Interface (computing) Statement (computer science) output Resultant
Histogram Greatest element Clique-width Multiplication sign Parameter (computer programming) Mereology Number String (computer science) Motion blur Cuboid Summierbarkeit Metropolitan area network Rule of inference Interior (topology) Counting Bit Line (geometry) Machine code Annulus (mathematics) Loop (music) Malware Computer animation Doubling the cube Uniform resource name Internet forum Interface (computing) Hill differential equation Procedural programming
Metropolitan area network Building Histogram Computer animation Different (Kate Ryan album) Computer programming Interface (computing) Value-added network
Point (geometry) Histogram Mapping Multiplication sign Sheaf (mathematics) Letterpress printing First-order logic Function (mathematics) Special unitary group Number Mathematics Casting (performing arts) Radio-frequency identification Insertion loss String (computer science) Motion blur Integer Addressing mode Arc (geometry) Metropolitan area network Raw image format Execution unit Counting Bit Modulare Programmierung Arithmetic mean Word Message passing Loop (music) Malware Computer animation Uniform resource name Interface (computing) Statement (computer science) Arithmetic progression
Metropolitan area network Information management Personal identification number MUD Multiplication sign Simultaneous localization and mapping Maxima and minima Parameter (computer programming) Line (geometry) Function (mathematics) Infinity Complete metric space Arm Storage area network Emulation Message passing Word Declarative programming Computer animation Causality Internet forum Interface (computing) Right angle Arithmetic progression
Ocean current Application service provider Statistics MUD Mapping Computer file Mountain pass Maxima and minima Device driver Limit (category theory) Function (mathematics) Special unitary group Arm Value-added network Number Usability Duality (mathematics) Computer programming String (computer science) Drill commands Software testing Arithmetic logic unit Summierbarkeit Newton's law of universal gravitation Metropolitan area network Maximum length sequence Execution unit Interior (topology) Menu (computing) Euler angles Variable (mathematics) Complete metric space Rothe-Verfahren Inclusion map CAN bus Arithmetic mean Word Message passing Error message Computer animation Uniform resource name Interface (computing) Personal area network Right angle Arithmetic progression Wide area network
Dialect Group action Computer file Mountain pass Weight Simultaneous localization and mapping Artificial neural network Letterpress printing 3 (number) Device driver Hand fan Variance Emulation Number Coefficient of determination Computer programming Musical ensemble Row (database) Addressing mode Summierbarkeit Hydraulic jump Metropolitan area network Execution unit Structural load Debugger Interior (topology) Counting Coma Berenices 3 (number) Line (geometry) Word Computer animation Internet forum Interface (computing) Inference Convex hull Hill differential equation Right angle Very long instruction word Resultant
Metropolitan area network MUD Interface (computing) Computer-aided design Coma Berenices Letterpress printing Computer animation Hooking Uniform resource name Computer programming Internet forum Interface (computing) Hill differential equation Right angle Summierbarkeit Wireless Markup Language
all I about online simulation and more work for technology so in the next
section we're gonna take everything you learned about C and Fortran and put it together with rapture so now if someone hands you a C programmer Fortran programs and says make it look pretty put up a new you can do it because you got rapture and you're all set so let's take an example program kind like the 1 that you guys just used in the lab assignment this was a fairly program that I've used before but it pretty much the same thing if I if I have a fairly program at 1st of all you know I got a compiler and probably I should make myself a file and once side compiled that I can write it like that and the last me something like that of the Fermi level and I'll put in a value 2 point 4 and last before for the temperature and output in a value like 77 and then the very program although in right it's staying and produce output file and if I looked at the output file it would give me a bunch of numbers right so that's the way most C language programs are written but so we might remember way back when I told you about my sequel program was written in Fortran was a lot like this the in some values and you get out some data now enraptured we can make it look a whole lot this year because instead of prompting the user to type in things on the terminal we can give them inputs and then we can give them outputs just like the Matlab example that we saw yesterday right and again this is in the if you look in the rapture examples directory there's that very and there's a C-language directory of Fortran directory and you can see all of the different languages trash right so here is my C
language version of the Fermi function calculator and you that might be getting that kind of eerie sense of deja vu because a lot of this 1st of all looks like the ceiling which we just been doing and 2nd of all it looks like the the Fermi function we saw yesterday in Matlab very similar so like any good C-language program it starts out with some pound includes it's got a mean program and all that there's a press statement a scanner statement here and that corresponds to this control right in the C-language program we we say and the Fermi energy and we you stand after reading a value that sorta like that control that we have in rapture and this other print f and others can have is just like that control that we use for the temperature and this stuff down at the bottom which prints out values for the curve but that's just like the curve object enrapture so just like we saw yesterday there's some good stuff and there some output stuff and then there's some stuff in the middle that does all the real work the stuff in the middle is all the physics code where here were computing of using the Boltzmann constant to figure out the energy spread and we're going through a list of energy ranges were actually computing the function f in a while and so that's really the the meat of of my program so whatever you're starting a program like this you shall these Iast yourself what are the inputs what are the outputs and they take those inputs and outputs and map it onto rapture interface you notice in this case the inputs and the outputs in the interface that we get are identical to the Matlab thing we saw yesterday the identical the interface want when you're running the program on on all of you actually would wouldn't be able to tell whether it was a C-language a Matlab a Fortran under the hood it all looks the same right
so if we were going to go in and just like we did yesterday we were going to go in and create this interface and the builder we drag and drop all the controls over or actually I could just use the tool . XML but I have for the Matlab version but the difference is that the bottom if I go into the tool interface there's a of parameter the bottom for program instead of saying matlab or Octave there were set C language so I'm just gonna change the language there and then we go to say if we can save skeleton program in see and we can save a Makefile may the builder of build Makefile for you so you guys all have a file you want to create a a and make sure you save those because otherwise there's a lot more code for you right so here's the
generated program raptures hemisphere out the skeleton program that already has all the statements forgetting the number in the you know the temperature in the EDF and all that and there's a piece in there where it says add your code here right so what we do is we take the mean of our program and stick it in right words as edges code here that's the needed the program and all we have to do is connected up again we have if we have a variable called temperature but in my code called the T I need to stay those 2 things up and if we have these vectors f and that are generated by the program but rapture call them X and Y and heat sink those 2 things up so just like yesterday and you get that eerie sense of deja vu with the Matlab program except it's a slightly different language syntax is all but just like yesterday we did this trash so here's my Finnish programmer plugged in the code and are pretty much left alone but I just plug in the F. and E. and stuff like that but now rapture generated the Makefile for me so I can use that Make file you notice when I say make it a lot more complicated here it's good to have rapture generate Makefile for it because rapture has libraries all this other gobbledy-gook you guys would have to put in the dash I International and you'd be like while I know that and the answer is you don't tell me what rapture generate the Makefile for you and you put all the libraries in place and so every time you say make it compiler with the right libraries and now if we look in the directory will see the Makefile the rapture generated will see the tool that XML that we got the builder we see may not see we just added that and now that we did make this a program called graphical that means and so that means the version of the program that's been compiled and I can type rapture and just like before rupturing the tool that XML right I put in my values for the temperature in India have and when I click simulate it produces a driver file which is an exact copy of told that XML but with the current values it'll run my program execute my code and then spit out a run file and remember the run file is just like the driver file except it has all the results shown there just like we learned yesterday the only difference is that mean program now is written in C but everything works the same way rapture loads of my curve and it was so it won't run filing member we talked yesterday the run file was in your data results directory so this was the way that now
it's a little different if you look inside the tool that XML and how the program gets invoked we looked at this yesterday to the command section of the tool that XML still uses the actual and still uses the @ driver just a little different from yesterday in this case we wanna run the executable means see where is mean is in the same directory right now as you're told on XML so I can say act Tools slash means see if it's 1 directory up and over here then I can say at Tools slash dot art slashed the slashed whatever you give it whatever path you want that works in Unix but always relative to actual actual is where your tool that XML is you can figure out where everything else is relative to the tool that XML so in this case I'll keep it simple means he's right there with the tool that XML source they actually means the and then the 1st argument on the command line is the driver file that driver that right raptures could expand that out wherever you tool happens to be you know I I don't find in this point well enough yesterday you may have had a few guys ever done this before you may have a program that's running it works great for you and then you tell someone else you take it you compile it you use it you put up on nanoHUB you install it and all of a sudden when it comes and goes to somebody else's directory doesn't work anymore why because they're hard coded paths in your program and hard-coded paths in various places and it's also up to work in your directory but on someone else's directory see that's the reason why we do all this actually that driver stuff rapture so that the tool can be can plug it down anywhere and everything works because everything's relative to the tool that XML so when you're tool installed on nanoHUB it will actually go into a directory like slash apps slash whatever the name your tool is slashed current and so forth so what would you have to know that the point is by using actual it works no matter where you drop all that code and build and that's why we do the actual things because we don't want any hard-coded passed in your program that right now inside the main program if you look at the code the rapture generated in the main program 1 of the 1st things it does is it opens up API library with our bracket 1 hardly bracket 1 is the 1st argument on the command line and that the minimum my driver file 1st argument on the command line and again I'll have a random number you have no you just say at driver so it'll it'll take the file little open it will do its thing and then again at the very end make sure you call all the API results in a new exit with a status code of 0 if you forget if you don't call API result or if somehow in the massive of craziness of debugging you delete that line of the program then if you never call result rapture will get a run file it'll be like what's up no run file or if you don't except with a status code of 0 hour after will say you program failed must have failed because it had a non 0 X the status code so rapture will just say your programs no good but failed so you gotta make sure you do those 2 things you file exhibitors 0 status code that means you're going to buy so
that you can kind of think of it like this when you think about you know I can show you all this you like while is a lot of stuff there with rapture but really think of it like this when you write a program instead of writing a bunch of documentation which is like your user guide and the user manual reference manual tutorial examples all that instead of doing all that the old fashioned way is to create a tool that XML file that really has that stuff and that right you don't need user guide if you have tooltips on your tool in of the tool has good documentation kind explains what it does so you're you're documentation now becomes embedded in the tool in the form of the stuff you put into the tool that XML so instead of writing a lot of documentation just build a good tool that XML instead of calling stand after get parameters and from standard and you do the rapture things rapture thing is I've got a control I can get a string Raftery but has no API convert double that will do unit conversion that's even 1 step better because instead of telling the user you have to give me the temperature in degrees Kelvin the user can put in degrees Fahrenheit or whatever they wanted to and natural to units conversion just like that instead of printing stuff out on the screen at the end you just do the API put string and the API results stuff that we saw earlier so it's really 1 for 1 you know instead of wasting your time on documentation writing preference can have you can just use the tool that XML file and the stuff that's kind of built into rapturous all equivalent it's all the same thing the rest your program stays the same that was the
C language version let's shift gears and I'll show you the Fortran version and used by the time I'm done with this you're going to be crying uncle because you be like my gosh I've seen the same thing so many times in all these different languages I get I get I'm really hoping that be saying I get I get don't tell me again so in my Fortran programs have a part where I'm asking the person and the energy in the that's just like that control and the replace this code with that control and all this stuff at the bottom the print stuff out and then use a curve instead of in the middle of got my physics code and then a unique that out of the program and put it in my rapture program right just like the C language was and again the tool that XML is identical 1 change in the
tool that XML for bringing up in the builder I change the language here to Fortran 77 so if I change the language in the builder that I can say that
out in member you just like before I can say that is a file and I can generate the skeleton program so now I've got this skeleton program all written in Fortran and all I have to do is say a few words as add your code here stick the Fortran code in there so here's my Fortran code stick it in right words as add your code here and just figure out how it connects up again it's called temperature versus the so I have to fix that and again the arrays Anthony's instead of X and Y so I have to fix that so I just find those spots in the code where everything connects up the state that coding and I'm going to go so this is what my Fortran program looks like with the code inserted using the variable temperature using f and he brings all integrated working so that's my program and again I have to make my program so rapture generated the Makefile for me all I have to do is say make and it'll build with the libraries and I can look and now I've got a make file a tool that XML may not have and I just built main as 77 the Makefile certain set up to build something called me of 77 minister rapture and brings up the interface and just like before it's reading my tool that XML in generating the same interfaces before now when I click simulate it creates a driver file just like before it runs the program but this time it's a Fortran program and the program generates a around XML which as the data in and then the data gets loaded individually and the run filed its with way to your data results directory and everything's identical the only thing that's different is the program is written in Fortran here that's set everything else works the same way so if I go into the tool
that XML highway invoke that Fortran program so I like to see program acceptance of different executable name so I'm I'm going to invoke the full path of it whatever that full path is and then given the driver files an input and so again I say actual slash the executable name at driver that I'm assuming that the executables gonna sit wherever my tool that inside my program you can see how it looks up because inside the program calls the Fortran weight get are 1 it's the 1st argument off the command line and saves it in a variable called in file so driver 3 to 7 . xml so in file and then loads that in filing goes on from there so the 1st argument of the command line if I change the command line then I probably need to call change the call to get on to get a different argument than at the very end of my program again I have to call API result and what turns out in Fortran there is no well there is an exit program but most people don't use it exit function and so in in trade if I call API result and then I just in my main program for training terminates cleanly with an exit status code of 0 and also a way of the there's a stop thing in Fortran you can say stop if you say stop that's like were somewhat wrong but true so again instead of writing
documentation to create a good tool not XML file matter what language used instead of and for training you can read parameters just use the Fortran equivalent functions in rapture to to get the parameters and to do unit conversions you notice that the languages are all little different copy of the bar units under bar convert noble and all that and the arguments might be slightly differ from Fortran but it's all about the same thing in terms of how does the units conversion was trying to do and instead of writing stuff out you can use these functions to save everything in the XML tree by
you find lots documentation if you need the reference documentation rapture out or you can find all the documentation for the various languages and stuff and off we spent much time doing that just a of the labor the point I'll show enraptured org under documentation here and 1st of all there's some tutorials that you can go to define this and other courses in the 2nd of all you can see for all the different languages so if you try to wonder Haiti had a a call that progress function rapture it's all written down here you can see all the different things like the progress function like the API units convert noble and all that so if you like for training here's all the dark if you like job which we haven't talked about much there's doc here you figure out how to use the Java language calls and all that the build makes a pretty simple because with the builder you are accounted generates such stuff for you and again there's the 2 examples at very written in C written in Fortran written in Java written by phone you can find those examples there to trash
by lab assignment before lunch will get started on this now before lunch and will break for lunch and probably finish it up right after I want you to create a rapture interface for the program that you guys just finished reading right if you got stuck I can always get you a solution for the last assignment and you can move on from there and I don't want to be chatting against the wall for the last assigned by most people are working so take your letters program the letter accounting program that you just got involved in working in now you can add a rapture interface to the rapture interface is going take a string as an input in type what everyone Hello world instead of producing a histogram as an output and we haven't talked much about the history and yet that we didn't talk too much about the string was histogram and string again if
I go back to raptured out work and I'm looking at the documentation page where it says rapture documentation there's a section here words as rapture gooey XML elements right above all the language stuff these are all the different things in rapture that you can't mess with and these are the things you find in the builder there's a boolean value a choice a cloud a curve and so forth so all these different things like the string for example this shows you the examples of how to do this string it shows you a picture of what a string looks like a miniature these are the XML code that you see in the tool . XML if you're looking at it in Canada from that of all the different options there are you notice there's if you just do a normal string it's like a one-line string if you you could also make being strings and we make the being strings when you're looking at the documentation it says there's a size parameter the size parameter if I say 40 by 10 it means 40 characters wide and 10 lines tall that's how you make a big strain you can give it a size parameter and if you look in the Great build a there's actually a prompt for that there is a way to fill in the size of a string in green on so anyway you can look at this documentation kind of figure things out and looking at the gooey builder and see what options there are also for the histogram same thing you
can read about the history and here in terms of how it works and you can find in the go ability to strike it over drop it and probably you can figure it all out just by looking at the agreed builders on so the histogram thing is a lot like the curve that we've looked at before but it produces a bar chart and so on and you give it an x and y values on the x and y values could be numbers so they don't have to necessarily be continuous they could also be strings if you read the documentation a little bit when you're when you're sitting out but you can have you know you can have values like 1st and . 9 9 a 2nd point 3 4 so now come in handy for us because in our case we would have a letter in the count so we would have like a 3 D 7 you know and that'll that'll be all the different parts of the histogram for us
right so the job is the got 1 input is a string you got 1 output is a histogram extra credit if you wanna add another output another output you can you can report a number of number of words the number of words to me feel like an integer right because I can have 2 . 7 words and so you could have an integer output reporting the number of words if you wanna get some extra credit and on and then now once you've created the interface in the builder is going to build a you build this interface and then the next step is to save the file to save the skeleton program and then try to take the skeleton program the rapture has been connected up with the letters program that you've got you need to copy and paste from 1 end to the other whichever way you wanna go somehow you got a copy and paste the code and those 2 programs together to make it work and if you can do that man you could do anything so give it a try and and will be around 4 questions OK let me show you the solution I came up with for art lab assignment so I'm
in my workspace here and I'm right where we left off I've got this program called letters that C which is a C-language program and it prompts you for the letters and all that and I've got my makefile and I can compile it and when I run it then asked me to type in a sentence like hello world and accounts letters so that started from right now i wanna create a rapture interface for it so I use the builder and in my building I grab a string as the input and I grabbed a histogram as the output and I'll do the extra credit to all grabbed the integer number of words as the output to estimate of fixed each 1 of these to give it a better a better name and I'll call this so I and str in string and a label input text count the letters and this input string by default value will be blank and the size will be but this is where we can set the size of the string to be bigger than you notice if you if you read the little tooltip will tell you what goes here so if you want something like you know widened tall then you can say something like 40 by 5 5 which gives you at least 40 at least 40 characters wide and at least 5 lines if there's more space and you can put that in fact it'll it'll absorbed by any extra space on there's also hint string we can say I'm entered text above and whatever you put in there you'll see that shows up in the just below where the input area Sony histogram but give that a name on this is the letters and we'll call that letter counts on the x-axis is going to be the letter and the Y axis is gonna be the count and and you can look at all those options there's no units in this case because we don't have any physical units associated with the letters of the counts or anything and then this I'll call this and words and this is the number of words and again a description of number of words in the input string that now if I do my preview there's still a few warning so I guess I'll take a look at how we are forgot the tool and will call this 1 I call this word counter Arleta counter Augustus Russia call and description is solution for assignment number 6 and improve the program I'm going to do is in C language for this solution and and I can go through the rest of my warnings to just to see if I've clean everything up I guess it once and x-axis description and the y axis description here and then you should done the and for the Y axis of letters in input string are cycling everything up I can look at the previous
now hold my head up high hikers everything's nice and clean and you can see the hint text down here where it says enter text above and you can see the other the tooltips popping up when mouse-over things you notice if i mouse an axis it shows its description and so forth so it's good to put all those descriptions into can help people understand what's there and I have 2 results is going to be letter counts the number of words so I go back now pretty happy with my tool that XML and I can say that I'm going to say that in this directory is tool that XML I'm going to turn on the skeleton program and I'm going to turn on a new Make file and I can save all those things i want the tool definition the program in the Makefile when I go to say that it says wait a minute Make file already exists you 1 overwrite it yeah that's old crappy made by hand Make file I don't care so I'll just over at that 1 so now you can see I've
got the file in the tool that XML the make fun the new file of guys got all the wretched stuff in it and I have this new main . C program which what is what rapture generated and it says your code here for the main body of the program and it's got all this progress stuff and all that
but an oven I got my old letters . si program here so the trick is going to be combining those 2 combining the old letters . in the new main . si by the way I have a tool that XML and so I can run rapture right now and it will look like I can do something but it's not quite working yet because I don't have the program compiled so when go to try to simulate it says it can execute means see because there there is women compiled so I I can get that far but now I'm going take my main . si and can emerge in all the stuff that I had from letters . si but undergo the bottom and then read in letters . see all the parts and I'm gonna look at all the parts and start to put them together you notice I've got a few pound includes here those usually go up to the top so the pattern includes pattern defines undertake those 5 lines and put them up at the top and you notice there's a little bit of repetition I've already got standard I O here and I don't need another 1 there and over to get standard live and don't need another 1 there I do need type that 1 was new so by a many get rid of the 2 that I've already got leave the 1 that I didn't have I'm also gonna leave and letters I need that my main program already has a main program there and you notice I've got another 1 here I can do that I can have 2 main programs inside
so I wanna get rid of that and and all the rest of this that I have from my letters program all that stuff down there I need to put in the middle of summer get rid of all that a dump it in words as add your code here it needs to go there were sort of there usually declarations like this go at the top your program although modern compilers don't care modern compilers be just as happy with all the declarations there but but if you're if you're an item in a return of about those things I guess then you can take the the lines that we had there is room up to the top were all the rest of these definitions are right so I'm basically folding these 2 programs together and doing all this stuff the the real the 2 main areas where I need to change are where I get my input I used to print out and I used to read from standard in and also where I put the output
I used to print everything out to standard out and so that's the part I still have to fix the
wants to start with the input part I'm not going to prompt the user anymore to type in a sentence they don't need that so I'll just get rid of that and instead of reading each character from standard in instead is get what I really want to do is get each character out of in string raptures already
got this thing called in string which is going to be my input string and I wanna get each character out of that so I could set up like a counter set i equals 0 and then I could say in strings of 0 hour I guess to get the 1st character and then down at the bottom of the loop I can get the next 1 like ins strings of my course I have to the counter but before I do it so this would get the 1st character of the string and handle the 1st character and then I move my increment my pointer my mind I counter and then I would get the next character then out of the string and so so that should work that's a little bit wonky it in if you used during C + + code and I can do it a little bit better than that I can say i equals 0 in string i + + and therefore it's already advance to the next spot I don't need that but every time I get a character I can say i + + that's the reason they invented that plus plus operator in sequencing player in C and C + + because it's really handy sometimes to bump a pointer while you're doing something and so what we're doing here is we're grabbing the value I and as soon as we got that value go ahead and jump to the next character so that I'm ready next time around because seize statement and we used to it's kind handy that way so I'm starting with the value books some sorry starting with a value of 0 and coming in getting the value for a 0 and then bumping into 1 so that I'm ready and then I go down here I grabbed the value for 1 and about 2 2 so that I'm ready for the next time and I just keep going and going until I get to the end of the string now the way we used to have at the end of the string was a new line because you type in hello world in a new line in rapture the end of the string is a null character in general and the language the end of a string is always a null character from a change that to look for a null character and at the end of a string so that's a pretty good now it's actually gonna take the input value that I get from rapture and it's gonna look through that string there's 1 other thing I'll show you 2 and in case you guys have seen you guys heard about pointers and probably seen pointers and so there is a thing for using pointers on and instead of using this string like an array of and I could say a star insta plus plus you may have seen that sometimes in new C-language program the stars says give me the character out of that character string and again the + + as move on to the next character so instead of looking for instar bracket i + + bracket I can just say star insta + + and get the character and moving to the next 1 and then I do the same thing at the bottom of loop star insta + + that character moving to the next 1 and it'll do that as it's doing that cause I only do 1 pass through the string because it's actually moving in store along when I'm done with this loop I can go back and look at the string again because it'll will be moved to the end of the string and so what so it's kind of destructive in the sense that it moves the pointer as I'm going on 5 if I don't need in string again and I'm fine but if I do that I should make a copy of the pointer or something anyway just mentioning that in case you guys were interested in C + + if you were if you were real C + + enthusiasm the audience you be scolding me right now for that brackets stuff in user just use the pointer and so I'll keep this solution for now because it's easier to probably for you guys to read or write on the output side I used to print things out to standard out I'm not going to do that anymore I'm gonna get rid of those protests statements also I used to return 0 I'm not going to do that the more you remember when we return books when we return from the program we don't just want return 0 we wanna call API result then X is 0 and all that so we get a few more things to do on where I'm looking through here going through all my letters here my FOR loop that were used to print out 1 at a time on the screen what I wanna do
instead is build up my histogram so down here there's a little bit code that shows you about how to do the histogram so I can grab these 5 lines and kind stick them inside my loop up here this is what I'm trying to put this part of the code together and instead of printing out to standard out like this I want to build up a string but I'm going to do the same kind of use the same kind of parameters amused by 5 plus a and count so by and I could make instead these are double g procedures for a double precision number but I really wanna character and a decimal number but if you look in the documentation for rapture by histogram has something called x
h w that x is the X value h is the height of the bar box and then the w is the width of the bar so that I could make the with the the bottom 1 turns out most of the time you don't need to set the width of the bar and if we go back and look at the
documentation that you guys are doing this more and more building your own programs Republican have to fall back on the documentation and take a look if we look in the histogram there are lots of different
ways to specify the data the 1 that the builders showed us was x HW like this where I can specify an x value and a height of the bar and with the the bark but there's also just a simple x y I can just say x y if I just wanna have X and Y and X and Y so I would do that instead instead of having a
with of a bar me get rid of that in a minute change this to x y z x h W so what that will do then uremic print statement said now inside my loop here it's going to build up a string with the character and the count and that is going to say that string out in the x y section in it and notice it says API live append API live append their means each time
I go through the loop at a point on a point at a point on to the end so you can go through your looping gradually add data onto the the histogram sections I have 1 more thing that I need to do and that's my number of words right and all it's doing pretty well for me I called I called this thing and words in the builder and fortunately we fortunately for me I actually have a variable in here called and words so my number of words is downwards so this is just work magically words gets converted to an integer value and then the integer value saved that to the word saying see so clever about the way things in the builder then decodes magic which is works otherwise you may have to change the names a little bit but we we never did much with the progress but just for kicks up progress message inside my loop where that where and generating the the output the I guess that'll be the easiest thing but I can tell that the user that the progress is 1 i divided by n letters and letters but actually I want that to be a double value so I got a cast that to be a double is double isn't going to go back and look at the
documentation if I look under the rapture C API there's a thing for progress RPU teIls progress and it was a percentage completion and the message and if I look down to find it was a long page from whole so I the missing documentation I should at least tell us what the parameters are cause I forget whether it's integer double on
so let's try double and we'll see what happens earlier multiplied by a hundred actually that's it that's an easy way to convert it to a double if I take my value i times 100 . 0 and then divide by and letters and then I will give it the message generating output where this is going to happen so fast we probably won't see any of those messages swing by but that's at least how you would add progress if you therefore were taking a long time to compute each of the letters or something like that right so that's an example of that now we try to compile and I'll see if I got anything going on main that see it's telling line 29 I have a re declaration of n words OK line
29 it tells me n words is re declared 0 because the builder declared it up here and then I declared it in my letters . si so OK 1 or the other to say that 1 and make ends telling you have got to unused variables Aaron data and that's because the builder The Builder declared that declared that saw get rid of that too and now what make it's nice and clean so if I having any trouble with my program member I can take my tool that XML and I can create a driver about XML and in my driver file I could put in a test string so I can say the current value of current ABC x y z and then I can run my main C program with the driver and see what happens books dunce . slash means you notice when I run it you can see each of the each of the progress messages and showing me like my percentage completion generating upward generating output and then the last thing it shows me as the run file so that I can look in their run file and see if it looks right this is what I would get and you can see that it actually generated some data generated the statistics for a b c and x y z and generated the number
of words here there's a current value for the number of words and all that in fact I can also do the
rapture load on that run file and I can see the
results so all of that
makes me very confident if I had any problems I would just going to GDP and I would do but my program right i would done for example set a breakpoint and that line 58 and I would run with my driver file and then I can step through my program and watch what happens as it's zeroing out the counts and then watch what happens as it goes in and counts each letter and so forth so just like before we can get in and debugger program we can print out the characters and print out the counts and check everything out and if I convinced myself that it's all pretty much working that I can try it for real so now put in some text hello world and I get the letter cannot that I can try a few more ABC x y z and simulate again and you notice for each of them I can also look at the number of words the number of words in my 1st example the number words my 2nd example and I can do 3rd groups quick brown fox jumps over the lazy dog stimuli that that's got a few more letters to it and then maybe a few more words words on that example that last example that I did alright so that is how it works and if you can do all of that you can build
just about any program now in rapture right because you can build the interface you can hook it underneath to the program that's there and you can make it all work