C. Keith Ray

C. Keith Ray writes about and develops software in multiple platforms and languages, including iOS® and Macintosh®.
Keith's Résumé (pdf)

Wednesday, April 17, 2019

Second Program

The University of Texas in Arlington kept its computers in the basement. Since a computer in 1981 weighed as much as a Chevy Impala, only the basement floor was strong enough to hold it. The basement wasn't damp and dark, it was brightly lit with fluorescent lights, dry, and over-air-conditioned. I was in a room adjacent to the computer. Ordinary students were not allowed in same room as the computer. I adjusted my shirt; sweat had formed between the time I got out of my car and into the basement. Normal for a Texas summer.

I was a student in the "Summer Sciences Institute in Physics" for high school students. An accelerated course, heavy on math. It was tough but fun. We were over-achievers from several high schools. We had been given access to this computer to analyze data from an experiment. 

I sat in an uncomfortable chair, at a plastic, faux-wood-topped table and wrote FORTRAN code by hand on paper, in pencil, because I would have to correct errors as I wrote and analyzed the problem and the code. I had a physics book, a book on FORTRAN, and a hand-out to refer to. It wasn't hard, but it was tedious. A few lines of that code looked like something like this:

        DO 20 J = 1, N
        SUM = SUM + SQR(X(J))
    20  CONTINUE

Then, sitting in front a punch-card writer, I typed in that code. One line of code per punch-card. Eventually, I held a short stack of punch-cards in my hand. With my pencil, I drew a diagonal line on the card edges so that, if I dropped the cards, I could could fairly easily get them back in order.

It was time to run the program. Trying to act nonchalant, I silently handed the deck of cards to the bored college student who was system operator for that lab. He dropped them into a card-reader and punched a button. Whirr-hiss-thump: the cards I had spent a half-hour typing were read by the computer in a second. He handed back my cards.

Fifteen minutes later, a printer the size of a dishwasher clattered, loud, even though it had a transparent cover. My name, and the results of my program, appeared on form-feed paper two feet wide, pre-printed with thick, light green, bands of color. The system operator tore off the pages and left them for me on a table.

It worked! A sophisticated electronic device had followed my instructions. That was my first program. Now I wanted to do something for fun. I wanted the computer to print out something visually interesting. Back to the table. I decided to print a sine wave. This computer system had no graphics, so I would have to print characters to form a picture. I decided to print a sine wave.

I wrote the code, typed it onto punch cards. To save time, I re-used several cards from my first program. Again, whirr-hiss-thump

My mouth was dry. We weren't supposed to be using the computer for fun. Would that college student know? I had an opened roll of Life-Savers in my pocket. I took it out, used my front teeth to free a cherry life-saver from the roll, and waited.

When I got the print-out, the output looked like this:

                           *
                                 *
                                      *
                                         *
                                          *
                                         *
                                      *
                                 *
                            *
                      *
               *
          *
     *
  *
 *
  *
     *
          *
               *
                     *
                            *
                                 *
                                      *
                                         *
                                          *
                                         *
                                      *
                                 *
                            *

I made art from math! I smiled to myself, packed up books and printouts, and went home.

* * *

This memory is from a long time ago, so I may have mis-remembered some details. If you want to see what an equivalent program in Python looks like, it follows here. On a Mac, run the Terminal application and type in the following:

python

This should appear:

Python 2.7.10 (default, Feb 22 2019, 21:17:52) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Type the following, including spaces:

import math
incr = math.pi / 10
x = 0.0
while x < math.pi * 4:
    x = x + incr
    y = math.sin(x) * 20.0 + 22.0
    print " " * math.trunc(y) + "*"

If nothing is happening, hit return again.

No comments:

Post a Comment