back to my top page



For those who love doing it yourself.

A FORTRAN 77 code (pixelfrt.for or pixelfrt_1.for) will generate PPM or BMP files. One purpose of codes like this is to finally make movies. Some good software such as tmpgenc on MS Windows can make mpeg files from BMP files (and this software well supports other formats like JPEG etc.), and on Linux system ppmtompeg can do so from PPM files. Most of movies and animations listed in my gallery page were made in these ways.

Why PPM and BMP ?

Both are of very simple format and widely used. Popularity greatly helps us when distributing outcomes to other people. Simplicity helps and encourages us when getting started, especially with Fortran that is not exactly versatile or flexible. The Fortran code linked above can generate one of three types of image format; P6 (binary, 24-bit color depth) and P3 (text-based, any color depth) of PPM format and Microsoft BMP format (here only 24-bit depth).
   PPM format is a standard graphic format on Linux / Unix, and lots of image viewers (like display of ImageMagick, and xv) and command-line conversion tools (such as netpbm toolkit package and convert of ImageMagick) support this format. On MS Windows system, many software such as IrfanView can display PPM files and convert them to other formats.
   BMP format is very commonly used. There are a few versions of BMP format. This Fortran code will generate one of them; uncompressed and in a 24-bit depth (8 bits for each primary color). The BMP format requires that the horizontal pixel size must be a multiple of 4. If the horizontal pixel size you specify is not a multiple of 4, some "padding" is needed to make the apparent horizontal size a multiple of 4. For simplicity, my code does not handle this rule.

What this code will do.

This Fortran code will generate PPM or BMP files named with three-digit serial number (smpl001.ppm, smpl002.ppm .....), and the first one must be
if you set ichoice = 0 in subroutine mkdata, or
otherwise.
By setting the integer ipixout in a subroutine pixout, you can choose the format of output image file;
ipixout=1PPM-P6 (binary/raw)
ipixout=2PPM-P3 (plain text; this is a safe choice)
otherwise BMP (binary/raw; 24-bit color depth, uncompressed)
An mpeg movie (ormp4 format) here was made by following three lines (on Linux):
ifort pixelfrt.for ; ./a.out ; ppmtompeg pixelfrt.par,
here, pixelfrt.par is a parameter file that contains minimum information for ppmtompeg to do things. It may not be difficult to edit/modify these files for your own purposes.

Notes :

  1. Some mpeg encoder may require that both horizontal and vertical pixel sizes should be multiples of 16 (or 8). Also, if you choose BMP as the output format, the horizontal pixel number (given to a parameter ihpixf) must be a multiple of 4.
  2. You can freely modify the subroutine mkbitmap so that you can make your own images and then movies. It must be fun. Enjoy, and good luck !
  3. This code assumes the color depth of three primary colors (red, green, blue) is 256, or 8-bit, each. That is, color value is integer and ranges from 0 to 255. This constraint matches with that of PPM-P6 and BMP format. Because the PPM-P3 format does not have any color-depth limit, you may choose PPM-P3 if you really, really need color-depth greater than 256 for each color element.
  4. This program uses "$" in the I/O format field to indicate line continuation without any line break (CR or LF). This is from a good old DEC Fortran extension, and thus, may not be standard today. It is up to the compiler you are using whether this convention will be accepted or not. If you have a problem when compiling this code, choose PPM-P3 as output format by setting ipixout = 2 so that the I/O format statement will not use the character.
  5. Often a few of 256 characters are assigned to abnormalities such as NaN (not a number), +/-Inf (infinity), and "undefined". Under some debugging environments, the process will be terminated when the "abnormal" character is detected. This is normal. This code, the compiler, and the debug tool all do correctly what they are supposed to do.
  6. I have confirmed that this code can be successfully compiled and run through, with g77 version 3.4.2, gfortran version 4.2.0, and Intel Fortran version 9.1, 10.1 and 11.0 on Linux (Red Hat, version ?????), with Digital Fortran 5 on MS-DOS prompt of Windows 98SE, and with gfortran version 4.2.0(?) on command prompt of MS Windows Vista (64bit) SP2 and 7 SP1. No other combination had been tested at the time of creating this webpage (some 20+ years ago).
  7. Compiling with aggressive optimization options may result in some weird results. .... Good Luck!

last minor update/correction: August 2025
last major update: June 2007
first version: June 2002
K. Hayashi