How to use the OPeNDAP server in MATLAB with Structs Tool.
The following explains the steps of loading data served by OPeNDAP using MATLAB.
Download and install MATLAB (if needed):
Download and install the MATLAB OPeNDAP library (if needed):
Start MATLAB:
Load data using loaddap / loaddods (loaddods replaces loaddap on
older installations)
and proceed as you normally would:
Note: % operator as comments. Example is using MATLAB R2006.
>> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> |
% Information on how to use loaddap help loaddap % Load the coastline load coast xlon = long; ylat = lat; % Find the indexes for 165W-153W, 18N-24N, and Oct 3, 2004. % Note: indices start from 0 x=loaddap('-A', 'http://apdrc.soest.hawaii.edu/dods/public_data/NLOM/nlom_ssh'); url_lon = strcat('http://apdrc.soest.hawaii.edu/dods/public_data/NLOM/nlom_ssh?lon[0:1:', num2str(x.lon.DODS_ML_Size-1), ']'); url_lat = strcat('http://apdrc.soest.hawaii.edu/dods/public_data/NLOM/nlom_ssh?lat[0:1:', num2str(x.lat.DODS_ML_Size-1), ']'); url_time = strcat('http://apdrc.soest.hawaii.edu/dods/public_data/NLOM/nlom_ssh?time[0:1:', num2str(x.time.DODS_ML_Size-1), ']'); x=loaddap(url_lon); lon=x.lon; x=loaddap(url_lat); lat=x.lat; x=loaddap(url_time); time=x.time; I = find(lon >= 195 & lon <= 207); J = find(lat >= 18 & lat <= 24); % Note: datenum and datevec use the time since Jan 0, 0000. % We need to add 365 days to fix the dataset % because this dataset uses since Jan 1, 0001. % datevec(time(1)+365) = [2002 6 1 0 0 0] {start time: Jun 1, 2002} % datevec(mytime+365) = [2004 10 3 0 0 0] {my time: Oct 3, 2004} mytime = datenum([2004 10 3 0 0 0])-365; K = find(time == mytime); time_param = strcat('[',num2str(K-1),':1:',num2str(K-1),']'); lat_param = strcat('[',num2str(J(1)-1),':1:',num2str(J(end)-1),']'); lon_param = strcat('[',num2str(I(1)-1),':1:',num2str(I(end)-1),']'); url_ssh = strcat('http://apdrc.soest.hawaii.edu/dods/public_data/NLOM/nlom_ssh?ssh',time_param,lat_param,lon_param); x=loaddap(url_ssh); % Fill missing data with NaN ssh=x.ssh.ssh; m=find(ssh<-1.0e33); ssh(m)=ones(size(m))+nan; % Contour sea surface height worldmap([lat(J(1)) lat(J(end))],[lon(I(1)) lon(I(end))]) setm(gca,'MapProjection','mercator') gridm off framem off % Contour sea surface height [c1,h1] = contourfm(lat(J),lon(I), double(squeeze(ssh)), 12); set(h1, 'EdgeColor', [0 0 0]) colorbar % Plot land outlines plotm(ylat,xlon,'k') title('NLOM 1/16 degree Sea Surface Height [cm] October 3, 2004') tightmap |
Instructions for IPRC "Theme" linux computers using loaddap
>> >> >> |
% After starting Matlab (or add to Matlab startup), % directories need to be added to the search path. addpath /usr/local/share/loaddap addpath /usr/local/bin % Return grid information of dataset whodap('http://apdrc.soest.hawaii.edu/dods/public_data/NLOM/nlom_ssh') Dataset { Grid { Array: Float32 ssh[time = 1380][lat = 2304][lon = 4096]; Maps: Float64 time[time = 1380]; Float64 lat[lat = 2304]; Float64 lon[lon = 4096]; } ssh; Float64 time[time = 1380]; Float64 lat[lat = 2304]; Float64 lon[lon = 4096]; } public_data/NLOM/nlom_ssh; |