fid=fopen('woce_sum_file.txt','w');
fprintf(fid,'%s','\tiny');
fprintf(fid,'\n');
fprintf(fid,'%s','\begin{landscape}');
fprintf(fid,'\n');
fprintf(fid,'%s','\begin{longtable}{llllllllllllllllll}');
fprintf(fid,'\n');    
fprintf(fid,'%s','\caption{Abaco Cruise -- WOCE Summary File\label{woce} }\\');
fprintf(fid,'\n');   
fprintf(fid,'%s','\hline');
fprintf(fid,'\n');    
fprintf(fid,'%s','SHIP/CRS & WOCE &     &      & CAST & CAST & UTC & EVENT &     &     &     & UNC   & HT ABOVE & WIRE & MAX & NO. OF  &            &        \\');
fprintf(fid,'\n');    
fprintf(fid,'%s','EXPOCODE & SECT & STN & CAST & TYPE & DATE & TIME & CODE & LAT & LON & NAV & DEPTH & BOTTOM   & OUT  & PRS & BOTTLES & PARAMETERS & COMMENTS\\');
fprintf(fid,'\n');    
fprintf(fid,'%s','\hline');
fprintf(fid,'\n'); 
fprintf(fid,'\n'); 
  expocode='WBTSNSRHB';
  sect_id='AB1202';
  cast_no=1;
  cast_type='ROS';
  event_code=['BE';'BO';'EN'];
  nav='GPS';
  param=('1,2');
  
  for i=1:length(vertcat(cnv.station)),
      
    bot_ind=find(cnv(i).altM==min(cnv(i).altM));
    date_beg=(datestr(datenum(2011,12,31)+cnv(i).timeJ(1),'mmddyyyy'));
    date_bot=datestr(datenum(2011,12,31)+cnv(i).timeJ(bot_ind(1)),'mmddyyyy');
    date_end=datestr(datenum(2011,12,31)+cnv(i).timeJ(end),'mmddyyyy');
    time_beg=(datestr(datenum(2011,12,31)+cnv(i).timeJ(1),'HHMM'));
    time_bot=datestr(datenum(2011,12,31)+cnv(i).timeJ(bot_ind(1)),'HHMM');
    time_end=datestr(datenum(2011,12,31)+cnv(i).timeJ(end),'HHMM');
    lat_beg=cnv(i).latitude(1);
    lat_bot=cnv(i).latitude(bot_ind(1));
    lat_end=cnv(i).latitude(end);
    lon_beg=-1*cnv(i).longitude(1);
    lon_bot=-1*cnv(i).longitude(bot_ind(1));
    lon_end=-1*cnv(i).longitude(end);
    
    
    %beginning line
    fprintf(fid,'%s%s\t%s%s\t%d%s\t%d%s\t%s%s\t%8c%s\t%4c%s\t%s%s\t',expocode,'&',sect_id,'&',cnv(i).station,'&',cast_no,'&',cast_type,'&',date_beg,'&',time_beg,'&',...
        event_code(1,:),'&');
    fprintf(fid,'%2.3f%s%s\t %2.3f%s%s\t %s%s%s%s%s%s%s%s%s\t\n',lat_beg,'N','&',lon_beg,'W','&',nav,'&','&','&','&','&','&','&','\\');
    
    %middle line
    fprintf(fid,'%s%s\t%s%s\t%d%s\t%d%s\t%s%s\t%8c%s\t%4c%s\t%s%s\t',expocode,'&',sect_id,'&',cnv(i).station,'&',cast_no,'&',cast_type,'&',date_bot,'&',time_bot,'&',...
        event_code(2,:),'&');
    fprintf(fid,'%2.3f%s%s\t %2.3f%s%s\t %s%s\t %4.0f%s\t %3.0f%s\t %4.0f%s\t %4.0f%s\t %2.0f%s\t %s%s\t %s%s\t\n',lat_bot,'N','&',lon_bot,'W','&',nav,'&',...
        cnv(i).depSM(bot_ind(1)),'&',cnv(i).altM(bot_ind(1)),'&',winchout(i),'&',cnv(i).prDM(bot_ind(1)),'&',length(btl(i).Bottle),'&',param,'&',comments(i,:),'\\');
    
    %end line
    fprintf(fid,'%s%s\t%s%s\t%d%s\t%d%s\t%s%s\t%8c%s\t%4c%s\t%s%s\t',expocode,'&',sect_id,'&',cnv(i).station,'&',cast_no,'&',cast_type,'&',date_end,'&',time_end,'&',...
        event_code(3,:),'&');
    fprintf(fid,'%2.3f%s%s\t %2.3f%s%s\t %s%s%s%s%s%s%s%s%s\t\n',lat_end,'N','&',lon_end,'W','&',nav,'&','&','&','&','&','&','&','\\');
    
    clear bot_ind date_beg time_beg lat_beg lon_beg date_bot time_bot lat_bot lon_bot date_end time_end lat_end lon_end
   end;
   
fprintf(fid,'\n');    
fprintf(fid,'%s','\hline');
fprintf(fid,'\n');          
fprintf(fid,'%s','\end{longtable}');
fprintf(fid,'\n');
fprintf(fid,'%s','\end{landscape}');

fclose(fid); 
