There is a command,
MAKE TERRAIN Terrain Number, Heightmap Filename
that makes a terrain matrix for you. It might not be what you need, but you could check it and see.
This code takes Green Gandalf's image and makes a terrain from it:
load image "purple.png",1
make terrain 1, "purple.png"
texture terrain 1,1
position terrain 1,0,0,0
position camera 50,30,-150
point camera 0,0,0
do
control camera using arrowkeys 0,.1,.1
loop
and this code makes an object out of the terrain. You can use most of the object commands on it, like saving it, moving it, etc.
ink rgb(255,255,255),0
for x = 0 to 10 step 10
for y = 0 to 100 step 10
box x,y,x+5,y+5
box x+5,y+5,x+10,y+10
next y
next x
get image 2,0,0,10,10
load image "purple.png",1
make object terrain 1
set terrain heightmap 1,"purple.png"
set terrain texture 1,2,2
set terrain scale 1,1,.25,1
build terrain 1
position object 1,0,0,0
position camera 50,50,-150
point camera 0,0,0
do
control camera using arrowkeys 0,.1,.1
loop