function input_file=WriteInput(fighandle)
% FILE = WriteInput(FIGHANDLE)
% FIGHANDLE is the handle to the main GUI figure. 
% 
% This function prompts for (and returns) an input file name FILE and writes the
% information from the input dialogues for later use with the function
% ImportInput.
% All of the input dialogues must have been successfully completed before calling
% this function.

% get handles from main GUI
handles=guidata(fighandle);

% prompt for input file name
filterspec = '*.in';
title = 'Save Input:';
dflt='input.in';
[input_file,pn]=uiputfile(filterspec,title,dflt);

% indicate BUSY in figure window
ToggleStatus(1,fighandle);

% open and write information to file
fid=fopen([pn,input_file],'w');
fprintf(fid,'%1d \n',handles.prop.twoDflag);
fprintf(fid,'%6g %4g %6g\n',handles.prop.youngmodulus, handles.prop.poissonratio,...
    handles.prop.thermalcoeff);
if handles.prop.youngmodulus<0
    fprintf(fid,'%6g %6g %6g %6g %6g %6g %6g %6g %6g\n',handles.prop.anisomods);
end
fprintf(fid,'%4g %4g\n',handles.prop.bodyforce);
fprintf(fid,'%4g\n',handles.prop.deltatemp);
numbounds=length(handles.bcsi.codes);
fprintf(fid,'%2d \n',numbounds);
for i=1:numbounds
    fprintf(fid,'%1d %6g %6g\n',handles.bcsi.codes(i),...
        handles.bcsi.normbcs(i),handles.bcsi.tangbcs(i));
end
if isfield(handles.bcsi,'pointbcs')
    numpbcs=size(handles.bcsi.pointbcs,1);
    fprintf(fid,'%2d \n',numpbcs);
    for i=1:numpbcs
        fprintf(fid,'%6g %6g %1d %6g %6g %10g\n',handles.bcsi.pointbcs(i,:));
    end
else
    fprintf(fid,'%2d \n',0);
end

% close file and indicate WAITING in figure window
fclose(fid);
ToggleStatus(0,fighandle);
