% -----------------------------------------------------------------------------
% CreateRCFile.m
% -----------------------------------------------------------------------------
%
%  Writes out the contents of the parameter struct to an RC file. The 
% parameter struct must be created with InitSimSect and filled in 
% with the desired parameters to be written into the RC file. This 
% function extracts the field names automatically from the struct. 
% It also supports strings.
%
% -----------------------------------------------------------------------------
%
%  function CreateRCFile( params, filename );
%
% -----------------------------------------------------------------------------
%  Input Arguments:
%    
%    params   : struct with fields corresponding to config file entries.
%    filename : Name of the output file. (must include .rc extension)
%
% -----------------------------------------------------------------------------
% $Id: CreateRCFile.m,v 1.1.1.1 2003/10/28 20:05:59 ulucs Exp $
% -----------------------------------------------------------------------------

function CreateRCFile( params, filename );

names = fieldnames( params );

fid = fopen( filename, 'w' );

fprintf( fid, '# %s\n#\n', filename );
fprintf( fid, '# SimSect++ RC file.\n#\n', filename );
fprintf( fid, '# This file has been automatically generated by \n', filename );
fprintf( fid, '# SimSect++ Matlab toolset.\n#\n\n', filename );

for ind = 1:length(names),
  curname = char(names(ind));
  curvalue = getfield(params, curname);
  if ( ischar( curvalue ) )
    fprintf( fid, '%s = \"%s\";\n', curname, curvalue );
  else
    fprintf( fid, '%s = %g;\n', curname, curvalue );
  end
  
end

fclose( fid );