% do_adcp.m - oc415-4 outer loop for drifter processing
% first have to go to april to get the messages from Jim's account:
%
%> ssh -l sci1 april
%> pine   [messages will be moved to file ~/mail/ARGOS]
%> mv mail/ARGOS cindy/ARGOS.# [# = sequential number - see ls for latest]
%> exit
%
% then run this script
%
% C Sellers 08/05
%

% get the files from april 
nn=input('enter the file number: ','s');
eval(['!scp sci1@april:cindy/ARGOS.',nn,' .'])
eval(['!\cp ARGOS.',nn,' ./m1.txt'])

% get the good lines
!awk '$1 ~ /02182/ && $2 ~ /52484/ && NF == 12 {print $0}' m1.txt >> l_argos_pos.txt
!awk '$1 ~ /02182/ && $2 ~ /52486/ && NF == 12 {print $0}' m1.txt >> drft_shp.txt
!awk '$1 ~ /02182/ && $2 ~ /52485/ && NF == 12 {print $0}' m1.txt >> drift_52485.txt

% make a plot
map_argos

% make file to plot on ADCP map
cout=cvt_argos(s2,s3,lat,lon+360);
fid = fopen('dr_52484.txt','w');
lll=length(cout);
for ii = lll-50:lll
  fprintf(fid,'%f %f %f\n',cout(ii,1),cout(ii,2),cout(ii,3));
end
fclose(fid);

% make a file of all data for this drifter
fid = fopen('dr_4.txt','w');
lll=length(cout);
for ii = 1:lll
  fprintf(fid,'%f %f %f\n',cout(ii,1),cout(ii,2),cout(ii,3));
end
fclose(fid);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% make files for other drifters
cout6=cvt_argos(s2n,s3n,lt,ln);
fid = fopen('dr_52486.txt','w');
lll=length(cout6);
for ii = lll-50:lll
  fprintf(fid,'%f %f %f\n',cout6(ii,1),cout6(ii,2),cout6(ii,3));
end
fclose(fid);

fid = fopen('dr_6.txt','w');
lll=length(cout6);
for ii = 1:lll
  fprintf(fid,'%f %f %f\n',cout6(ii,1),cout6(ii,2),cout6(ii,3));
end
fclose(fid);

%%%%%%%%%%%%%%%
cout5=cvt_argos(s2n5,s3n5,lt5,ln5);
fid = fopen('dr_52485.txt','w');
lll=size(cout5,1);
if lll > 50
  for ii = lll-50:lll
    fprintf(fid,'%f %f %f\n',cout5(ii,1),cout5(ii,2),cout5(ii,3));
  end
else
  for ii = 1:lll
    fprintf(fid,'%f %f %f\n',cout5(ii,1),cout5(ii,2),cout5(ii,3));
  end
end
fclose(fid);

fid = fopen('dr_5.txt','w');
lll=size(cout5,1);
for ii = 1:lll
  fprintf(fid,'%f %f %f\n',cout5(ii,1),cout5(ii,2),cout5(ii,3));
end
fclose(fid);


