Next: Contents
In this section:
© Edward N. Bromhead 2022.
The fact that you are reading this book means that either you are looking for a cure for insomnia or - because from the title this isn’t the sort of thing that you would pick up to casually browse through - then you probably have a real need. If I am allowed to speculate it is that you have a Fortran program from somewhere that you would like to put a Windows graphical user interface (GUI) on to, and you possibly looked at some of the alternative ways to do it and decided that they are far too complicated, or you have just chanced on this at the beginning of your search. Alternatively, there is the very remotest chance that you are setting out to write a program from scratch and that you think it ought to have a Windows GUI. If you are writing a program from scratch, then I still recommend that you do the Windows part in a particular order, which is the order I have set out in the book. If you are not an old-style programmer then you probably ought to leave out Chapter 3, and if you aren’t at all interested in my journey, then just ignore Chapter 27. The rest is still relevant.
You can find out about me and how I came to be programming first of all in Fortran, secondly using the Silverfrost compiler and thirdly, how I came to be using ClearWin+ in the first instance, if you flip the book and read that last chapter (27). It’s probably one that you could easily leave out, and if you wanted to criticise my old-fashioned approach to Fortran, then reading it would probably tell you why I do things the way I do.
Many years ago, I bought a very small and slim paperback book called “The Elements of Fortran Style” by two American authors: Kreitzberg and Schneiderman. I lost my first copy to a student who borrowed it and as so often was the case with my books, never returned it. It was all about things that you might do in Fortran 66, and some of their advice is no longer as useful as it was back then. I loved that slim paperback book, and eventually found another copy to buy. I also loved their advice, and just following it, I managed to get the runtime in one of my programs back in the early 1970s down from three hours to 20 minutes! The lasting advice, however, which I still follow a scrupulously as I possibly can, is to use a lot of white space in my Fortran source codes. By doing so, I find that things that I wrote nearly a half-century ago are still fairly straightforward and I can follow them, which is more than can be said for some modern codes which when I look at them, my eyes glaze over and I lose interest! That’s a pity, because I have learnt a lot in the past by reading other people’s Fortran codes, sometimes things that are useful to do, but far more often, things that I should avoid.
I don’t think that I am the final authority on how to write Fortran – far from it. I’m also not the ultimate authority on the ClearWin+ system that is an integral part of the Silverfrost FTN95 compiler package. I’m not connected with the company that markets that particular compiler in any way other than having a licensed copy of it. You don’t even need to buy a licence to do a bit of personal Fortran development because the company offers completely free of charge a Personal Edition. However, if your application is very successful and you want to market it commercially, then you will undoubtedly want a proper commercial licence if for no better reason than it will remove the nagging screen that appears when the application starts and lasts for about six seconds. The other reason, of course, is the obvious legal one. Other than that, there is no actual difference between what you can do with the Personal Edition and the licensed version.
My authority – such as it is - to write the book comes from the fact that I have used FTN95 and ClearWin+ to write a number of Fortran applications for Windows. Yes, I have written applications completely from scratch in this way, but I have also modified existing Fortran codes of my own to give them a Windows GUI interface. However, I’m rather old-fashioned in the way that I program Fortran because I started in about 1970 and that is a long time ago. As
L. P. Hartley makes his protagonist Leo say in the opening lines of the book The Go-Between: ‘The past is a foreign country. They do things differently there.’ Fortran has developed a lot in the half century or more since 1970 and some of the developments I think are brilliant, others just seem to me a different way of doing things because the Fortran committee that establishes the standards doesn’t like Fortran as it was; and others I simply can’t see the point of. That isn’t a philosophical perspective such as one might have if one was a computer scientist – just that they do things in a way that I either don’t understand or don’t need to.
I’ll start by showing you how easy it is to write a Fortran application in ClearWin+ and FTN95. It should whet your appetite, but make no mistake, even though ClearWin+ is a lot easier than many of the alternative systems, to produce a professional looking windows GUI for your application will need a lot of programming and take a lot of time and effort. How to get started is simply to install the FTN95 package. It’s not just a Fortran compiler, it’s three different Fortran compilers and it has C compilers as well. There are other applications included in the package including a GUI development environment called Plato, and debugging aids. You don’t need to use any of those additional applications, in fact I don’t. Instead of Plato, I use a freeware program file editor called PFE32. That does not mean that there is anything wrong with Plato, it is just what I am used to. New users should automatically go to Plato and not look anywhere else. It is far more integrated than any old editor and a bunch of batch files.
So how easy is it to write a Fortran program to run in Windows? The bare bones are given in Chapter 1.
I am simply not going to cover every facility available in ClearWin+, because after a while, you will get used to looking for the appropriate facilities in the online help file(s), and hopefully, you will better understand the descriptions therein. My first ports of call in the help file depend on whether I am looking for the details on something for which I know the name, or where I simply know the context. If I know the name, then for a format code (explained later), I look in the help file under the tab ‘ClearWin+’ and then the subsidiary tab ‘Format code reference’, where all the available format codes are listed alphabetically with links to places in the help file where they are described more fully. Similarly, when I am looking for a subroutine or function for which I know the name, I look in the related tab ‘Library reference’. In both of these tabs everything is listed in alphabetical order. I find the library reference particularly useful in discovering whether something is a subroutine or a function because that is not always clear in my memory. Occasionally, I need to look in the ‘FTN95 library’ where there are a range of routines described that do prove useful, and include both Fortran standard routines and Silverfrost’s own.
If I am looking for something on the basis of a concept of what it should do then I might look in the tab ‘Library overview’, where subroutines and functions are grouped by their purposes. The format codes do not have a similar grouping, but at a higher level (i.e. only one step below the ClearWin+ tab), the descriptions are grouped by functionality.
I am an inveterate reader of documentation, and as well as the various help files that are supplied with the compiler package and which may be either read directly or via an option in the Plato integrated development environment, some useful files are included with the FTN95
installation. Two of these files have the .ENH qualifier, with one of them noting version by version enhancements to the Fortran compiler itself and the other noting again version by version enhancements to ClearWin+. When I read the ClearWin+ enhancements file it sometimes gives me ideas about things to incorporate my programs. It’s a file that you should skip to the end of first, and read it almost in reverse order, because lots of the earlier enhancements are actually described fully in the online help files.
The ultimate point of this book is that since the Fortran Standards Committee in their infinite wisdom have not seen the need either for integrated graphics, or for facilities to create a good user interface, let alone a graphical one, then if you want those, you need compiler extensions. The folks at Silverfrost, and at Salford before them, saw the need for both, and provided them right from the beginning, providing a Windows-compatible GUI system a long time ago. In my view, they were smart to do so – smarter than the Fortran Standards Committee.
These are the 10 steps that I have found to work best in modifying an existing Fortran computer program or creating one from scratch that uses the FTN95/ClearWin+ system to create a Windows application.
Stage I: | Make sure that the computational algorithm works and compiles with FTN95. |
Stage II: | Create the necessary Windows menu structure to allow different input data files to be used. |
Stage III: | Add a graphical back end (meaning display the results of the analysis graphically). |
Stage IV: | Implement a variety of graphics options for the back-end. |
Stage V: | Implement the necessary menus to allow data values from the data file to be modified. |
Stage VI: | Modify the File menu to allow saving of the changed dataset. Stage VII: Produce hardcopy output. |
Stage VIII: | Implement a method of creating a dataset from nothing. |
Stage IX: | Create a toolbar to simplify the input of data and to perform other tasks. |
Stage X: | Generate the help system. |
The whole point of doing it in this order is that you are always able to use your program, it just gets more and more like a Windows application as you complete each stage. However, what you have to learn, and the complexities of how you do the job, are not the same for every stage. I have dropped the stage nomenclature for the book, but I have retained the underlying structure. Each chapter covers one main topic, and I have put in place milestones to reflect what you will have achieved when you have mastered that topic.
Of course, there is nothing to stop you doing things in a different order – the choice is yours. You may not even agree with the order of my 10 stages. And, of course, ClearWin+ is not some static thing, it is being developed. It has new facilities introduced all the time. There will be some that have been introduced after I finished writing this book. Equally, I haven't described everything in ClearWin+, because eventually you will feel so confident that you can go looking in the documentation for what you want, and understanding how ClearWin+ works, you will understand the documentation better. At least I hope that you will. However, there is enough in this book to give you that head start.
If you decide to program something entirely from scratch, there is still merit in the ten-stage procedure I have drawn up, although Stage I is effectively producing a traditional Fortran program. I have the habit of calling such things nowadays as ‘DOS’ programs, noting that in the world of personal computers prior to the introduction of Windows, the operating system was MS DOS. Another name for them apparently preferred today is ‘console application’. I even have some advice on how to proceed.
In the earliest stages of development, I recommend that you initialise your test dataset using DATA statements or assign statements – I find the latter easier. My recommendation is that you don’t scatter your initialisations all through your program, but keep them in one place, preferably in a single subroutine where you can find them and check up on them.
Make sure that your solution algorithm works for that dataset. Doing it that way means that you can work on the algorithm(s), and when testing you don’t waste time inputting data values. Just output your results using PRINT * (or WRITE(*, ...), as I do from force of habit having used compilers that didn’t support PRINT).
When you have been able to get sensible results, alter the dataset, and test that. Repeat until you are satisfied. Then, add the necessary code to read your sample dataset from a file. Check the values in the file for validity and completeness, but don’t bother with any fancy coding to do with data file selection, because that pre-empts Stage II. Then join in with the ten steps as listed above. You will, of course, need to remove your data initialisation statements or subroutine, but don’t discard it. There will come a time when you need a standard dataset for quality control purposes. I have a standard dataset that I can use as a template from which to develop my data models as it is easier to start from a complete dataset and then modify it than it is to start from scratch.
It has never been my intention to cover every facility offered by ClearWin+, but rather to get you, the reader, started with the system. What is my intention, however, is to give you an order in which to implement facilities that always gives you the impression (correctly) that you are making progress, so that you don’t just give up. I hope that in following my sequence you won’t get to the point of simply not knowing what to do next.
However, if you do follow my sequence, you will (hopefully) get to the stage where you are developing a program that you have already given its own Windows ‘look and feel’, and in the course of which you have gained familiarity with the documentation for the system. Then, you can root out and use those extra facilities as and when you need them. If my experience counts for anything it is that the existing documentation is not, and perhaps was never intended to be, a self-instruction manual.
I also don’t recommend reading this book from start to finish before embarking on your quest. Instead, I recommend reading at most a chapter at a time, then follow the steps I have suggested for your existing Fortran program. In that way you will consolidate your knowledge in what I hope are digestible chunks.
I have tried to write in a ‘chatty’ style, and sometimes about my own experiences, so that you realise that I make no claims to be the arbiter of all knowledge, but instead present my views from the perspective of someone who has been there before, made lots of mistakes and gone down many blind alleys, before arriving at something that ultimately works. It is my hope that you don’t make as many mistakes as I have, or if you do, don’t become disheartened and quit, but instead, learn from them.
FORTRAN and the ART of Windows Programming, Copyright © Eddie Bromhead, 2023.