%% EXPORTS
clear all
close all
filename='partE1_6.mat';
load(['/Users/emmanuel.boss/Desktop/EXPORTS01/IOPPackage/software/Particulate_output_E1_1_7_E2_1_8_E3_1_6/',filename])

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%inputs for sb file:

docfile1='EXPORTS_ap_cp_processing_SlowDROP.docx';
textfile1='test'

roundwl=roundn(wl,-1);
for iwl=1:length(wl)
    wlarray{iwl}=['ap',num2str(roundwl(iwl)),','];
    wlarray2{iwl}=['cp',num2str(roundwl(iwl)),','];
    wlarray3{iwl}=['ap',num2str(roundwl(iwl)),'_sd,'];
end
for iwl=1:length(wl)-1
    wlarray4{iwl}=['cp',num2str(roundwl(iwl)),'_sd,'];
end
wlarray4{length(wl)}=['cp',num2str(roundwl(length(wl))),'_sd'];

% create arrays of units for the file header
apunits=repmat('1/m,',1,4*length(wl)-1);
apunits=[apunits,'1/m'];

%wlprint = strrep(num2str(wlem'),'       ',' ')

fileID(1)=fopen(textfile1,'w');


%header:
for i=1:1
fprintf(fileID(i),'%-30s\n','/begin_header');
fprintf(fileID(i),'%-30s\n','/investigators=Emmanuel_Boss,Nils_Haentjens');
fprintf(fileID(i),'%-30s\n','/affiliations=UMaine');
fprintf(fileID(i),'%-30s\n','/contact=emmanuel.boss@maine.edu');
fprintf(fileID(i),'%-30s\n','/experiment=EXPORTS');
fprintf(fileID(i),'%-30s\n','/cruise=EXPORTSNP');
fprintf(fileID(i),'%-30s\n','/station=NA');
if i==1
   fprintf(fileID(i),'%-30s\n',['/data_file_name=',textfile1]);
else
   fprintf(fileID(i),'%-30s\n',['/data_file_name=',textfile2]);
end
fprintf(fileID(i),'%-30s\n','/documents=EXPORTS_ap_cp_processing_SlowDROP.docx');
fprintf(fileID(i),'%-30s\n','/calibration_files=acs298.dev');
fprintf(fileID(i),'%-30s\n','/data_type=cast');
% fprintf(fileID(i),'%-30s\n','/data_status=final');
fprintf(fileID(i),'%-30s\n','/start_date=20180907');
fprintf(fileID(i),'%-30s\n','/end_date=20180907');
fprintf(fileID(i),'%-30s\n','/start_time=19:53:00[GMT]');
fprintf(fileID(i),'%-30s\n','/end_time=20:17:00[GMT]');
fprintf(fileID(i),'%-30s\n','/north_latitude=50.413[DEG]');																														
fprintf(fileID(i),'%-30s\n','/south_latitude=50.4125[DEG]');
fprintf(fileID(i),'%-30s\n','/east_longitude=-144.6729[DEG]');
fprintf(fileID(i),'%-30s\n','/west_longitude=-144.6763[DEG]');
fprintf(fileID(i),'%-30s\n','/water_depth=-999');
fprintf(fileID(i),'%-30s\n','/delimiter=comma');
fprintf(fileID(i),'%-30s\n','/missing=-999');
fprintf(fileID(i),'%-30s\n','/instrument_model=ac-s');
fprintf(fileID(i),'%-30s\n','/instrument_manufacturer=Sea-Bird_Scientific');
end
%spectral output
fprintf(fileID(1),'%-30s\n','!COMMENTS');
fprintf(fileID(1),'%-30s\n','!ap and cp values are based on binning 1m measurements; calculations explained in associated documents');
fprintf(fileID(1),'%-300s\n',['/fields=pressure,Wt,sal,',wlarray{:},wlarray2{:},wlarray3{:},wlarray4{:}]);
fprintf(fileID(1),'%-300s\n',['/units=dbar,degreesC,PSU,',apunits]);
fprintf(fileID(1),'%-30s\n','/end_header');

fclose(fileID(1))



