 So in the next section we're going to take everything you learned about C and Fortran and put it together with Rapture. So now if someone hands you a C program or a Fortran program and says make it look pretty, put it up on Nano Hub, you can do it because you've got Rapture and you're all set. So let's take an example program, kind of like the one that you guys just used in the lab assignment. This one's the Fermi program that I've used before, but it's pretty much the same thing. If I have a Fermi program, Fermi.c, first of all, you know I've got to compile it and probably I should make myself a make file. And once I've compiled it, I can run it like that and it'll ask me something like enter the Fermi level and I'll put in a value 2.4 and it'll ask me for the temperature and I'll put in a value like 77. And then the Fermi program will go and run its thing and produce an output file and if I looked in the output file, it would give me a bunch of numbers, right? So that's the way most C language programs are written. That's the way my, remember way back when I told you about my SQL program was written in Fortran, it was a lot like this. Feed in some values and you get out some data. Now in Rapture, we can make it look a whole lot fancier 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 app Fermi and there's a C language directory and a Fortran directory and you can see all the different languages. All right, so here's my C language version of the Fermi function calculator. And you might be getting that kind of eerie sense of deja vu because a lot of this, first of all, looks like the C language we've just been doing. And second of all, it looks like 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 main program and all of that. There's a printf statement and a scanf statement here. And that corresponds to this control, right? In the C language program, we say enter the Fermi energy and we use scanf to read in a value. That's sort of like that control that we have in Rapture. And this other printf and other scanf is just like that control that we use for the temperature. And the stuff down at the bottom, which prints out the values for the curve, that's just like the curve object in Rapture. So just like we saw yesterday, there's some input stuff and there's 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 we're computing, using the Boltzmann constant to figure out the energy spread. And we're going through a list of energy ranges and we're actually computing the function f in a while loop. So that's really the meat of my program. So whenever you're starting a program like this, you should always ask yourself, what are the inputs, what are the outputs? And then you take those inputs and outputs and map it onto a Rapture interface. You notice in this case, the inputs and the outputs in the interface that we get are identical to the MATLAB thing that we saw yesterday, identical. The interface, when you're running the program on Nano Hub, you actually wouldn't be able to tell whether it was a C language or MATLAB or Fortran under the hood. It all looks the same. All right, so if we were going to go in, just like we did yesterday, we were going to go in and create this interface in the builder. We drag and drop all the controls over. Or actually, I could just use the tool.xml that I have for the MATLAB version. But the difference is down at the bottom. If I go into the tool interface, there's a parameter at the bottom for program. Instead of saying MATLAB or Octave there, we're going to set C language. So I'm just going to change the language there. And then when we go to save, we can save a skeleton program in C and we can save a makefile. The builder will build the makefile for you. So you guys will have a makefile, you won't have to create your own. All right, and make sure you save those because otherwise there's a lot more code for you to write. So here's the generated program. Rapture's going to spit out the skeleton program that already has all the statements for getting the number and the temperature and the EF 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 meat of our program and stick it in right where it says, add your code here. That's the meat of the program. And then all we have to do is connect it up again. We have to, if we have a variable called temperature, but in my code I called it T, I need to sync those two things up. And if we have these vectors F and E that are generated by that program, but Rapture called them X and Y, I need to sync those two things up. So just like yesterday, aren't you getting 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. So here's my finished program. I plugged in the code and pretty much left it alone. I just plugged in the F and the E and stuff like that. Now, Rapture generated the make file for me so I can use that make file. You notice when I say make, it's a lot more complicated here. It's good to have Rapture generate the make file for you. Cuz Rapture has libraries and all this other gobbledygook. You guys would have to put in the dash i and the dash l and you'd be like, well, how do I know that? And the answer is you don't. I mean, Rapture generate the make file for you and it'll put all the libraries in place. So every time you say make, it compile it with the right libraries. And now if we look in the directory, we'll see the make file that Rapture generated. We'll see the tool.xml that we got from the builder. We see main.c, we just edited that. And now that we did make, there's a program called Rapture calls it mainc. So there's a mainc version of the program that's been compiled. And now I can type Rapture and just like before, Rapture reads the tool.xml, right? I put in my values for temperature and EF. And when I click simulate, it produces a driver file, which is an exact copy of the tool.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 in it shown there. Just like we learned yesterday. The only difference is that main program now is written in C. But everything works the same way. Rapture loads up my curve and it whisks away the run file. Remember we talked yesterday the run file goes into your data results directory, so it gets whisked away. Now it's a little different if you look inside the tool.xml and how the program gets invoked. We looked at this yesterday too. The command section of the tool.xml still uses the app tool and still uses the app driver. It's just a little different from yesterday. In this case, we want to run the executable main C. Where is main C? It's in the same directory right now as your tool.xml. So I can say at tool slash main C. If it's one directory up and over here, then I can say at tool slash dot dot slash bin slash whatever. You give it whatever path you want that works in Unix but always relative to at tool. At tool is where your tool.xml is. You can figure out where everything else is relative to the tool.xml. So in this case, I'll keep it simple. Main C is right there with the tool.xml, so I'll say at tool main C. And then the first argument on the command line is the driver file, at driver. All right, so Rapture's gonna expand that out wherever your tool happens to be. You know, I don't know if I made this point well enough yesterday. You may have, I don't know if you guys have 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 it up on Nanohub, you install it. And all of a sudden when it comes in, it goes to somebody else's directory, it doesn't work anymore. Why? Because there are hard coded paths in your program and hard coded paths in various places. And it's all set up to work in your directory but not in someone else's directory. See that's the reason why we do all this at tool and at driver stuff in Rapture. So that the tool can, you can plunk it down anywhere and everything works because everything's relative to the tool.xml. So when your tool is installed on Nanohub, it will actually go into a directory like slash apps, slash whatever the name of your tool is, slash current, and so forth. So you don't have to know that. The point is by using at tool, it works no matter where you drop all of that code and build it. That's why we do the at tool thing, because we don't want any hard coded paths in your program. All right, now inside the main program, if you look at the code that Rapture generated in the main program, one of the first things it does is it opens up RP library with argv bracket one. Argv bracket one is the first argument on the command line, and that's going to be the name of my driver file, first argument on the command line. And again, that'll have a random number. You don't have to know, you just say app driver. So it'll take the file, it'll open it, it'll do its thing. And then again at the very end, make sure you called RPResult, and then you exit with the status code of zero. If you forget, if you don't call RPResult or if somehow in the massive craziness of debugging, you delete that line out of the program, then if you never call RPResult, Rapture won't get a run file. It'll be like, what's up, no run file. Or if you don't exit with the status code of zero, our Rapture will say, aha, your program failed. Must have failed because it had a non-zero exit status code. So Rapture will just say, your program's no good, failed. So you gotta make sure you do those two things. Save your run file, exit with a zero status code. That means you're good. All right, so you can kind of think of it like this. When you're thinking about, show you all this, you're like, wow, there's 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 of that. Instead of doing all of that the old fashioned way, you just create a tool.xml file that really has that stuff embedded in it, you don't need a user guide if you have tool tips on your tool, and if the tool has good documentation, kind of explains what it does. So your documentation now becomes embedded in the tool, in the form of the stuff you put into the tool.xml. So instead of writing a lot of documentation, just build a good tool.xml. Instead of calling scanf to get parameters in from standard in, you do the Rapture thing. The Rapture thing is I've got a control, I can get a string. Rapture even has a RP convert double that will do units conversion. That's even one 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 want to do. And Rapture will do the units conversion, just like that. Instead of printing stuff out on the screen at the end, you just do the RP put string and the RP result stuff that we saw earlier. So it's really one for one, instead of wasting your time on documentation and writing printf and scanf, you can just use the tool.xml file and the stuff that's kind of built into Rapture. It's all equivalent, it's all the same thing. The rest of your program stays the same. All right, that was the C language version. Let's shift gears and I'll show you the Fortran version. And geez, by the time I'm done with this, you're going to be crying uncle because you'll be like, my gosh, I've seen the same thing so many times in all these different languages, I get it, I get it. I'm really hoping that you'll be saying, I get it, I get it. Don't tell me again. So in my Fortran program, I have a part where I'm asking the person to enter the energy in EV, that's just like that control. I'm going to replace this code with that control. And all the stuff at the bottom that prints stuff out, I'm going to use a curve instead. And in the middle, I've got my physics code and I'm going to yank that out of the program and put it into my Rapture program, right? Just like the C language one. And again, the tool.xml is identical. One change in the tool.xml. If I bring it up in the builder, I got to change the language here to Fortran 77. So if I change the language in the builder, then I can save it out. And you remember, just like before, I can save it as a make file and I can generate the skeleton program. So now I've got this skeleton program all written in Fortran. All I have to do is see where it says, add your code here. Stick the Fortran code in there. So here's my Fortran code. Stick it in right where it says, add your code here. And just figure out how it connects up. Again, it's called temperature versus T, so I have to fix that. And again, there are arrays F and E instead of X and Y. So I have to fix that. So I just find those spots in the code where everything connects up and I stick that code in and I'm good to go. So this is what my Fortran program looks like with the code inserted, using the variable temperature, using F and E, everything's all integrated, working. So that's my program. And again, I have to make my program. So Rapture generated the make file 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.xml, a main.f, and I just built main f77. The make file set up to build something called main f77. Then I say Rapture and it brings up the interface. And just like before, it's reading my tool.xml and generating the same interface as 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 run.xml, which has the data in it. And then the data gets loaded into the GUI and the run file gets whisked away 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 it. Everything else works the same way. So if I go into the tool.xml, how do I invoke that Fortran program? It's a lot like the C program, except it's a different executable name. So I'm gonna invoke the full path of it, whatever that full path is, and then give it the driver file as an input. And so again, I say at tool slash the executable name at driver. I'm assuming that the executable's gonna sit wherever my tool.xml is. Inside my program, you can see how it hooks up because inside the program it calls the Fortran way, get arg one, gets the first argument off the command line and saves it in a variable called infile. So driver 327.xml gets saved into infile and then it loads that infile and goes on from there. So again, first argument off the command line. If I change the command line, then I probably need to change the call to get arg to get a different argument. And at the very end of my program, again I have to call rp result and it turns out in Fortran there is no, well there is an exit program, but most people don't use it, exit function. So in Fortran, if I call rp result and then I just end my main program, Fortran terminates cleanly with an exit status code of zero. There's also a way of, there's a stop thing in Fortran where you can say stop. If you say stop, that's like brr, something went wrong. All right. So, again, instead of writing documentation, create a good tool.xml file, no matter what language you use. Instead of in Fortran you can read parameters, just use the Fortran equivalent functions and rapture to get the parameters and to do units conversion. You notice with the languages, they're all a little different. rp underbar units, underbar convert, double and all that and the arguments might be slightly different for Fortran but it's all about the same thing in terms of how it does the units conversion and what it's trying to do. And instead of writing stuff out, you can use these functions to save everything in the XML. All right, you'll find lots of documentation if you need the reference documentation. If you go to rapture.org, you can find all the documentation for the various languages and stuff. I don't know if we spent much time doing that just to belabor the point. I'll show you. On rapture.org, under documentation here. First of all, there's some tutorials that you can go to to find this and other courses. And second of all, you can see for all the different languages. So if you're trying to wonder, hey, how do I call that progress function in rapture? It's all written down here. You can see all the different things like the progress function and like the rp units convert, double and all of that. So if you like Fortran, here's all the doc. If you like Java, which we haven't talked about much, there's doc here. You can figure out how to use the Java language calls and all of that. The builder makes it pretty simple because with the builder, it kind of generates that stuff for you. And again, there's the two examples, App Fermi written in C, written in Fortran, written in Java, written in Python. You can find those examples there too. All right. Lab assignment before lunch. We'll get started on this now before lunch and we'll break for lunch and we'll probably finish it up right after. I want you to create a rapture interface for the program that you guys just finished getting right. If you got stuck, I can always get you a solution for the last assignment and you can move on from there. I don't wanna make you beat your head against the wall for the last assignment, but I think most people got it working. So take your letters program, the letter counting program that you just got debugged and working and now you're gonna add a rapture interface to it. The rapture interface is gonna take a string as an input and type whatever you want, hello world and it's gonna produce a histogram as an output. We haven't talked much about the histogram yet and we didn't talk too much about the string. What's the histogram and string? Again, if I go back to rapture.org and I'm looking on the documentation page where it says rapture documentation, there's a section here where it says rapture, GUI XML elements, right above all the language stuff. These are all the different things in rapture that you can 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 the string. It shows you a picture of what a string looks like and then it shows you sort of the XML code that you'd see in the tool.xml. If you were looking at it. You can kind of get a sense 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 can also make big strings and the way you make the big strings when you're looking at the documentation, it says there's a size parameter. The size parameter, if I say 40 by 10, that means 40 characters wide and 10 lines tall, that's how you make a big string. You can give it a size parameter and if you look in the GUI builder, there's actually a prompt for that. There's a way to fill in the size of a string in the GUI builder. So anyway, you can look at this documentation and kind of figure things out and look in the GUI builder and see what options there are. Also for the histogram, same thing. You can read about the histogram here in terms of how it works and you can find it in the GUI builder. You just drag it over, drop it and probably you can figure it all out just by looking at it in the GUI builder. So the histogram thing is a lot like the curve that we've looked at before but it produces a bar chart and you give it X and Y values. The X and Y values could be numbers, they don't have to necessarily be contiguous, they can also be strings. If you read the documentation a little bit, when you're saving output, you can have values like first and 0.99 and second and 0.34. That'll come in handy for us because in our case, we wanna have a letter and the count. So we wanna have like A, three, B, seven. And that'll be all the different parts of the histogram for us. All right, so the job is you got one input, it's a string, you got one output, it's a histogram, extra credit if you wanna add another output. Another output, you can report a number, number of words. The number of words to me feels like an integer, right? Because I can't have 2.7 words. So you can have an integer output reporting the number of words if you wanna get some extra credit. And then once you've created the interface in the builder, go into the builder and you build this interface, then the next step is to save the make file, to save the skeleton program and then try to take the skeleton program that Rapture has and connect it up with the letters program that you've got. You need to copy and paste from one into the other whichever way you wanna go. Somehow you gotta copy and paste the code and meld those two programs together. Make it work. And if you can do that, man, you can do anything. So give it a try and we'll be around for questions. Okay, let me show you the solution that I came up with for our lab assignment. So I'm in my workspace here and I'm right where we left off. I've got this program called letters.c which is a C language program and it prompts you for the letters and all that. And I've got my make file and I can compile it and when I run it, it asks me to type in a sentence like hello world and it counts the letters. So that's where I'm starting from, right? Now I wanna create a Rapture interface for it. So I use the builder and in my builder, I grab a string as the input and I grab a histogram as the output and I'll do the extra credit too. I'll grab the integer number of words as the output too. And I'm gonna fix each one of these to give it a better name. I'll call this INSTR, in string. I'll label it input text, count the letters in this input string. Default value will be blank and the size will be, this is where we can set the size of the string to be bigger. And you notice if you read the little tool tip, it'll tell you what goes here. So if you want something like wide and tall, then you can say something like 40 by five which gives you at least 40 characters wide and at least five lines tall. If there's more space, you can put that in. It'll absorb any extra space. There's also a hint string. We can say enter text above and whatever you put in there, you'll see that shows up just below where the input area. So on the histogram, I'll give that a name. This is the letters and we'll call that letter counts. The x-axis is going to be the letter and the y-axis is going to be the count. 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 or the counts or anything. And then this, I'll call this n words and this is the number of words and again a description, number of words in the input string. Now, if I do my preview, there's still a few warnings. I guess I'll take a look at them. Oh yeah, I forgot the tool. We'll call this one, call this word counter or letter counter I guess is what I should call it. And the description is solution for assignment number six. And the program I'm going to do is in C language for this solution. And I can go through the rest of my warnings too just to see if I've cleaned everything up. I guess it wants an x-axis description and a y-axis description here. Dang, I should have done that. And for the y-axis count of letters in input string. All right, so I've cleaned everything up. I can look at the preview now and hold my head up high because everything's nice and clean. You can see the hint text down here where it says enter text above and you can see the tool tips popping up when I mouse over things. You notice if I mouse over an axis it shows its description and so forth. So it's good to put all those descriptions in to kind of help people understand what's there. And I have two results. It's going to be letter counts and number of words. So I go back now pretty happy with my tool.xml and I can save that. I'm going to save it in this directory as tool.xml. I'm going to turn on the skeleton program and I'm going to turn on a new make file. And then I can save. So I want all those things. I want the tool definition, the program and the make file. When I go to save it, it says, wait a minute, make file already exists. You want to overwrite it? Yeah, that's my old crappy made by hand make file. I don't care. So I'll just overwrite that. So now you can see I've got the make file and the tool.xml and the new make file I've got has got all the Rapture stuff in it. And I have this new main.c program which is what Rapture generated. And it says add your code here for the main body of the program. And it's got all this progress stuff and all that. And I've got my old letters.c program here. So the trick is going to be combining those two, combining the old letters.c and the new main.c. By the way, I have a tool.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 I go to try to simulate, it says it can't execute main.c because there is, we haven't compiled it yet. So all right, I can get that far but now I'm going to take my main.c and kind of merge in all the stuff that I had from letters.c. I'm going to go to the bottom and I'm going to read in letters.c, all the parts and I'm going to 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 at the top. So the pound includes and the pound defines, I'm going to take those five lines and put them up at the top. And you notice there's a little bit of repetition. I've already got standard IO here and I don't need another one there and I've already got standard lib and I don't need another one there. I do need C type, that one was new. So all right, I'm going to get rid of the two that I've already got, leave the one that I didn't have. I'm also going to leave n letters, I need that. My main program already has a main program there and you notice I've got another one here. I can't do that, I can't have two main programs inside. So I want to get rid of that. And all the rest of this that I have from my letters program, all of that stuff down there, I need to put in the middle. So I'm going to get rid of all that and I'm going to dump it in where it says add your code here. It needs to go there. Or sort of there. Usually declarations like this go at the top of your program. Although modern compilers don't care. Modern compilers would be just as happy with all the declarations there. But if you're, I don't know, anal retentive about those things I guess, then you can take the lines that we had there and move them up to the top where all the rest of these definitions are. All right, so I'm basically folding these two programs together, doing all the stuff. The real, the two 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. Let's start with the input part. I'm not going to prompt the user anymore to type in a sentence. They don't need that. I'll just, I'd get rid of that. And instead of reading each character from standard in, instead of this get char, what I really want to do is get each character out of in string. Rapture's already got this thing called in string, which is going to be my input string. And I want to get each character out of that. So I could set up like a counter, say I equals zero. And then I could say in string sub zero or I I guess to get the first character. And then down in the bottom of the loop, I can get the next one. Like in string sub I, of course I have to bump the counter before I do it. So this would get the first character out of the string and I'd handle the first character and then I'd move my increment, my pointer, my eye counter and then I would get the next character then out of the string. So that should work. That's a little bit wonky if you're used to writing C++ code. I can do it a little bit better than that. I can say I equals zero in string I plus plus and therefore it's already advanced to the next spot. I don't need that. But every time I get a character I can say I plus plus. That's the reason they invented that plus plus operator in C and C and C++ because it's really handy sometimes to bump a pointer while you're doing something. So what we're doing here is we're grabbing the value I and as soon as we've gotten that value go ahead and jump to the next character so that I'm ready next time around. It kind of saves me a statement and when you get used to it it's kind of handy that way. So I'm starting with a value, oops I'm sorry, starting with a value of zero and I'm coming in getting the value for zero and then bumping to one so that I'm ready and then I go down here and I grab the value for one and I bump to two 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 it, the end of the string was a new line because you would type in hello world and a new line. In Rapture the end of the string is a null character. In general in C language the end of a string is always a null character. So I'm gonna change that too to look for a null character at the end of the string. So that's pretty good. Now it's actually gonna take the input value that I get from Rapture and it's gonna loop through that string. There's one other thing I'll show you too in case you guys have seen it. You guys heard about pointers and you've probably seen pointers. So there's a thing for using pointers and instead of using the string like an array I could say star insta plus plus. You may have seen that sometimes in your C language programs. The star says get me the character out of that character string and again the plus plus says move on to the next character. So instead of looking for insta bracket I plus plus bracket I can just say star insta plus plus and it'll get the character and move me to the next one. And then I do the same thing at the bottom of the loop star insta plus plus it'll get that character moving to the next one and it'll do that. As it's doing that of course I can only get one pass through the string because it's actually moving insta along when I'm done with this loop I can't go back and look at the string again because it'll be moved to the end of the string. So it's kind of destructive in the sense that it moves the pointer as I'm going. If I don't need insta again then I'm fine but if I do then I should make a copy of the pointer or something. Anyway, just mentioning that in case you guys are interested in C plus plus if you were real C plus plus enthusiasts in the audience you would be scolding me right now for that bracket stuff and you'd say just use a pointer man. So I'll keep this solution for now because it's easier probably for you guys to read. All right, now on the output side I used to print things out to standard out. I'm not gonna do that anymore. I'm gonna get rid of those printf statements. Also I used to return zero, I'm not gonna do that anymore. Remember when we return, whoops, when we return from the program we don't just wanna return zero we wanna call rp result and exit zero and all that. So we got a few more things to do. Where I'm looping through here going through all my letters here in my for loop where I used to print out one at a time on the screen what I wanna do instead is build up my histogram. So down here there's a little bit of code that it shows you about how to do the histogram. So I can grab these five lines and kinda stick them inside my loop up here. This is what I'm trying to put this part of the code together. Instead of printing out to standard out like this I wanna build up a string but I'm gonna use the same kind of parameters. I'm gonna use i plus a and count sub i and I could make instead, these aren't double, g percent g is for a double precision number but I really want a character and a decimal number. If you look in the documentation for Rapture a histogram has something called xhw that x is the x value, h is the height of the bar and then the w is the width of the bar. So all right, I could make the width of the bar one. 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 as you guys are doing this more and more building your own programs you're probably gonna 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 one that the builder showed us was xhw like this where I can specify an x value and a height of the bar and a width of the bar but there's also just a simple xy. I can just say xy if I just want to have x and y and x and y. So I'm gonna do that instead. Instead of having a width of a bar I'm gonna get rid of that and I'm gonna change this to xy instead of xhw. All right. So what that will do then get rid of my print statement. So now inside my loop here it's gonna build up a string with the character and the count and then it's gonna save that string out in the xy section and notice it says rplib append. rplib append there means each time I go through the loop add a point, add a point, add a point on to the end. So you can go through your loop and gradually add data on to the histogram section. I have one more thing that I need to do that's my number of words, right? Oh and it's doing it pretty well for me. I called this thing n words in the builder and fortunately for me I actually have a variable in here called n words. So my number of words is yeah, called n words. So this is just gonna work magically. n words gets converted to an integer value and then the integer value gets saved out to the n words thing. See so if you're very clever about the way you name things in the builder then the code's magic, it just works. Otherwise you may have to change the names a little bit. We never did much with the progress but just for kicks I'll put a progress message in. Inside my loop where I'm generating the output. Yeah I guess that'll be the easiest thing. I can tell the user that the progress is I divided by n letters. N letters. Actually I want that to be a double value. So I gotta cast it to be a double. It is double isn't it? I gotta go back and look at the documentation. If I look under the Rapture C API there's a thing for progress. RP utils progress. And it wants a percentage completion and a message. And if I look down to find it, well it's a long page, huh? So missing documentation. It should at least tell us what the parameters are because I forget whether it's integer or double. So let's try double and we'll see what happens. Oh yeah, multiply by 100. Actually that's an easy way to convert it to a double. If I take my value i times 100.0 and then divide by n letters and then we'll give it the message generating output. Boy, this is gonna 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 we're taking a long time to compute each of the letters or something like that. All right, so that's an example of that. Now we try to compile and I'll see if I got anything going. Main.c it's telling me line 29 I have a redeclaration of n words. Okay, line 29 it tells me n words is redeclared. Oh, because the builder declared it up here and then I declared it in my letters.c. So okay, one or the other. Save that one. And make. And it's telling me I've got two unused variables, error and data. And that's because the builder declared that and it declared that. So I'll get rid of that too. And now when I make it's nice and clean. So if I'm having any trouble with my program, remember I can take my tool.xml and I can create a driver.xml and in my driver file I could put in a test string so I can set a current value, oops, current ABC, XYZ. And then I can run my main C program with the driver and see what happens. Oops, dots, dot slash main C. You notice when I run it, you can see each of the progress messages showing me like my percentage completion, generating output, generating output and then the last thing it shows me is the run file. So now I can look in that run file and see if it looks right. This is what I would get. And you can see that it actually, yeah, generated some data. It generated the statistics for ABC and XYZ and it 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 go into GDB and I would debug my program, right? I would, for example, set a break point at 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 debug our program. We can print out the characters and print out the counts and check everything out. And if I convince myself that it's all pretty much working, then I can try it for real. So now I'll put in some text, hello world and I get the letter counts and I can try a few more, ABC, XYZ 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 first example, the number of words in my second example, I can do a third. Oops, quick brown fox jump over the lazy dog. Simulate that. That's got a few more letters to it and maybe a few more words. More words on that example, that last example that I did. All right, so that is how it works and if you can do all of that, you can build just about any program now in Rapture, because you can build the interface and you can hook it in underneath to the program that's there and you can make it all work.