; File: sphscan.pro
; Author: Erik Brisson

ntheta = 100
nphi   = 100
nentries = ntheta*nphi

dat = fltarr(3,nentries)

openr, 1, '../data/xyz.dat'
readf, 1, dat
close, 1

print, nentries

theta = dat(0,*)
phi = dat(1,*)
r = dat(2,*)

triangulate, theta, phi, tri

x = r * sin(phi) * cos(theta)
y = r * sin(phi) * sin(theta)
z = r * cos(phi)

print, "size(x)  = ", size(x)
print, "nentries = ", nentries

openw, 1, 'sphscan.obj'
printf, 1, "mtllib sph.mtl"
for i=0, nentries-1 do begin
    printf, 1, "v ", x(i), y(i), z(i)
end
printf, 1, "usemtl density_cmap"
for i=0, n_elements(tri)/3-1 do begin
;    printf, 1, "f ", tri(0,i)+1, tri(1,i)+1, tri(2,i)+1
    printf, 1, "f ", tri(1,i)+1, tri(0,i)+1, tri(2,i)+1
endfor
close, 1

end
