| 1 | function export_gl(md,varargin)
 | 
|---|
| 2 | 
 | 
|---|
| 3 |         templist=plotoptions(varargin{:}); 
 | 
|---|
| 4 |         optionslist=templist.list;
 | 
|---|
| 5 |         options=optionslist{1};
 | 
|---|
| 6 |         options=checkplotoptions(md,options);
 | 
|---|
| 7 | 
 | 
|---|
| 8 |         %Setup unique directory in present dir: 
 | 
|---|
| 9 |         directory=getfieldvalue(options,'directory','./');
 | 
|---|
| 10 |         databasename=getfieldvalue(options,'database','webgl');
 | 
|---|
| 11 | 
 | 
|---|
| 12 |         %scaling factor: 
 | 
|---|
| 13 |         scaling_factor=getfieldvalue(options,'scaling_factor',50);
 | 
|---|
| 14 | 
 | 
|---|
| 15 |         %Deal with title: 
 | 
|---|
| 16 |         if exist(options,'title')
 | 
|---|
| 17 |                 title=getfieldvalue(options,'title');
 | 
|---|
| 18 |         else
 | 
|---|
| 19 |                 title='';
 | 
|---|
| 20 |         end
 | 
|---|
| 21 | 
 | 
|---|
| 22 |         %initialize model: 
 | 
|---|
| 23 |         model.title=title;
 | 
|---|
| 24 |         model.initialZoomFactor=getfieldvalue(options,'zoom',-.25);
 | 
|---|
| 25 | 
 | 
|---|
| 26 |         %Deal with contour {{{
 | 
|---|
| 27 | 
 | 
|---|
| 28 |         contour_lat=md.mesh.lat(md.mesh.segments(:,1));
 | 
|---|
| 29 |         contour_long=md.mesh.long(md.mesh.segments(:,1));
 | 
|---|
| 30 |         contour_surface=md.geometry.surface(md.mesh.segments(:,1));
 | 
|---|
| 31 | 
 | 
|---|
| 32 |         R=6371000*ones(length(contour_surface),1)+scaling_factor*contour_surface;
 | 
|---|
| 33 | 
 | 
|---|
| 34 |         contourx = R .* cosd(contour_lat) .* cosd(contour_long);
 | 
|---|
| 35 |         contoury = R .* cosd(contour_lat) .* sind(contour_long);
 | 
|---|
| 36 |         contourz = R .* sind(contour_lat);
 | 
|---|
| 37 | 
 | 
|---|
| 38 |         model.contourx=contourx;
 | 
|---|
| 39 |         model.contoury=contoury;
 | 
|---|
| 40 |         model.contourz=contourz;
 | 
|---|
| 41 | 
 | 
|---|
| 42 |         %}}}
 | 
|---|
| 43 | %Deal with mesh and results {{{
 | 
|---|
| 44 |         
 | 
|---|
| 45 |         
 | 
|---|
| 46 |         lat=md.mesh.lat;
 | 
|---|
| 47 |         long=md.mesh.long;
 | 
|---|
| 48 |         surface=md.geometry.surface;
 | 
|---|
| 49 |         numberofelements=md.mesh.numberofelements;
 | 
|---|
| 50 |         numberofvertices=md.mesh.numberofvertices;
 | 
|---|
| 51 | 
 | 
|---|
| 52 |         R=6371000*ones(numberofvertices,1)+scaling_factor*surface;
 | 
|---|
| 53 | 
 | 
|---|
| 54 |         x = R .* cosd(lat) .* cosd(long);
 | 
|---|
| 55 |         y = R .* cosd(lat) .* sind(long);
 | 
|---|
| 56 |         z = R .* sind(lat);
 | 
|---|
| 57 | 
 | 
|---|
| 58 | 
 | 
|---|
| 59 |         %Deal with triangulation: 
 | 
|---|
| 60 |         model.index=md.mesh.elements;
 | 
|---|
| 61 |         model.x=x;
 | 
|---|
| 62 |         model.y=y;
 | 
|---|
| 63 |         model.z=z;
 | 
|---|
| 64 |         model.surface=surface;
 | 
|---|
| 65 |         
 | 
|---|
| 66 |         %Deal with data: 
 | 
|---|
| 67 |         results=struct([]);
 | 
|---|
| 68 |         for i=1:length(optionslist),
 | 
|---|
| 69 |                 options=optionslist{i}; options=checkplotoptions(md,options);
 | 
|---|
| 70 |                 data=getfieldvalue(options,'data');
 | 
|---|
| 71 |                 results(i).data=data;
 | 
|---|
| 72 |                 results(i).caxis=getfieldvalue(options,'caxis',[min(data(:)) max(data(:))]);
 | 
|---|
| 73 | 
 | 
|---|
| 74 |                 label=getfieldvalue(options,'label','');
 | 
|---|
| 75 |                 if strcmpi(label,''),
 | 
|---|
| 76 |                         %create generic label: 
 | 
|---|
| 77 |                         label=['data' num2str(i)];
 | 
|---|
| 78 |                 end
 | 
|---|
| 79 |                 results(i).label=label;
 | 
|---|
| 80 | 
 | 
|---|
| 81 |                 shortlabel=getfieldvalue(options,'shortlabel','');
 | 
|---|
| 82 |                 if strcmpi(shortlabel,''),
 | 
|---|
| 83 |                         %create generic short label: 
 | 
|---|
| 84 |                         shortlabel=['data' num2str(i)];
 | 
|---|
| 85 |                 end
 | 
|---|
| 86 |                 results(i).shortlabel=shortlabel;
 | 
|---|
| 87 |                 
 | 
|---|
| 88 |                 if size(data,2)>1,
 | 
|---|
| 89 |                         time_range=getfieldvalue(options,'time_range',[0 100]);
 | 
|---|
| 90 |                         results(i).time_range=time_range;
 | 
|---|
| 91 |                 end
 | 
|---|
| 92 | 
 | 
|---|
| 93 |                 unit=getfieldvalue(options,'unit','');
 | 
|---|
| 94 |                 if strcmpi(unit,''),
 | 
|---|
| 95 |                         %create generic unit: 
 | 
|---|
| 96 |                         unit='SI';
 | 
|---|
| 97 |                 end
 | 
|---|
| 98 |                 results(i).unit=unit;
 | 
|---|
| 99 |         end
 | 
|---|
| 100 |         model.results=results;
 | 
|---|
| 101 |         
 | 
|---|
| 102 |         %Write model to javascript database file: 
 | 
|---|
| 103 |         writejsfile([directory databasename '.js'],model,databasename);
 | 
|---|
| 104 | %}}}
 | 
|---|