LG 9-26

Bio: Anatoly Krivitsky, has a PhD in computer science and more then 25 years of experience
working in the IT fiel...
Virtualization is great, however, it may not fit your application needs in terms of performance (some
    computer power i...
made IDE. Also, if VS.Net 2003 or 2005 is a part of the standard PC software image in your organization
(i.e., if there is...
technology are either free or require no additional investments, which makes the described migration

Imports System.Text

Module Module1

    Sub Main()
        Dim myProcess As Process = New Process()
        Dim errors As...
        Dim myNotepad As Process = New Process()
        myNotepad.StartInfo.FileName = "notepad"
Upcoming SlideShare
Loading in...5

Header: On a Budget


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Header: On a Budget

  1. 1. LG 9-26 Bio: Anatoly Krivitsky, has a PhD in computer science and more then 25 years of experience working in the IT field. He is the author of 25 published papers and books and 5 patents in computer science. akrivitsky@yahoo.com Header: On a Budget Migration of Legacy Scientific and Engineering Applications: From mainframes to PCs with open source technologies by Anatoly Krivitsky, Ph.D. There is a market from which a history of computers began – a market of numerical simulations for scientific and engineering applications. Note that these applications usually deal with a high number of mathematical calculations that are impossible without a computer. Historically, this was what provoked the computer’s invention. Also, the main purpose of software for this market is to provide results in a reasonable amount of time. Despite a long history, this market is alive and well, and it will be for some time. Consider, for instance, the following fields of numerical simulations: steam turbines (which are core elements of most conventional and nuclear power plants that supply electricity), so-called “green energy” (wind, waves and solar energy) facilities, blood flow in the human body, elementary particles of which our universe consists, the universe itself, environmental issues (including pollution simulations and simulations of ecosystems), etc. An important part of this market is the approximation of complex dependencies in order to speed up computations while maintaining accuracy (see for examples the books and articles listed in the resources section at the end of the article). Many applications for this market were developed for decades using mainframes and the programming languages available at the time. Many of these applications were written with various versions of Fortran. Let us note that modern PCs (personal computers) are relatively cheap and provide us with the same computational power of the mainframes of a not-so-distant past. Therefore, if you’re happy with your legacy mainframe scientific or engineering applications, it’s a good time to make the transition from mainframes to PCs to save money on mainframe time cost. There are a good many commercial Fortran compilers for PCs (consider Intel Fortran compiler). You may want to measure the performance of a compiler by benchmarks that suit your specific needs. (More information on benchmarks can be found in my article in JDJ, Vol. 10, issue 5, 2005, listed in the resources section or online at http://jdj.sys-con.com/read/83099.htm.) However, to save money, one should consider using open source compilers. It is well known that GCC (GNU Compiler Collection) compilers (including G77 Fortran) are mature and have reasonable performance. Besides, if you use a G77, the number of changes needed in your mainframe Fortran code is relatively small. On the other hand, there are a number of free editors that can be used for convenient editing of the source code. So you may want to implement a technology that will combine these editors and G77 in a sort of self-made IDE (integrated development environment). Operating System for a PC Let’s face it, most modern PCs come with Windows pre-installed. Most manufacturers of peripheral devices (printers, external HDDs, etc.) provide drivers for Windows XP. If you bought your PC with Windows XP pre-installed, you may not want to waste time installing another operating system (say various Linux or FreeBSD distributions). However, GCC works really well on Linux. Here are a few ways to solve this problem: • You may want to use virtualization. (See my articles about using Windows XP/Linux virtualization for compilations: from LinuxWorld Magazine, Vol. 4, issue 5, 2006, available online at http://jdj.sys- con.com/read/219966.htm, and from Enterprise Open Source Magaine, Vol. 4, issue 8, 2006.) Anatoly Krivitsky, Ph.D. Page 1 of 6
  2. 2. Virtualization is great, however, it may not fit your application needs in terms of performance (some computer power is needed to support virtualization). • You may use CygWin (emulation of Unix environment) under Windows XP. How to create self-made IDEs using free open source technologies with CygWin under Windows XP will be described later in this article as a part of the migration from mainframes to PCs. Source Code Migration from Mainframes to PCs There is a cheap tool that allows great simplification of the migration in question - Quick3270 - most likely it’s already used in your organization. If it is not used, I strongly recommend buying and implementing it. The tool is available from http://www.dn-computing.com/ where you can find information on pricing, etc. The migration under Quick3270 is a breeze. All you need to do is the following: • Split your ISPF screen (if your are unfamiliar with ISPF, TSO and other mainframe stuff, many more resources can be found at www.ibm.com) using a corresponding command (most likely it will be F2). You may want to double-check with mainframe developers/administrators from your organization to be sure of the command. • In one part of the split screen, go to “Command” TSO option (say it will be 7). Again, check the actual number for the option described above. • From this part of the screen, select appropriate options for file transformation from the Quick3270 menu. When the “File Transfer” dialog appears, put the fully qualified name of a member of your source code library in single quotes. For example, ‘MYLEVEL1NAME.MYLEVEL2NAME.MYLIBRARYNAME(MYFTNMEMBER)’. Of course, in real life, you should use real names. You may want to go to the corresponding library within the second part of the split screen, copy said name into the clipboard, and paste it in single quotes to save yourself some typing. • Put the needed file name on your PC under “PC file name” without quotes - for example, C:FromMainframeprogram1.f. • Hit “Receive File” button. That’s it. Now, any needed file will be transferred from the mainframe to the PC. CygWin Installation The process is described in numerous Internet resources. However, there are several things not articulated in known sources that could save you a lot of time if properly implemented: • For readers in the USA, a reasonable choice of CygWin mirrors/ftp sites is as follows: http://cygwin.elite-systems.org/ for a mirror and ftp://mirrors.kernel.org for an ftp site. • When considering what to install, it would be smart to keep in mind that these days HDD drives are cheap (less then $1 per Gigabyte at the time of writing). So if you care about the completeness of your CygWin distribution - and saving money by eliminating unnecessary findings of missing CygWin parts - you may want to install the whole thing. Installation of the whole CygWin is very simple. There is a figure that resembles a circle with two arrows, located next to every category within the “CygWin setup select – packages” window of the CygWin setup program. Clicking on this figure, which is located near “All,” will provide the needed installation. On average (the specific time will depend on your connection and PC), it takes about an hour to complete the installation. • After the installation, you will most likely need the following CygWin related shortcuts on your desktop: CygWin shortcut, start X server shortcut (these two are likely to be provided by the setup program), and X term shortcut. To place the X term shortcut on a desktop, go to Start | All programs | GygWin X, right-click on the X term icon, and select Send to | Desktop. Note that the X server and X terminal from CygWin will not be used further in this article. However, you may find them useful for your other development needs. Making Your Own IDE with G77 and Editors Without Additional Investments There are many free and/or open source editors that are suited for source code editing. However, you may find it convenient to use Crimson, available for free from http://www.crimsoneditor.com. Crimson has support for Fortran syntax highlighting, and, as you will see in this section, it can be used as part of a self- Anatoly Krivitsky, Ph.D. Page 2 of 6
  3. 3. made IDE. Also, if VS.Net 2003 or 2005 is a part of the standard PC software image in your organization (i.e., if there is no need for additional investments in VS.Net 2005 for the migration in question), why not use its highly customizable editor? Please see my article from Enterprise Open Source Magazine (Vol. 4, issue 8, 2006) for an analysis on how a typical IDE works. With help from the article as well as the aforementioned editors, you’ll be able to build your own IDE. The program in question will allow you to call G77 within the CygWin environment right from the editor (likewise you can call a native or external compiler from the IDE), and see the results within Notepad (likewise you can see the results in the designated IDE area). The program is written with VB.Net (compatible with VB.Net 2003 and 2005); VB.Net 2005 professional edition was used to develop and compile the program. However, nothing will prevent you from compiling it using the free Visual Basic 2005 express edition. To call G77 from Crimson (or VS.Net if it is already installed on your PC), the program emulates the user who is typing within CygWin by doing the following: • Starting CygWin • Sending appropriate keystrokes to CygWin for calling G77 • Redirecting G77 standard output and errors (if any) into special variables • Closing CygWin • Calling Notepad and filling it out with G77 errors (if any) The program will be started from the command line when appropriate points are selected from the menu within Crimson or VS.Net 2005 (please see above for a similar activity with regard to the calling of a native or external compiler from the IDE). Debugging note: G77 errors (if any) are written in a special file within the directory from which the program was called; after you make sure the program works, you may want to delete or comment out the related block of code. Similar functionality probably can be achieved with other languages (for instance, with Java using java.awt.Robot for sending keys and using other means to redirect G77 standard output and errors, etc.), but as we work under Windows XP within this article, you may find that using VB.Net is more convenient. The source code for the program is given in Listing 1. There are several hard-coded values that are used within the program. Most will be correct (for instance, the hard-coded location for CygWin), but others will need to be adjusted (like the name of your CygWin home directory). It is assumed that the code (received from the mainframe as described earlier) will be placed under any subdirectory of your CygWin home directory. This assumption works for me. However, the program can easily be adjusted, if needed, to work with a directory from any reasonable location. (Please keep in mind that CygWin, like any software, has its own limitations.) Use of the program within Crimson and VS.Net 2005 is simple and illustrated in Figures 1 and 2. <INSERT FIGURES 1 & 2>What you need to do is put the executable file of the program (the name used in this article is: SendingKeysToCygwinAndRedirectOut.exe) under some directory of your choice that you may want to include in Windows XP path (in this article, it is C:G77Start). Next, include the needed calls in your Tools | Conf. User tools for Crimson (See Figure 1) or Tools | External tools for VS.Net 2005 (See Figure 2). In this article, the menu text for the call is G77start. At this point, you may call G77 within CygWin from Crimson or from VS.Net 2005 by selecting Tools | G77start, and you will see the results in Notepad. To test this technique, you may use my file for performance measurement (dwhet.f from http://www.myjavaserver.com/~akrivitsky/G77.html). First, use it “as is” within Crimson or VS.Net 2005. In this case, no meaningful error message will be returned. Second, copy this file to dwhet_error.f, and, within Crimson or VS.Net 2005, type the word “error” in the place of your choice. In this case, you will obtain the appropriate error message from G77. Note that similar techniques can be applied to programs written in C, or any other legacy application language, with appropriate compilers that exist both in mainframes and CygWin. What Was Done The described technology that is based on free and open sourced CygWin will allow (in many cases) the migration of legacy applications from mainframes to PCs. The only thing you need to purchase is Quick327- which is very cheap – if you don’t have it installed already. All other products used for the Anatoly Krivitsky, Ph.D. Page 3 of 6
  4. 4. technology are either free or require no additional investments, which makes the described migration budget-friendly. Resources • A.S. Krivitskii, et. al. (1995). "A System of Equations for Calculating on a Personal Computer the Thermodynamic Properties of Water and Steam on the Saturation Curve." Thermal Engineering. Vol. 42, no. 12. • A.S. Krivitsky, et. al. (1996). "Tables of Thermodynamic Derivatives for Water and Steam." Electrogorsk Research and Engineering Centre of Nuclear Power Plants. • A. Krivitsky. (2005). “Remote Benchmarking with Servlets and JSF." JDJ. Vol.10, issue 5. • A. Krivitsky. (2006). "Running Fedora Core 5 Under Windows XP - Tips and Tricks." LinuxWorld. Vol. 4, issue 5. • A. Krivitsky." (2006). “The Best of Both Worlds: Debugging Linux/Unix code using Windows XP software development.” Enterprise OpenSource. Vol. 4, issue 8. • My Web site: http://www.myjavaserver.com/~akrivitsky/. Listing 1. Module1.vb ' Copyright (c) 2006 Anatoly S. Krivitsky, PhD. ' All rights reserved. ' Conditional permission for free use of the ' code. ' As soon as above copyright notes are ' mentioned, ' the author grants a permission to any person ' or organization ' to use, distribute and publish this code for ' free. ' Questions and comments may be directed to the ' author at ' akrivitsky@yahoo.com and akrivitsky@gmail.com. ' Disclaimer of Liability ' The user assumes all responsibility ' and risk for the use of this code "as is". ' There is no warranty of any kind associated ' with the code. ' Under no circumstances, ' including negligence, ' shall the author be liable ' for any DIRECT, INDIRECT, INCIDENTAL, SPECIAL ' or CONSEQUENTIAL ' DAMAGES, ' or LOST PROFITS that result from the use or ' inability to use the ' code. ' Nor shall the author be liable for any such ' damages including, ' but not limited to, reliance by any person on ' any ' information obtained with the code Imports System.Windows.Forms Imports System.Diagnostics Imports System.IO Anatoly Krivitsky, Ph.D. Page 4 of 6
  5. 5. Imports System.Text Module Module1 Sub Main() Dim myProcess As Process = New Process() Dim errors As String Dim psi As New _ System.Diagnostics.ProcessStartInfo("C:cygwincygwin.bat") Dim arguments As [String]() = Environment.GetCommandLineArgs() Dim FileName As String = arguments(1) Dim pathToDirectory As String = arguments(2) Console.WriteLine("File Name = " & FileName) Console.WriteLine("pathToDirectory = " & pathToDirectory) Dim split As String() = Nothing Dim delimStr As String = ":." Dim delimiter As Char() = delimStr.ToCharArray() split = pathToDirectory.Split(delimiter) Dim directoryName As String = split(split.Length - 1) Dim CygwinCdCommand As String = "cd /home/Anatoly/" & _ directoryName & "{ENTER}" split = FileName.Split(delimiter) Dim FileNameWithoutExtension = split(0) Dim g77Call As String = "g77 -O " & _ FileName & " -o " & FileNameWithoutExtension & ".exe{ENTER}" psi.RedirectStandardOutput = True psi.RedirectStandardError = True psi.WindowStyle = ProcessWindowStyle.Hidden psi.UseShellExecute = False myProcess = System.Diagnostics.Process.Start(psi) Dim myOutput As System.IO.StreamReader _ = myProcess.StandardOutput Dim g77Errors As System.IO.StreamReader _ = myProcess.StandardError If myProcess.Responding Then System.Windows.Forms.SendKeys.SendWait( _ CygwinCdCommand) System.Windows.Forms.SendKeys.SendWait( _ g77Call) System.Windows.Forms.SendKeys.SendWait( _ "exit{ENTER}") errors = g77Errors.ReadToEnd() Dim pathTog77Output As String pathTog77Output = pathToDirectory & "g77Output.txt" If File.Exists(pathTog77Output) Then File.Delete(pathTog77Output) End If Console.WriteLine("pathTog77Output = " & pathTog77Output) Dim sw As StreamWriter = New StreamWriter(pathTog77Output) sw.Write(errors) sw.Flush() sw.Close() Else myProcess.Kill() End If myProcess.WaitForExit(2000) Anatoly Krivitsky, Ph.D. Page 5 of 6
  6. 6. myProcess.Close() Dim myNotepad As Process = New Process() myNotepad.StartInfo.FileName = "notepad" myNotepad.StartInfo.WindowStyle = _ System.Diagnostics.ProcessWindowStyle.Normal myNotepad.EnableRaisingEvents = True myNotepad.Start() myNotepad.WaitForInputIdle(1000) If myNotepad.Responding Then System.Windows.Forms.SendKeys.SendWait( _ errors) Else myNotepad.Kill() End If End Sub End Module Anatoly Krivitsky, Ph.D. Page 6 of 6