function moor2m3d(in_file,out_file)

% note: order of mooring from north to south I,F,E,B - F is tucked into
% Penobscot Bay latitudes: 44.1066, 44.055, 43.714, 43.180

% hardwire in depths of moorings to approximate averaging interval in the wc
% mooring I depth is a bit shallow - derived from stellwagon mesh

%
% GOMOOS moorings 
%
% A 42 31'40" N,70 33'59" W,65 m
% B 43 10'51" N,70 25'40" W, 62 m
% C 43 34'10" N, 70 03'18" W, 46 m
% E 43 42'47" N, 69 21'20" W, 100 m
% F 44 03'20" N, 68 59'53" W, 110 m
% I 44€ 06'21" N, 68€ 06'31" W, 100 m
%
%


mI_dep = 69;
mF_dep= 30;
mE_dep= 77;
mB_dep= 61;    

mB_dep=62;
mC_dep=46;
mC_dep=46;
mC_dep=46;
mC_dep=46;

fid= fopen(in_file,'r')
data = fscanf(fid,'%f')

% mooring data comes has 9 columns:
numtimes = size(data,1)/9;
% time, lat, lon, wind speed, wind dir, taux, tauy, uavg, vavg
temp = reshape(data,[9 numtimes]);
clear data;
data = temp';
clear temp;

% find the indexes in the data file corresponding to each mooring
% use for reference to depth
Iind = find(data(:,2) == 44.106);
Find = find(data(:,2) == 44.055);
Eind = find(data(:,2) == 43.714);
Bind = find(data(:,2) == 43.180);

% filter out mooring F
Filt_ind = [Iind Bind Eind];
temp = data(Filt_ind,:);
clear data;
data = temp;
clear temp;

[m,j]=sort(data(:,1));
data=data(j,:);

Blat=43.18
Clat=43.71
Dlat=44.06
Elat=43.63 
Flat=43.49 

Bind = find(data(:,2) == Blat);
Cind = find(data(:,2) == Clat);
Dind = find(data(:,2) == Dlat);
Eind = find(data(:,2) == Elat);
Find = find(data(:,2) == Flat);



day = data(:,1);
% convert time to yearday - not *completely* sure what the initial time
% base was, but this seems to work, using routine from snackbar
for i = 1:size(data,1); 
  yday(i) =data(i,1)-datenum(2004,1,1)
end
% convert lat/lon to x,y
lat = data(:,2);
lon = data(:,3);
[x y] = ll2xy(lat, lon);

% convert u,v to m/s
u = data(:,8)./100;
v = data(:,9)./100;

% initialize an array of depth, tb, and bb
d(1:size(data,1)) = 0;
tb(1:size(data,1)) = 0;
bb(1:size(data,1)) = 0;


% fill in depths, tb, bb.  Right now, we are approximating tb and bb
d(Iind) = mI_dep;
d(Eind) = mE_dep;
d(Bind) = mB_dep;
d(Find) = mF_dep; 

tb(:) = 15;

bb(Iind) = mI_dep - 15;
bb(Eind) = mE_dep - 15;
bb(Bind) = mB_dep - 15;
bb(Find) = mF_dep - 15;

fid_out = fopen(out_file,'w')
fprintf(fid_out,'XXXX \n');
fprintf(fid_out,'stw2 \n');
fprintf(fid_out,'header line \n');
fprintf(fid_out,'2004 \n');
fprintf(fid_out,'8 \n');
 
% need to add top bin, bottom bin, and depth
for i = 1:size(data,1);
  if ~isnan(yday(i)+x(i)+y(i)+u(i)+v(i)+tb(i)+bb(i)+d(i)),
          fprintf(fid_out,'%f %f %f %f %f %f %f %f \n', ...
          yday(i),x(i),y(i),u(i),v(i),tb(i),bb(i),d(i));
  end
end
fclose(fid)
