back to my top page



For those who love doing it yourself.

A example 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 and 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 (such as 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, of 24-bit color depth. When the horizontal pixel size is not multiple of 4, this format needs "padding" (filling with meaningless data so that apparent horizontal size will be multiple of 4). This rule was made possibly for faster loading and displaying. 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)
ipixout=2PPM-P3 (plain text; this is most compiler-friendly.)
otherwise BMP (binary; 24-bit color depth, uncompressed)
An mpeg movie (or mp4 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 will require that both horizontal and vertical pixel size should be multiple of 16 (or 8).
  2. When you choose to make BMP file (by setting ipixel = 3 or so), set the horizontal pixel number (ihpixf) to be multiple of 4. Otherwise, the generated files will not satisfy the BMP format. In other words, this Fortran code does not do "padding".
  3. I hope you will modify the lines in a subroutine mkbitmap so that you can make your own images and then movies. It must be fun even though it will cost you substantial labor and time. Enjoy, and good luck !
  4. 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.
  5. This program uses "$" in the I/O format field. Also some of I/O formats are first stored in character arrays then referred as "fmt=string variable". These are based on good old DEC Fortran extensions, and thus, may not be standard. Whether or not these lines can be handled will depend upon the compiler you use. If you have problem when compiling this code, choose PPM-P3 as output format by setting ipixout = 2, with which this code will become free from such non-standard features.
  6. Some system had assigned some of 256 characters to abnormalities such as NaN (not a number) or +/-Inf (infinity), or "undefined". Under some debugging environment, therefore, the process will be terminated when such "abnormal" numbers are detected. This is normal: Either of this code and the compiler does what each is supposed to do.
  7. 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 has been tested. Compiling with aggressive optimization options may result in some weird results. .... Good Luck !

last minor update: Jan. 2016
last major update: June 2007
first version: June 2002
K. Hayashi