⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadxsil.m

📁 XMDS is a code generator that integrates equations. You write them down in human readable form in a
💻 M
📖 第 1 页 / 共 2 页
字号:
function loadxsil(fname)%%  Copyright (C) 2003-2004%%  Code contributed by Paul Cochrane%%  This file is part of xmds.% %  This program is free software; you can redistribute it and/or%  modify it under the terms of the GNU General Public License%  as published by the Free Software Foundation; either version 2%  of the License, or (at your option) any later version.%%  This program is distributed in the hope that it will be useful,%  but WITHOUT ANY WARRANTY; without even the implied warranty of%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%  GNU General Public License for more details.%%  You should have received a copy of the GNU General Public License%  along with this program; if not, write to the Free Software%  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.%% $Id: loadxsil.m,v 1.13 2004/10/21 09:39:40 paultcochrane Exp $disp('parsing xsil file')debug = 0;  % just a variable useful for testing stuff% open the xsil file for readingfp = fopen(fname,'r');if (fp == -1)  disp('cannot open xsil file')  disp('exiting...')  returnendbinaryFound = 0;singleFound = 0;samplesFound = 0;while 1  line = fgetl(fp);  % if we get to the end of the file, break out of loop  if ~isstr(line), break, end    while (isempty(findstr(line,'<XSIL')))    % look for format="binary" on same line as <output    outputFound = findstr(line, '<output');    indStart = findstr(line, 'format="binary"');    if (~isempty(outputFound) & ~isempty(indStart) & binaryFound == 0)      binaryFound = 1;      useBinary = 1;      %indEnd = findstr(line, '</binary_output>');      %binaryElement = line(indStart+15:indEnd-1);      %if (strcmp(binaryElement,'yes'))      %  useBinary = 1;      %elseif (strcmp(binaryElement,'no'))      %	useBinary = 0;      %end    end        % look for precision="single"  (double is the default)    indStart = findstr(line, 'precision="single"');    if (~isempty(outputFound) & ~isempty(indStart) & singleFound == 0)      singleFound = 1;      useDouble = 0;  % use single precision      %indEnd = findstr(line, '</use_double>');      %doubleElement = line(indStart+12:indEnd-1);      %if (strcmp(doubleElement,'yes'))      %	useDouble = 1;      %elseif (strcmp(doubleElement,'no'))      % useDouble = 0;      %end    end    % look for <samples> tag, and work out how many moment groups there are    % and their parameters (ie 1 or 0)    if (~isempty(findstr(line,'<samples>')) & samplesFound ==0)      samplesFound = 1;      indStart = findstr(line, '<samples>');      indEnd = findstr(line, '</samples>');      samplesElement = line(indStart+9:indEnd-1);      % remove spaces, then check the length of the string, if longer than      % one, iterate over it finding values of moment groups      samplesElement = strrep(samplesElement,' ','');      samplesLen = length(samplesElement);      % for some reason data is still kept even if one of the      % samples variables is 0...  Oh well, I'll just set      % numMomentGroups to the length of the samplesElement then...      numMomentGroups = samplesLen;      %       if (samplesLen == 1)      % 	% don't need to do anything (I guess....)      % 	numMomentGroups = 1;      %       elseif (samplesLen > 1)      % 	% this is the number of <XSIL elements we need to look for      % 	numMomentGroups = 0;      % 	for i = 1:samplesLen      % 	  if (samplesElement(i) == '1')      % 	    numMomentGroups = numMomentGroups + 1;      % 	  end      % 	end      %       end    end        line = fgetl(fp);  end  % ok, if we got this far, then we must make some assumptions  % if binary_output isn't set then assume it's text  % if use_double isn't set then assume it's double     if (findstr(line,'<XSIL') & binaryFound == 0)    disp('using ascii output for xsil file')    useBinary = 0;  end        if (findstr(line,'<XSIL') & singleFound == 0 & binaryFound == 1)    disp('using double output for binary file')    useDouble = 1;  end  fprintf('%s%s%s\n', 'I found ', num2str(numMomentGroups), ' moment groups');    for imoments = 1:numMomentGroups    fprintf('%s%s\n', 'processing moment group ', num2str(imoments));        % go looking for <XSIL    while (isempty(findstr(line,'<XSIL')))      line = fgetl(fp);    end    % look for number of independent variables    searchStr = '<Param Name="n_independent">';    while (isempty(findstr(line,searchStr)))      line = fgetl(fp);    end    indStart = findstr(line,searchStr);    indEnd = findstr(line,'</Param>');    numIndepVars = str2num(line(indStart+length(searchStr):indEnd-1));    % look for the variables, how many of them and their names    searchStr = '<Array Name="variables" Type="Text">';    while (isempty(findstr(line,searchStr)))      line = fgetl(fp);    end    % grab the next line, it *should* be a <Dim> tag    line = fgetl(fp);    indStart = findstr(line,'<Dim>');    indEnd = findstr(line,'</Dim>');    % get the number of variables    numVars = str2num(line(indStart+5:indEnd-1));        % now grab the next line, it *should* be a <Stream tag with the word    % "Text" in it somewhere    line = fgetl(fp);    if (findstr(line,'<Stream>') & findstr(line,'"Text"'))      % now, this line should be the variables, space delimited      line = fgetl(fp);      inds = findstr(line,' ');      if (length(inds) ~= numVars)	disp('Number of variable names found not equal to number of variables')	disp('Exiting...');	return      end      indStart = 1;      varNames = {};      for i = 1:length(inds)	indEnd = inds(i)-1;	if (indEnd == indStart)	  varNames(i).name = strcat(line(indStart:indEnd),'_',num2str(imoments));	elseif (indEnd > indStart)	  varNames(i).name = strcat(line(indStart:indEnd),'_',num2str(imoments));	else	  disp('For some reason, indEnd is less than indStart')	  disp('Exiting...')	  return	end	indStart = inds(i)+1;      end    else      disp('huh, for some reason I could not find a <Stream> tag with "Text" field')    end    % now go looking for the data    while(isempty(findstr(line,'<Array Name="data"')))      line = fgetl(fp);    end    % this line should now either be a <Dim> or <Stream>    % loop until I find the stream    line = fgetl(fp);    i = 1;    while(isempty(findstr(line,'<Stream>')))      indStart = findstr(line,'<Dim>');      indEnd = findstr(line,'</Dim>');      loopInd(i) = str2num(line(indStart+5:indEnd-1));      i = i + 1;      line = fgetl(fp);    end        % ok, this line should tell me if the output was binary or text    % however, I should already know (maybe I should error check....)    if (useBinary)      disp('loading binary file')      % the line just read tells us if we are using       % bigendian or littleendian binary format      if(~isempty(findstr(line,'BigEndian')))        machineFormat = 'ieee-be';      elseif(~isempty(findstr(line,'LittleEndian')))        machineFormat = 'ieee-le';      else        machineFormat = 'native';      end          % right, it's binary, now run the binary loading routine      % this is the binary data filename      line = fgetl(fp);      % strip superfluous spaces...      datFname = strrep(line,' ','');      % set the precison      if (useDouble == 0)	precision = 'single';        disp('using single precision data')      else	precision = 'double';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -