function write_icq4(flnm,s);
%function write_icq4(flnm,s);

fp=fopen(flnm,'w');
eol='\n';
%XXXXXXXXXXXXXX<Some files have a bad eol charecter>XXXXXXXXXXXXXX
alphanumeric=['ACCDEFGHIJKLMNOPQRSTUVWXYZ',...
   			 'abcdefghijklmnopqrstuvwxyz',...
   		    '0123456789'];
if ~any(s.codename(end)==alphanumeric),
   s.codename=s.codename(1:end-1);
end
if ~any(s.casename(end)==alphanumeric),
   s.casename=s.casename(1:end-1);
end
if ~any(s.inqfilename(end)==alphanumeric),
   s.inqfilename=s.inqfilename(1:end-1);
end
if ~any(s.initcondname(end)==alphanumeric),
   s.initcondname=s.initcondname(1:end-1);
end
fprintf(fp,[s.codename,eol]);
fprintf(fp,[s.casename,eol]);
fprintf(fp,[s.inqfilename,eol]);
fprintf(fp,[s.initcondname,eol]);
%XXXXXXXXXXXXXXXX<Some have a bad eol charecter>XXXXXXXXXXXXXX

fprintf(fp,['%10i %10i',eol],[s.nn,s.nnv]);
fprintf(fp,['%2i %2i %4i %10i    180',eol],[s.day,s.month,s.year,s.curr_seconds]);
format long e;
for n=1:s.nn;
   fprintf(fp,[' %11E %11E %11E %11E %11E %11E',eol],...
      [s.HMID(n),s.UMID(n),s.VMID(n),s.HOLD(n),s.UOLD(n),s.VOLD(n)]);
end

for nv=1:s.nnv, 
	for n=1:s.nn, 
      fprintf(fp,['%11E %11E %11E %11E %11E %11E %11E %11E %11E',eol],...
      [s.ZMID(n,nv),s.ZOLD(n,nv),s.UZMID(n,nv),s.VZMID(n,nv),s.WZMID(n,nv),...
           s.Q2MID(n,nv),s.Q2LMID(n,nv),s.TMPMID(n,nv),s.SALMID(n,nv)]);   
  end
end
fclose(fp);