close all
clear all

%load data
% load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\Equatorial Box Project\EqBox_GP506\Flowthrough\Transect2\ACS_apcp_Transect2_20080522T145448.mat'
% load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\Equatorial Box Project\EqBox_GP506\Flowthrough\Transect3\ACS_apcp_Transect3_20080613T092056.mat'
% load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\Equatorial Box Project\EqBox_GP506\Flowthrough\Transect4\ACS_apcp_Transect4_20080613T154258.mat'
load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\Equatorial Box Project\EqBox_GP506\Flowthrough\Transect5\ACS_apcp_transect5_20080620T141536'
I=find(str2num(datestr(acs_ap.time,'MM'))==15);
date=datestr(acs_ap.time(I),31)
%load position
load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\Equatorial Box Project\EqBox_GP506\SCS\AllTransects_SCS_Bin_20080514T142311.mat'
lat=interp1(scs_time,scs_gp90a_lat.mean,acs_ap.time(I),'linear');
lon=interp1(scs_time,scs_gp90a_lon.mean,acs_ap.time(I),'linear');
date_yyyy=datestr(acs_ap.time(I),10);
date_mm=datestr(acs_ap.time(I),5);
date_dd=datestr(acs_ap.time(I),7);
hour=datestr(acs_ap.time(I),13);
ap=acs_ap.mean(I,:);
cp=acs_cp.mean(I,:);
M=find(isfinite(cp(:,1)) & isfinite(ap(:,1)));
% fid = fopen('C:\Documents and Settings\Lisa Taylor\My Documents\Data\Equatorial Box Project\EqBox_GP506\seabass\Data_GP506cruise_transect2.txt', 'wt');
% fid = fopen('C:\Documents and Settings\Lisa Taylor\My Documents\Data\Equatorial Box Project\EqBox_GP506\seabass\Data_GP506cruise_transect3.txt', 'wt');
% fid = fopen('C:\Documents and Settings\Lisa Taylor\My Documents\Data\Equatorial Box Project\EqBox_GP506\seabass\Data_GP506cruise_transect4.txt', 'wt');
fid = fopen('C:\Documents and Settings\Lisa Taylor\My Documents\Data\Equatorial Box Project\EqBox_GP506\seabass\Data_GP506cruise_transect5.txt', 'wt');
% print header
fprintf(fid,'/begin_header\n');
fprintf(fid,'/investigators=Emmanuel_Boss,Michael_Behrenfeld,Wayne_Slade\n');
fprintf(fid,'/affiliations=UMaine-MISC_Lab,OSU,UMaine-MISC_Lab\n');
fprintf(fid,'/contact=emmanuel.boss@maine.edu,behrenfm@science.oregonstate.edu,wayne_slade@umit.maine.edu\n');
fprintf(fid,'!experiment=TAO_125_140_2006b\n');
fprintf(fid,'/experiment=TAO_2006b\n');
fprintf(fid,'/cruise=gp5-06-ka\n');
fprintf(fid,'/station=NA\n');
% fprintf(fid,'/data_file_name=Data_GP506cruise_transect2.txt\n');
% fprintf(fid,'/data_file_name=Data_GP506cruise_transect3.txt\n');
% fprintf(fid,'/data_file_name=Data_GP506cruise_transect4.txt\n');
fprintf(fid,'/data_file_name=Data_GP506cruise_transect5.txt\n');
fprintf(fid,'/documents=acs_particulate.txt\n');
fprintf(fid,'/calibration_files=acs_particulate.txt\n');
fprintf(fid,'/data_type=flow_thru\n');
fprintf(fid,'/data_status=final\n');
fprintf(fid,'/start_date=%4s%2s%2s\n',date_yyyy(M(1),:),date_mm(M(1),:),date_dd(M(1),:));
fprintf(fid,'/end_date=%4s%2s%2s\n',date_yyyy(M(length(M)),:),date_mm(M(length(M)),:),date_dd(M(length(M)),:));
fprintf(fid,'/start_time=%8s[GMT]\n',hour(M(1),:));
fprintf(fid,'/end_time=%8s[GMT]\n',hour(M(length(M)),:));
fprintf(fid,'/north_latitude=%5.3f[DEG]\n',max(lat(M)));
fprintf(fid,'/south_latitude=%5.3f[DEG]\n',min(lat(M)));
fprintf(fid,'/east_longitude=%5.3f[DEG]\n',max(lon(M)));
fprintf(fid,'/west_longitude=%5.3f[DEG]\n',min(lon(M)));
fprintf(fid,'/water_depth=NA\n');
fprintf(fid,'/measurement_depth=3\n');
fprintf(fid,'/secchi_depth=NA\n');
fprintf(fid,'/cloud_percent=NA\n');
fprintf(fid,'/wind_speed=NA\n');
fprintf(fid,'/wave_height=NA\n');
fprintf(fid,'!\n');
fprintf(fid,'! These are flow-through particulate absorption and attenuation data obtained with a WETLabs ac-s.\n');
fprintf(fid,'! Please see acs_particulate_data.txt for more information.\n');
fprintf(fid,'! Measurements are calibration independent.\n');
fprintf(fid,'! Please contact Wayne with questions or comments.\n');
fprintf(fid,'!\n');
fprintf(fid,'/missing=-9999.000\n');
fprintf(fid,'/delimiter=space\n');

fprintf(fid,'/fields=date,time,lat,lon');
for i=1:81
     fprintf(fid,',ap%4.1f',acs_ap.wavel(i));
end
for i=1:83
     fprintf(fid,',cp%4.1f',acs_cp.wavel(i));
end
fprintf(fid,'\n');
fprintf(fid,'/units=yyyymmdd,hh:mm:ss,degrees,degrees');
for i=1:83+81
    fprintf(fid,',1/m');
end
fprintf(fid,'\n');
fprintf(fid,'/end_header\n')
% print data
for i=1:length(M)
     fprintf(fid, '%4s%2s%2s ', date_yyyy(M(i),:),date_mm(M(i),:),date_dd(M(i),:));
     fprintf(fid, '%8s ', hour(M(i),:));
     fprintf(fid, '%5.3f ', lat(M(i)));
     fprintf(fid, '%5.3f ', lon(M(i)));
     fprintf(fid, '%6.4f ', ap(M(i),:));
     fprintf(fid, '%6.4f ', cp(M(i),:));
     fprintf(fid, '\n');
end     
fclose(fid);
