Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).

(Read the definition of PPM file on Wikipedia.)




mata
void writeppm(name, r, g, b) {
	n = rows(r)
	p = cols(r)
	f = fopen(name, "w")
	fput(f, "P3")
	fput(f, strofreal(p) + " " + strofreal(n) + " 255")
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= p; j++) {
			fput(f, strofreal(r[i,j]) + " " + strofreal(g[i,j]) + " " + strofreal(b[i,j]))
		}
	}
	fclose(f)
}
 
r = J(1, 6, (0::5) * 51)
g = J(6, 1, (0..5) * 51)
b = J(6, 6, 255)
writeppm("image.ppm", r, g, b)
end