import etopo_class; load("zegraph", "matrix.dll", "hdf.dll"); // graph objects xmin = 90; xmax = 130; ymin = 20; ymax = 60; zmin = 0; zmax = 20; grid = 5; width = 800; height = 600; render = zegraph("render"); render:size(width, height); scene = zegraph("scene"); scene:viewport(0, 0, width, height); render:add(scene); root = zegraph("node"); scene:root(root); light = zegraph("light"); light:ambient(0.7, 0.7, 0.7); light:position(1, 0, 1); root:rotatez(-25); root:rotatex(-60); root:translate(0, 30, 0); plot = zegraph("plot"); font = zegraph("font"); plot:font(font, 10); plot:scale(.5, .5, .4); axis = plot:xaxis(0, -1, -1); axis:title("Longitude"); axis:range(xmin, xmax); axis:tickmarks(xmin, grid, 0); axis:tickdigits(0); axis = plot:yaxis(1, 0, -1); axis:title("Latitude"); axis:range(ymin, ymax); axis:tickmarks(ymin, grid, 0); axis:tickdigits(0); axis = plot:zaxis(1, 1, 0); axis:title("Altitude [km]"); axis:range(0, 20); axis:tickmarks(2, 2, 0); axis:tickdigits(0); root:add(light, plot); // the main trajectory line lxyz = zegraph("vertex"); line = zegraph("line"); line:solid(1.5); line:color(1,1,1); line:vertex(lxyz); lnor = zegraph("vertex"); line:normal(lnor); plot:add(line); // particle ball = zegraph("polygon"); ball:sphere(3, 2); ball:color(.8, .8, 0); // colorbar cbar = zegraph("colorbar"); r = [0.0, 0.0, 0,0, 0.0, 0.5, 0.9, 1.0, 1.0, 0.8]; g = [0.0, 0.0, 0.2, 0.6, 0.5, 0.9, 1.0, 1.0, 0.5]; b = [0.5, 0.5, 0.0, 0.0, 0.0, 1.0, 1.0, 0.9, 0.0]; c = [-.1, -.01, 0, .01, 1, 2, 3, 4, 5 ]; n = size(c); for (i = 0; i < n; i++) { cbar:add(r[i], g[i], b[i], c[i]); } // topograph data E = new Etopo; E->open("data/etopo.h5"); Z = matrix("double"); Z:clone(E->get("etopo15", xmin, xmax, ymin, ymax)); Z[Z<0] = -100; Z /= 1000.0; [m, n] = Z:size(); pz = Z:ptr(); Y = matrix("double", 1, m); Y:fill(ymin, E->c_grid); py = Y:ptr(); X = matrix("double", 1, n); X:fill(xmin, E->c_grid); px = X:ptr(); surface = zegraph("polygon"); vert = surface:mesh(pz[0], px[0], px[1], py[0], py[1]); surface:color(vert:color(cbar)); norm = vert:normal(4); surface:normal(norm); surface:fill(1); plot:add(surface); // read initial time and position f = open("tmp/test500.csv", "r"); s = read(f); a = tokenize(s, ","); nhr = integer(a[1]); s = read(f); a = tokenize(s, ","); np = integer(a[0]); x = real(a[1]); y = real(a[2]); z = real(a[3])/1000.0 + surface_height(x, y); // the first frame lxyz:add(x, y, z); lnor:add(1, 1, 1); plot:anchor(ball, x, y, z); //show(); return; render:togifa("metex-anim3d3.gif", 60); for (i = 0; i < nhr; i++) { plot:clear(); plot:add(line, surface); for (j = 0; j < np; j++) { s = read(f); a = tokenize(s, ","); x = real(a[3]); y = real(a[4]); z = real(a[5])/1000.0 + surface_height(x, y); plot:anchor(ball, x, y, z); if (j == 0) { lxyz:add(x, y, z); lnor:add(1, 1, 1); } } render:togifa("add", 60); csv(i); } plot:clear(); render:togifa("end", 100); function tokenize(str, del) { ret = []; len = size(del); k = 0; k1 = 0; k2 = find(str, del, k1); while (k2 > 0) { if (k2 > k1) { ret[k] = substr(str, k1, k2-k1); k++; } k1 = k2 + len; k2 = find(str, del, k1); } len = size(str); if (len > k1) ret[k] = substr(str, k1, len); return ret; } function show() { window(width, height, "show_callback"); function show_callback(hwnd, msg, wp, hwp, lwp, lp, hlp, llp) { if (msg == "PAINT") { render:towindow(hwnd); } else if (msg == "SIZE") { hide(); } } } function surface_height(x, y) { [m, n] = Z:size(); for (i = 0; i < m-1; i++) { if (X[i] > x) break; } for (j = 0; j < n-1; j++) { if (Y[j] > y) break; } return Z[i,j]; }