Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

# A multi conditional goto-like implementation in Matlab 1.0

Date Added: July 14, 2013  |  Visits: 190

1. IntroductionEnough debate has been devoted from time to time to the luck of "go to" in Matlab.Ourselves being somewhat devoted followers of structured programming, we rarely useit in our FORTRAN applications and implementations. However, one cannot help thatsometimes there exists this need of a "quick and dirty" redirection within a code.Nevertheless, we are fully aware that a "go to" implementation in Matlab would leadto a lot of unacceptable coding. The "for entertaining purposes" "go to" implementationof Husam Aldahiyat as presented in File Exchange of Mathworks triggered us into tryingit in a long waiting FORTRAN to Matlab conversion of a subroutine, that needs to performa set of conditional "go tos". This "go to" did not actually work for us. Its mainproblem is that it is designed to handle "go to"s that do not transfer control to other.m code for the same application. Consequently, we decided that it was high time to tryand implement our FORTRAN subroutine with conditional "go tos" in Matlab, using structuredprogramming.2. Our conditional "go to" problemWe need to guide our code, so that to proceed to a series of different steps, dependingon choices. As it happens our choices are quite many. In order to differentiate thesechoices from each other we gave each one a unique number between 0 and 63. It is obviousthat each choice number can be a result of summing up 0, 1, 2, 4, 8, 16 and 32 orequivalently 0, 2^0, 2^1, 2^2, 2^3, 2^4, and 2^5. In our code if sum = 0 nothing happens,if sum = 1 then task#1 is performed, if sum = 2 then task#2 is performed, if sum = 4 thentask#4 is perforned, if sum = 8 then task#8 is performed, if sum = 16 then task#16 isperformed and finally if sum = 32 no specific task is assigned and this choice numberis reserved for provisional use. In other words our code would not exploit all sum valuesavailable. The actual implementation is useful for the calculation of chosen thermophysicalproperties out of a set of available equations for water. To our best knowledge theoriginal of this implementation is to be found in:Hendricks R.C., Peller R.C., Baron A.K., "WASP - A Flexible FORTRAN IV Computer Code ofCalculating Water and Steam Properties", Report No. NASA Technical Note TN D-7391, NASA,Washington D.C. 20546, USA, 1973.3. The FORTRAN implementationIt can be found in the .zip file as total.f subroutine4. The Matlab implementationIt can be found in the .zip file as total.m function5. Some discussionIt was not that straightforward but it is evident that a FORTRAN code with such acomplicated set of conditional "go tos" invoking some programming decisions, could beimplemented in Matlab as well. In this particular case the JPCi variables which governthe conditional choice decisions are included in the m code function, while they arecommunicated to the FORTRAN subroutine, using COMMON blocks calling a BLOCK DATA subprogram.Furthermore, attention should be paid that the implementation presented is based in a systemof "functions that call other functions". Such a programming environment in Matlab calls forusing only static variables that should be communicated "to and from" as inputs and outputsof functions and not as parts of global scripts.S.T. Pachitsas, Student of Mechanical EngineeringN.P. Petropoulos, LecturerNuclear Engineering DepartmentSchool of Mechanical EngineeringNational Technical University of Athens15780 Athens, GREECE

 Requirements: No special requirements Platforms: Matlab Keyword: Baron,  Calculating,  Computer,  D7391,  Flexible,  Properties,  Report,  Steam,  Technical,  Water Users rating: 0/10