function [argodata,missingprof,missingname,missingSigns] = find_argo_inbox(lonlim,latlim,argo,dlim); % dlim is the date range as a 2x1 vector in matlab time units % lonlim and latlim are the geographical limits % argo is the data structure created next, based on the file saved in % select_float_data_allm. if ~exist('callSigns') % Created in select_float_data_all.m load /Users/eleanor/matlab/_insitu/argo/stNAtl/all_argo_in_mann.mat end %% Create argo structure argo.lon=datalon; argo.lat=datalat; argo.callSigns=callSigns; argo.P=data_P; argo.date=datadate; argo.filename=datafilename; %% % Execute this script iteratively: % 1) Run cell 1 and then determine which float profile data are missing % 2) Download that individual provile data in a .tgz file from the argo % website, see frajka-williams.com/help.php. % 3) Extract the tarballs, tar -xf ####.tgz where #### is the argo callSign number % 4) Rerun cell 1 to see whether you got them all. % Next check whether there're individual profiles missing for callSigns % which were previously downloaded. Note, if you are running for delayed % mode (quality controlled,'D') profiles, you may never get them all, % because your file saved in select_float_data_all only knows about all the % profiles which exist, and will tell you to go get them, regardless of % whether they exist in D yet or not. If you are running in realtime 'R', % you should be able to get them all (i.e. run until there're no % missingfloats or missingprofs) % What profiles are we looking for? missingprof=[]; missingname=''; argodata(1).s=NaN; ilon = findbetw(argo.lon,lonlim); ilat = findbetw(argo.lat,latlim); iloc = intersect(ilon,ilat); idate=findbetw(argo.date,dlim); iloc=intersect(iloc,idate); %% Cycle through the callSigns to extract all the data into .mat files whos iloc callSigns=[]; datactr = 'nodc'; % This is where you choose realtime or delayed mode (quality controlled) time = 'D'; % Realtime or delayed zdo=0;qdo=0; uniqSigns=unique(argo.callSigns); sdo=0; missingSigns=[]; for ndo=1:length(uniqSigns) call1=uniqSigns(ndo); if ~sum(call1==callSigns) % At each first instance when the callSign appears, % process all nc files in that directory mydir = ['/Volumes/DATADRIVE/argo/AtlanticData/tgz/',num2str(call1),'/profiles/']; %% Read the directory and parse the .nc if the .mat corresponding %% doesn't exist allfiles = dir(mydir); if length(allfiles) for rdo=1:length(allfiles) name1= allfiles(rdo).name; if length(name1)>3 istr1=1; istr2 = strfind(name1,'.nc'); if name1(1:2)=='._' eval(['!rm ',mydir,name1]); else filename = name1(istr1:istr2-1); if length(filename) filenamemat = [filename,'.mat']; if ~exist([mydir,filenamemat],'file') read_nc_write_mat(mydir,filename); end end end end end else % If we didn't find an appropriate directory sdo=sdo+1; missingSigns(sdo)=call1; end end end % Now check whether you have any missing callsigns (entire float numbers % which don't have any data on your computer, but are within your region of % interest, as defined by latlim, lonlim and dlim. To check this, execute % a "unique(missingSigns)" at your command line, and then based on those % callSign numbers, go download more data from teh argo website. % See: http://www.personal.soton.ac.uk/eefw1u08/download-argo-data-load-to-matlab.php %% Determine expected profnums associated with each callSign % May not run until next section is run % Once you have all the callSigns on your computer, check to see whether % you have all the profiles from each callSign--that is, have more float % profiles been uploaded to the Argo website since you last downloaded that % callSign? Run the next few cells. allSigns=unique(argo.callSigns(iloc)); profnum=[]; qdo=0; for sdo=1:length(allSigns) isign=find(argo.callSigns(iloc)==allSigns(sdo)); for fdo=1:length(isign) qdo=qdo+1; f1=argo.filename(iloc(isign(fdo)),:); ibar=strfind(f1,'_'); idot=strfind(f1,'.'); % profnum(qdo)=str2num(f1(ibar(end)+1:idot(1)-1)); matchsigns(qdo)=allSigns(sdo); t1=str2num(f1(ibar(end)+1:idot(1)-1)); if length(t1) % Added this because it was crashing on the f1 profile number % containing a character 'D'. Not sure why there was something % 760D.nc rather than just numbers... matchprof(qdo)=str2num(f1(ibar(end)+1:idot(1)-1)); end end end %% Now load all the data. All matfiles should exist because you processed them in the read_nc_write_mat line above. zdo=0;qdo=0; %gotsigns=mysigns; clear missingprof missingname gotsigns profnum %argodata=argodata(1:length(iloc)); for ndo=1:length(allSigns); sign1=allSigns(ndo); isigns=find(argo.callSigns(iloc)==sign1); mydir = ['/Volumes/DATADRIVE/argo/AtlanticData/tgz/',num2str(sign1),'/profiles/']; allfiles=dir(mydir); for pdo=1:length(isigns) sdo=iloc(isigns(pdo)); filename1=argo.filename(sdo,:); for rdo=1:length(allfiles) name1=allfiles(rdo).name; if strcmp(name1(end),'c') filename2=filename1; ir=strfind(filename1,'_R'); if length(ir) filename2(ir:ir+1)='_D'; end doit=0; if 0 if strfind(filename1,name1) filenameuse=filename1; doit=1; elseif strfind(filename2,name1); filenameuse=filename2; doit=1; end elseif strfind(filename2,name1); % Only use delayed modes filenameuse=filename2; doit=1; end if doit istr1=1; istr2=strfind(name1,'.nc'); name2=name1(istr1:istr2-1); filenamemat=[name2,'.mat']; if exist([mydir,filenamemat],'file') qdo=qdo+1; eval(['load ',mydir,filenamemat]); ibar=strfind(name1,'_'); idot=strfind(name1,'.'); gotsigns(qdo)=sign1; t1=str2num(name1(ibar(end)+1:idot(1)-1)); if length(t1) profnum(qdo)=str2num(name1(ibar(end)+1:idot(1)-1)); end argodata(qdo).s = argos; argodata(qdo).t = argot; argodata(qdo).p = argop; argodata(qdo).o = argoo; argodata(qdo).callSign = sign1; argodata(qdo).filename = filename; argodata(qdo).date = argo.date(sdo); argodata(qdo).lat = argo.lat(sdo); argodata(qdo).lon = argo.lon(sdo); argodata(qdo).P = argo.P(sdo,2); end end end end end end %% Compare filenames and callSigns? Problem is that filenames don't have a % regular structure % qdo=0;zdo=0; clear ss allmissing=0; for ndo=1:length(allSigns) sign1=allSigns(ndo); isign=find(matchsigns==sign1); igot=find(gotsigns==sign1); profexp=matchprof(isign); if max(igot)>length(profnum) disp('err, skip') else profgot=profnum(igot); sd1=setdiff(profexp,profgot); if length(sd1) qdo=qdo+1; ss(qdo).sign=sign1; ss(qdo).missingprof=sd1; disp([num2str(qdo),'. For ',num2str(sign1),' missing ',num2str(length(sd1)),' profiles: ',num2str(sd1)]) end allmissing=allmissing+length(sd1); if 0 sd2=setdiff(profgot,profexp); if length(sd2) sd2 end if length(profgot)>length(unique(profgot)) zdo=zdo+1; disp([num2str(zdo),'. For ',num2str(sign1),' extra profiles']) end end end end disp(['All missingL ',num2str(allmissing),' profiles']) if ~exist('ss') ss=[]; end % Scan the above list which was printed to your screen. If there're floats % (callSigns) which have lots of missing profile numbers, you should check % them on the Argo website. Sometimes, the profiles are missing because % you're looking for delayed mode and there're only realtime data % available. Sometimes they're missing because you downloaded that % particular callSign a while ago, and that float is still active in the % ocean, and has since uploaded more data to the website.