function [files,url_nolon,url_metafail,poslon, mtable]=dir_to_ge(params); % DIR_TO_GE Writes metadata from all netCDF files in URL dir to GE % % new features- ability to enable/disable use of the timeslider on creation, % and the Z is used for depth, so they're actually underwater. % % usage: [files,url_nolon,url_metafail,poslon, mtable]=dir_to_ge(params); % where params is a structure containing fields: % url_dir (the url or directory where the files to read are) % if you want to do the cwd, do wdir=pwd; param1.url_dir=wdir; % kml_name (output name root) % do_timespan (include code for time slider or not (yes or no)) % % this version can take a TDS address for url_dir, or a local directory. % if you choose a local directory, the URL in the box will need to be % modified after the fact. % % originally by Rich Signell, mods by Ellyn Montgomery, both usgs.gov. % Google Earth icon to use %iconStr = 'http://maps.google.com/mapfiles/kml/pal3/icon35.png'; iconStr = 'http://maps.google.com/mapfiles/kml/paddle/ylw-stars.png'; %iconStr = 'http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png'; url_dir=char(params.url_dir); kml_name=char(params.kml_name); do_tspan= lower(char(params.do_timespan)); if(strncmp(do_tspan,'y',1)) do_timespan=1; else do_timespan=0; end % here's where it decides to use local directory or not, and a TDS or not if(~isempty(strfind(url_dir,'http'))) if ~isempty(strfind(url_dir,'thredds')) files=get_files_from_TDS(url_dir); else [files]=get_files_from_url(url_dir); end else files=dir(url_dir); % ok to get everything here- conditions below do selection if ~ispc files(1:2)=[]; % remove the references to . and .. end end kmlStr='';% initialize kml string kk=0;k=0;j=0; % initialize bad file counters % Loop through each NetCDF file, getting metadata, and collecting % urls where the metadata fails or lon is empty. url_nolon=[]; url_metafail=[]; poslon=[]; mtable=struct([]); % for i=1:10 % use this to do a subset of the data when testing. for i=1:length(files); %for i=1:20; % for i=1:10 if(~isempty(strfind(url_dir,'http'))) file=char(files{i}); % cond=['~isempty(findstr(lower(file),''-a.'')) | ~isempty(findstr(lower(file),''-cal.''))']; % conditions=[eval(cond)]; else file=files(i).name; end % this is how it decides which files to process % one could also remove any burst type files from the directory % prior to running to accomplish the same thing. cond1=['~isempty(findstr(lower(file),''.nc'')) | ~isempty(findstr(lower(file),''.cdf''))']; cond2=['isempty(findstr(lower(file),''b-cal''))']; cond3=['isempty(findstr(lower(file),''wb-'')) | isempty(findstr(file,''Wvs''))']; cond4=['isempty(findstr(file,''_raw''))']; %sonar files cond5=['isempty(findstr(file,''isus''))']; cond6=['~strncmp(file,''.'',1)']; %. and .. may be in files- don't process conditions=[eval(cond1) & eval(cond2) & eval(cond3) & eval(cond4) & eval(cond5) & eval(cond6)]; % conditions=[eval(cond1) & eval(cond2) & eval(cond3) & eval(cond4) & eval(cond6)]; % end % if (strmatch(file,'8521Wvsp-cal.nc')); keyboard; end % when getting files from stellwagen, you have to replace catalog with % dodsC if strfind(url_dir,'stellwagen') end if strncmp(url_dir(end),'/',1) url=[url_dir file ]; else url=[url_dir '/' file ]; end % don't process files with q in the name - these are usually adv quality % files that don't have time or position in the metadata if (isempty(findstr(file,'q-cal'))) % process only files starting with numbers (ours all do) %if ~isempty(str2num(file(1))) % do only the -a or -cal files; not lp or a1h %if (~isempty(findstr(lower(file),'-a.')) | ~isempty(findstr(lower(file),'-cal.'))) % or do all .nc, except the burst files %if (~isempty(findstr(lower(file),'.nc'))) % if (isempty(findstr(lower(file),'b-cal')) & isempty(findstr(lower(file),'wb.'))) % also ignore the burst files if (conditions) %now returns a struct mvals=get_whfc_meta(url); if ~isempty(mvals) mtable{i}=mvals; mtable{i}.fname=file; % unpack for use jdmat_start=mvals.jd_start; jdmat_stop=mvals.jd_stop; lat=mvals.lat; % these are from the lot & lon variables lon=mvals.lon; % the metadata may be different if isempty(mvals.wdep) | isempty(mvals.meas_dep) inst_ht=0; else inst_ht=(mvals.wdep-mvals.meas_dep(1)).*3.2808399; %ft/m end if length(inst_ht) > 1 inst_ht=inst_ht(1); end if do_timespan tstart = datestr(jdmat_start,'yyyy-mm-ddTHH:MM:SSZ'); tstop = datestr(jdmat_stop,'yyyy-mm-ddTHH:MM:SSZ'); if isempty(tstart) disp ('there is nothing in tstart, which suggest the program could not open the URL') disp ('make sure a DAP-enabled mexnc is first in the MATLABPATH and try again') return end if (i==1) pltparams{1}=tstart(1:4); pltparams{2}=tstop(1:4); else if size(tstart) >4 if (str2num(tstart(1:4)) < str2num(pltparams{1})) pltparams{1}=tstart(1:4); end end if size(tstop) >4 if (str2num(tstop(1:4)) > str2num(pltparams{2})) pltparams{2}=tstop(1:4); end end end else tstart=' '; tstop=' '; end % do a bit of bounds checking if isempty(jdmat_start) kk=kk+1;url_metafail{kk}=url; elseif (jdmat_stop > datenum(now) || jdmat_stop < 0 || jdmat_start < datenum(1970,1,1)) kk=kk+1;url_metafail{kk}=url; disp('stopped here because meta_failed because jdmat has problems') keyboard else try if ~isempty(lon), if lon >= 0 % see if if the metadata is correct and use that if mvals.lonmeta == -lon lon=mvals.lonmeta; else j=j+1; poslon{j}= url; end % this is a mega-kludge to get around some wave files if lon >-1 && lon < 1 && mvals.lonmeta < -50 lon=mvals.lonmeta; keyboard end end % %put some values in the right click content box... % table_str is a nx2 cell array table_str=meta_to_table(url,lon,lat, mvals); % fabricate the kml string with the best guess at the values % use mod version to avoid output of bogus directions if do_timespan str=mod_ge_point(lon,lat,inst_ht,... 'name', file,... 'altitudeMode','relativeToSeaFloor',... 'description',[url '.html'],... 'timeSpanStart',tstart,... 'snippet','',... 'timeSpanStop',tstop,... 'visibility',1,... 'iconURL',iconStr,... 'pointDataCell',table_str); else % this part done if no timespan needed str=mod_ge_point(lon,lat,inst_ht,... 'name', file,... 'altitudeMode','relativeToSeaFloor',... 'description',[url '.html'],... 'visibility',1,... 'iconURL',iconStr,... 'pointDataCell',table_str); end % even though relativeToSeafloor requires % gx:AltitudeMode, don't put gx: here - dealt with % in mod_ge_point kmlStr=strcat(kmlStr,str); % accumulate strings else k=k+1;url_nolon{k}=url; end catch kk=kk+1;url_metafail{kk}=url; end end end end end end % % add the lat and lon to the plot parameters if isnumeric(lon) & isnumeric(lat) pltparams{3}=[num2str(lon) ',' num2str(lat) ',' num2str(inst_ht)]; else pltparams{3}=[]' end % write accumulated string to Google Earth KML % use mod* version to avoid output of bogus directions % _output_tslider implements the timeslider, _output does not if(do_timespan) mod_ge_output_tslider([kml_name '.kml'],kmlStr, pltparams); else mod_ge_output([kml_name '.kml'],kmlStr, pltparams); end