function write_xml_components(filename,names,freqs,amplitudes,phases,name,tstart,tstop);
%function write_xml_components(filename,names,freqs,amplitudes,phases,name,tstart,tstop);
% write tidal components in xml-format
%
% <Transfer ns0:noNamespaceSchemaLocation="HC_Schema_V1.xsd" xmlns:ns0="http://www.w3.org/2001/XMLSchema-instance">
%   <Port>
%     <name>A port in a storm</name>
%     <country>A man without a country</country>
%     <position>
%       <latitude>0.0</latitude>
%       <longitude>0.0</longitude>
%     </position>
%     <timeZone>0000</timeZone>
%     <units>m</units>
%     <observationStart>2013-01-01T00:00:00</observationStart>
%     <comments>No comment</comments>
%     <observationEnd>2014-01-01T00:00:00</observationEnd>
%     <Harmonic>
%       <name>Z0</name>
%       <speed>0.0</speed>
%       <inferred>false</inferred>
%       <phaseAngle>0.0</phaseAngle>
%       <amplitude>0.070</amplitude>
%     </Harmonic>

fid=fopen(filename,'w');

%function write_xml_components(filename,freqs,amplitudes,phases,name,tstart,tstop);
fprintf(fid,'<Transfer ns0:noNamespaceSchemaLocation="HC_Schema_V1.xsd" xmlns:ns0="http://www.w3.org/2001/XMLSchema-instance">\n');
fprintf(fid,'  <Port>');
fprintf(fid,'    <name>%s</name>',name);
fprintf(fid,'    <country>A man without a country</country>');
fprintf(fid,'    <position>');
fprintf(fid,'      <latitude>0.0</latitude>');
fprintf(fid,'      <longitude>0.0</longitude>');
fprintf(fid,'    </position>');
fprintf(fid,'    <timeZone>0000</timeZone>');
fprintf(fid,'    <units>m</units>');
fprintf(fid,'    <observationStart>%s</observationStart>',datestr(tstart,'yyyy-mm-ddTHH:MM:SS'));
fprintf(fid,'    <comments>No comment</comments>');
fprintf(fid,'    <observationEnd>%s</observationEnd>',datestr(tstop,'yyyy-mm-ddTHH:MM:SS'));

for i=1:length(amplitudes),
   fprintf(fid,'    <Harmonic>\n');
   fprintf(fid,'      <name>%s</name>\n',deblank(names{i}));
   fprintf(fid,'      <speed>%f</speed>\n',freqs(i));
   fprintf(fid,'      <inferred>false</inferred>\n');
   fprintf(fid,'      <phaseAngle>%f</phaseAngle>\n',phases(i));
   fprintf(fid,'      <amplitude>%f</amplitude>\n',amplitudes(i));
   fprintf(fid,'    </Harmonic>\n');
end;

fprintf(fid,'  </Port>\n');
fprintf(fid,'</Transfer>\n');
fclose(fid);
