Changeset 27030
- Timestamp:
- 05/31/22 06:02:41 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/model.m
r26831 r27030 1752 1752 1753 1753 end % }}} 1754 function savemodeljs(md,modelname,websiteroot,varargin) % {{{ 1755 1756 %the goal of this routine is to save the model as a javascript array that can be included in any html 1757 %file: 1758 1759 options=pairoptions(varargin{:}); 1760 optimization=getfieldvalue(options,'optimize',0); 1761 1762 1763 %disp: 1764 disp(['saving model ''' modelname ''' in file ' websiteroot '/js/' modelname '.js']); 1765 1766 %open file for writing and declare the model: 1767 fid=fopen([websiteroot '/js/' modelname '.js'],'w'); 1768 fprintf(fid,'var %s=new model();\n',modelname); 1769 1770 %now go through all the classes and fwrite all the corresponding fields: 1771 1772 fields=properties('model'); 1754 function saveasstruct(md,filename) % {{{ 1755 1756 fields=sort(properties('model')); %sort fields so that comparison of binary files is easier 1757 disp('Converting all model fields to struct...'); 1758 warning off MATLAB:structOnObject 1773 1759 for i=1:length(fields), 1774 1760 field=fields{i}; 1775 1776 %Some properties do not need to be saved 1777 if ismember(field,{'results','cluster' }), 1778 continue; 1779 end 1780 1781 %some optimization: 1782 if optimization==1, 1783 %optimize for plotting only: 1784 if ~ismember(field,{'geometry','mesh','mask'}), 1785 continue; 1786 end 1787 end 1788 1789 %Check that current field is an object 1790 if ~isobject(md.(field)) 1791 error(['field ''' char(field) ''' is not an object']); 1792 end 1793 1794 %savemodeljs for current object 1795 %disp(['javascript saving ' field '...']); 1796 savemodeljs(md.(field),fid,modelname); 1797 end 1798 1799 %done, close file: 1800 fclose(fid); 1761 md.(field) = struct(md.(field)); 1762 end 1763 disp('Converting model to struct...'); 1764 md=struct(md); 1765 warning on MATLAB:structOnObject 1766 disp(['Saving as ' filename '...']); 1767 save(filename,'md','-v7.3') 1768 end % }}} 1769 function savemodeljs(md,modelname,websiteroot,varargin) % {{{ 1770 1771 %the goal of this routine is to save the model as a javascript array that can be included in any html 1772 %file: 1773 1774 options=pairoptions(varargin{:}); 1775 optimization=getfieldvalue(options,'optimize',0); 1776 1777 1778 %disp: 1779 disp(['saving model ''' modelname ''' in file ' websiteroot '/js/' modelname '.js']); 1780 1781 %open file for writing and declare the model: 1782 fid=fopen([websiteroot '/js/' modelname '.js'],'w'); 1783 fprintf(fid,'var %s=new model();\n',modelname); 1784 1785 %now go through all the classes and fwrite all the corresponding fields: 1786 1787 fields=properties('model'); 1788 for i=1:length(fields), 1789 field=fields{i}; 1790 1791 %Some properties do not need to be saved 1792 if ismember(field,{'results','cluster' }), 1793 continue; 1801 1794 end 1795 1796 %some optimization: 1797 if optimization==1, 1798 %optimize for plotting only: 1799 if ~ismember(field,{'geometry','mesh','mask'}), 1800 continue; 1801 end 1802 end 1803 1804 %Check that current field is an object 1805 if ~isobject(md.(field)) 1806 error(['field ''' char(field) ''' is not an object']); 1807 end 1808 1809 %savemodeljs for current object 1810 %disp(['javascript saving ' field '...']); 1811 savemodeljs(md.(field),fid,modelname); 1802 1812 end 1803 end 1813 1814 %done, close file: 1815 fclose(fid); 1816 end 1817 end 1818 end
Note:
See TracChangeset
for help on using the changeset viewer.