% extractstd - script which extracts variable values and standard deviations from % the file specified in the variable std_filename. % % Output: Variables given in the std file, prepended with std_, e.g. std_N0. % % NOTE: In the std file, vectors are simply given as several scalar variables % with the same name. In this case, these scalars are simply appended % to form a vector, if a variable name already exists. For this reason % the std-variables should be cleared before calling this function!!! % % Written by Lennart Frimannslund, April 2010 % Check for already existing variables starting with std_ (except std_filename, which should be present). who_cell = who('std_*'); if (length(who_cell)>1), fprintf(2,'WARNING!!! Variables starting with %sstd_%s detected. %s might malfunction.\n',char(39),char(39),mfilename); fprintf(2,'Consider calling %sclear std_*%s\n',char(39),char(39)); end; if (exist('std_filename','var') == 0), fprintf(1,'%s: Filename variable %sstd_filename%s not defined!\n',mfilename,char(39),char(39)); return; end; fid = fopen(std_filename,'r'); if (fid == -1), fprintf(1,'%s: Unable to open file %s.\n',mfilename,filename); return; end; % Get rid of first line l = fgetl(fid); % Now get all variable names, values and stddevs, in columns 2,3 and 4, respectively. while (l ~= -1), l = fgetl(fid); if (l==-1), break; end; [token, remainder] = strtok(l); [currname, remainder] = strtok(remainder); [currval, remainder] = strtok(remainder); [currstd, remainder] = strtok(remainder); if (exist(['std_' currname],'var') == 0), eval(sprintf('std_%s = [ %s %s ];',currname,currval,currstd)); else, eval(sprintf('std_%s = [ std_%s; %s %s ];',currname,currname,currval,currstd)); end; end; fclose(fid); clear fid token l currname currval currstd remainder who_cell;