function data2stl(x,y,z,g,isoc_val,fname)
% Authors: K. Taira, Y. Sun, D. Canuto
% Florida State University, Nov 14, 2016
% === inputs === 
%   (x,y,z) = spatial grid points (e.g., meshgrid format)
%   g = variable of interest defined over (x,y,z)
%   isoc_val = isocontour value used to create structure
%   fname = output STL file name (.stl will be appended)
% === output ===
%   fname.stl = STL format file (for 3D printing)

% output faces (f) and vertices (v)
[f,v] = isosurface(x,y,z,g,isoc_val); 
% write to STL file; need stlwrite.m from Matlab file exchange
stlwrite([fname,'.stl'],f,v)