Wednesday, December 28, 2016

Simple ISO images

So here I am, busy installing a new version of Linux Mint on Hal, my Linux Box.

To do this, I want to

  • Use GParted to reformat Hal's main disk, partitioning it the way I'd like it to be, and
  • Install Linux Mint from an ISO image.

In the old days this meant burning the ISO images for both GParted and Linux Mint to CDs or DVDs, as appropriate, and booting from the DVD drive. Now days we'd kind of like to have the images on a bootable USB drive. Especially GParted, which is useful for disk manipulation on any machine.

In general a big pain, as you have to remember the intricacies of the dd command.

When I was preparing for the update, listed all of the packages I'd installed using LMDE, my old Linux version. In there, I found something called mintstick, which is billed as Tool to write .img and .iso files to USB sticks. Can also format them.

And it works. Here's what you do

  1. Download your ISO image
  2. Insert your USB Stick
  3. Launch mintstick from a terminal window, using the command
    $ mintstick -m iso
  4. A window will pop up that looks something like this:
  5. On the left, use the dropdown menu to find your ISO image
  6. On the right, find the USB drive. (Make sure you get the right one.) You'll get something that looks like this:
  7. Click the Write button once it's highlighted.
  8. Wait for completion.
  9. Remove USB drive, and test on your target machine.

Supremely easy.

If you launch mintstick without the -m option you'll see it can do formatting, too, but I haven't looked into that. If you figure it out, leave a comment

Friday, November 25, 2016

Animation in PDF Presentations

I've been teaching an introductory class in physics and wanted to show my students how a standing wave gets constructed. The math & physics of it aren't too hard, really:

  • Start with a wave of a given frequency and wavelength, moving to to right.
  • Add a similar wave, with the same frequency, wavelength, and amplitude, except that it's moving to the left.
  • Add them together, and the combined waves will have a fixed points (nodes) every λ/2, where λ is the common wavelength.

The whole process looks something like this:

Animation of standing wave generated from two traveling waves

The problem is twofold. First, how to construct such an animation, and second, how to get it into a presentation.

To begin, we need to create a moving plot. It turns out that my favorite plotting program, gnuplot, is sort up to the task. Sort of. You'd expect that an animation algorithm would follow a set of rules like this:

  • Draw the picture at time t = 0
  • Increment the time a bit
  • Redraw the picture
  • Repeat after you've gone enough time steps to make you happy

Most codes implement this with some kind of a loop function. Gnuplot doesn't have a loop. However, a file can ask that the program reread the file. So an animation gnuplot script has features like this:

  #! /usr/bin/gnuplot     # Location of the source program YMMV
  dt = 0.01  # Length of a time step (choose yours to fit your needs)
  steps = 1000 # Number of steps you want
  i = 0 # this is a counter. It will be incremented one every time step
  load "realplot.gnu" # The actual plot file

realplot.gnu has the meat of the plotting program. For our traveling sine wave, it looks something like this:

  plot sin(x - i*dt) w l lt 1
  i = i + 1
  if (i < steps) reread

The code plots the curve at a given time, then increments the time by an amount i*dt, and asks to be reread. The program does this until the final time step is completed.

That's fine, this displays a very nice set of curves on the screen. However, it's nothing you can embed in a presentation. We need to save the output in some form. The best way to do this right now is using an animated GIF. Just like a movie, this is a collection of still images played at a pre-determined rate. Gnuplot has this capability. Adding these two lines changes the output from the screen to a file, in this case one named standing_waves.gif:

set term gif enhanced font 'arial' 16 animate delay 0.05 size 1000,750 nooptimize
set output "standing_waves.gif"

Most of this isn't hard to figure out:

  • set term gif tells gnuplot to make the output a gif file
  • enhanced font 'arial' 16 tells gnuplot to use its fancy plotting features, like printing Greek letters, and to use the Arial font with a font size of 16 (some platforms handle this better than others, more on that later)
  • animate delay 0.05 says to do animation, and play the frames 0.05 seconds apart (25 frames/second)
  • size 1000,750 is the size of the GIF, use what fits your presentation best
  • nooptimize is probably best. Optimization tries to save file space by only printing out the parts of a picture which are changing. This works on some platforms (my Linux box, my Mac at work), and fails on others (my Mac at home). So turning optimization off is probably best.
  • set output "standing_waves.gif" just tells gnuplot to output all these frames into a file.

For my project, I then stacked a bunch of plots together. At the risk of boring you, here's the whole thing in detail.

  • The main calling program sets up everything that is going to be fixed throughout the run, sets the time steps, etc. I'm doing this for a fixed number of periods, with a fixed number of time steps per period. For those who need to know, I set the wavelength to be 2π in arbitrary units, and the period to also be 2π, again in arbitrary units.
          #! /usr/bin/gnuplot
          # Settings which remain the same for all graphs
          set samples 2000
          unset ytics
          set xrange [0:7*pi]
          set yrange [-2.6:2.6]
          set xtics ("0" 0,"{/Symbol l}/2" pi,"{/Symbol l}" 2*pi, \
          "3{/Symbol l}/2" 3*pi, "2{/Symbol l}" 4*pi, \
          "5{/Symbol l}/2" 5*pi, "3{/Symbol l}" 6*pi, \
          "7{/Symbol l}/2" 7*pi)
          set arrow 1 from pi,graph 0 to pi,graph 1 nohead lt -1
          set arrow 2 from 2*pi,graph 0 to 2*pi,graph 1 nohead lt -1
          set arrow 3 from 3*pi,graph 0 to 3*pi,graph 1 nohead lt -1
          set arrow 4 from 4*pi,graph 0 to 4*pi,graph 1 nohead lt -1
          set arrow 5 from 5*pi,graph 0 to 5*pi,graph 1 nohead lt -1
          set arrow 6 from 6*pi,graph 0 to 6*pi,graph 1 nohead lt -1
          set key opaque
          set key reverse Left
          set xzeroaxis
          # Length of time used to plot each image, in periods
          periods = 1.00
          # Number of time steps for each period
          stepsperperiod = 50
          # Length of a time step
          dt = 2*pi/stepsperperiod
          # Total number of setps
          maxstep = periods*stepsperperiod
          set term gif enhanced font 'arial' 16 animate delay 0.05 size 1000,750 nooptimize
          set output "standing_waves.gif"
          # Remember to reset the time before running each plot
          i = 0
          load "rightsine.gnu"
          i= 0
          load "leftsine.gnu"
          i = 0
          load "bothsine.gnu"
          i = 0 load "constructive.gnu"
          i = 0 load "standing.gnu"
  • The remaining files have everything that changes in from one graphic to the next:
    A rightward traveling wave:
          set title "Wave Traveling to Right"
          plot sin(x-i*dt) t "sin ( k x - {/Symbol w} t)" w l lt rgb "red" lw 8
          i = i + 1
          if (i < maxstep) reread

    A leftward traveling wave:
          set title "Wave Traveling to Left"
          plot sin(x+i*dt) t "sin ( k x + {/Symbol w} t)" w l lt rgb "green" lw 8
          i = i + 1
          if (i < maxstep) reread

    Both waves together:
          set title "Both Waves"
          plot sin(x-i*dt) t "sin ( k x - {/Symbol w} t)" w l lt rgb "red" lw 8 , \
          sin(x+i*dt) t "sin ( k x + {/Symbol w} t)" w l lt rgb "green" lw 8
          i = i + 1
          if (i < maxstep) reread

    Both waves, along with the combined waveform:
          set title "Constructive Interference"
          plot sin(x-i*dt) t "sin ( k x - {/Symbol w} t)" w l lt rgb "red" lw 8 , \
          sin(x+i*dt) t "sin ( k x + {/Symbol w} t)" w l lt rgb "green" lw 8 , \
          sin(x-i*dt)+sin(x+i*dt) t "Combined Waves" w l lt rgb "blue" lw 8
          i = i + 1
          if (i < maxstep) reread

    Just the final wave:
          set title "Standing Wave"
          plot sin(x-i*dt)+sin(x+i*dt) t "Combined Waves" w l lt rgb "blue" lw 8
          i = i + 1
          if (i < maxstep) reread

The result is just what you see in the picture above.

Now we want to get this into a presentation. You can obviously embed this into a web page, as we're doing now. You can also put it into a Powerpoint presentation.

I, however, like to to my presentations in Beamer, a class in LaTeX which can produce fairly nice PDF files. The problem is that pdflatex, which takes LaTeX source and produces a PDF file, doesn't know nor care anything about GIFs, animated or not, so first we have to convert the GIF into something LaTeX can handle. The answer is the PNG format, which LaTeX loves. We simply use the convert command from ImageMagick:

  convert standing_waves.gif sw.png

and Whoa! we get a bunch of PNG files, conveniently labeled sw-0.png, sw-1.png, sw-2.png, ... , all the way up to, in this case, sw-249.png. To put them all back together we need to use the LaTeX package animate. A very simple Beamer file might look like this:


  % Allow animation
  \section{Standing Waves}

Most of this is pretty self-explanatory. I put the PNG files into a sub-directory, so they are png/sw-0.png, png/sw-1.png, ... . The {25} is the number of frames per second, since we lost that information from the GIF file. Keep running pdflatex on this until the errors stop, and voila, you've got a PDF presentation with animation. You'll have to use Adobe Reader to play it out, but hey, it works.

I've made all of this work on my LMDE box, and on two Macs, both using Macports to get the LaTeX and ImageMagick software. One of my Macs has a problem with the Greek fonts going into the GIF, and I don't know why. Also, gnuplot on the Mac is slightly different that my current Linux gnuplot, so I've written everything in a form that works on both machines. Finally, I've found that setting the font size works better on one of my Macs than it does on the other Mac or Linux box. I don't know why, but if I figure it out I'll let you know.

Sunday, March 13, 2016

Office 2007 With Wine

Every once in a while I need a real honest to Bill version of Microsoft Office. Not often, but it happens.

Now I have a three license copy of Microsoft Office Home and Student Edition, purchased back in the day when Child No. 1 had a Windows computer. That computer is long gone and replace by a Mac. I could install this copy on Hal's Windows partition, but that means I have to reboot and update Windows 7 every time I want to use the software. Irritating.

Then yesterday I was updating my Harmony Remote, and found that the update software would run on Linux under Wine. True, the fonts were ugly, but hey, it ran, and given that updating a remote is a run-up-and-down-the-stairs-10-times kind of thing, having one less step was a blessing.

Now I've tried Wine before, and never been all that happy with it. But maybe it's now good enough, so what the heck.

Having installed Wine via the Synaptic Package Manager, I went looking to see if there was help for the Office install on the internet, and lo and behold, I found How to Install Microsoft Office 2007 in Ubuntu (Under Wine).

What can I say? As I said, I already had Wine installed, so it was mostly point at setup.exe and click. What do you know, it worked, right down to finding the riched20.dll library and correcting it so that PowerPoint would run.

Now this was a copy of Office 2007, so it's a little out of date. Fortunately, Microsoft is providing extended support until 2017, so it's still viable. There was a problem, though: Microsoft Update wants to work with Internet Explorer, and I don't have that installed under Wine — in fact, I don't know if I can install it properly, and I'm not inclined to try. But you can go fetch the update directly from Microsoft. Just download, make it executable, and run it from a terminal, ignoring all of those evil looking error messages.

A couple of things: LMDE puts all of the Office Suite in the Other tab of the menu. You can edit the menu, make an M$Office tab to hold everything, and move it there. Second, dialog boxes often revert to Wine's font, which is horrible. But Office itself uses native Office fonts, which is what we really want.

Now I have no idea what happens if you try this with a newer version of Office. This works for Office 2007, which was written for Windows XP. If you get a newer version running, leave a comment.