\cancel mode verify

! set initial demo state
cancel data/all
cancel region
cancel mode logo

! dods_demo.jnl  *kob* 5/99
! customized for IPRC presentation 9/99 *sh*
!
! Description: Demo: how to use Ferret and OPeNDAP to access remote Datasets
!              OPeNDAP was formerly known as DODS: (Distributed Oceanographic Data Systems)
!

set mode verify
IF ($program_name"0|PyFerret>1|*>0") THEN SET TEXT/Font=arial



!      *********************************************************
!        DEMO: Using Ferret and OPeNDAP to access remote data sets
!      *********************************************************

! First we will examine the COADS climatology dataset from the Pacific
! Marine Environmental Laboratory (PMEL) in Seattle, Washington. 


! Note:  Once the dataset has been initialized from the remote site,
!        using the dataset is exactly the same as if it were local


PAUSE
!      *********************************************************



set data "http://ferret.pmel.noaa.gov/nvods/thredds/dodsC/las/COADS-climatology/data_coads_climatology.jnl"
show data



! SHOW DATA verifies that this is indeed a remote dataset
! 
! Now let's look at a color contour of Sea Surface Temperature




PAUSE
!      *********************************************************

fill/t="16-jul" sst
go land

! Next, let's look at a subregion of the SST. 
 
!   Note: Higher data access speed may be noticed due to data caching by Ferret



PAUSE
!      *********************************************************


go basemap x=130e:170w y=30N:70N 20
fill/overlay/t="16-jul"/x=140e:180e/y=40N:65N sst


! Remote data has full random access. Here we will plot the evolution of SST
! averaged over the Equatorial waveguide (an XT section)

PAUSE
!      *********************************************************


fill/x=140e:180e/l=1:24 sst[y=5s:5n@ave]

! Now, let's use a different SST dataset from the Earth System Research Laboratory
! (ESRL) in Boulder, Colorado

PAUSE
!      *********************************************************

use "http://www.esrl.noaa.gov/psd/thredds/dodsC/Aggregations/OISSThires/sst.mean.nc"
show data 2

! This data set contains weekly mean global SST grids prepared by
! Reynolds et. al.  (see http://www.esrl.noaa.gov/psd/thredds/catalog.html)
! Let's look at the SST for June 15, 1989

PAUSE
!      *********************************************************


fill/t="15-JUN-1989" sst[d=2]
go fland

! Now, let's see where the June 15, 1989 Reynolds field (served from Boulder)
! exceeds the June climatological data (served from Seattle)

! This requires regridding the 2x2 degree COADS data to the 0.25x0.25 degree
! Reynolds grid

PAUSE
!      *********************************************************

let coads_on_reynolds = sst[d=1,g=sst[d=2]]
let warmer = IF sst[d=2] GT coads_on_reynolds THEN 1

IF ($program_name"0|Ferret>1|*>0") THEN \ 
shade/x=80w:20e/y=0:80N/pal=black/levels/pattern=weave/t="15-jun-1989"/over warmer

! PyFerret does not have pattern palettes.
IF ($program_name"0|PyFerret>1|*>0") THEN \ 
shade/x=80w:20e/y=0:80N/pal=black/levels/palette=cyan_light/t="15-jun-1989"/over warmer

! Urls change, and some of these may no longer be available. Even if these
! commands yield errors, read the comments for techniquesto handle large datasets, 
! and ones that have grids with orientations different than what is expected. 
! The commands are illustrated in the on-line version of this demo:
! http://ferret.pmel.noaa.gov/documentation/how-to-use-ferret-and-opendap-to-access-and-analyze-remote-data-1

SET MODE ignore
PAUSE

! Next let's look at a dataset from NASA's Earth Observing system (EOS) HDF-EOS group. 
! This data set is in HDF format. It contains surface data - wind stress, heat flux,
! humidity, precipitable water.

!   Note that OPeNDAP gives Ferret format-independence -- the ability to read
!        an HDF file

PAUSE
!      *********************************************************
use "http://eosdap.hdfgroup.org:8080/opendap/data/NASAFILES/hdf5/GSSTF.2b.2008.01.01.he5"
show data/att 3


! Let's look at the wind-stress vectors

PAUSE
!      *********************************************************


vector/xskip=5/yskip=1 A4STu, A5STv
go fland

! Next lets examine some NOAA AVHRR data served by the University
! of Rhode Island, Graduate School of Oceanography (GSO). This
! data is in the form of 1024x1024 pixel images (1 megabyte per image)

! We will use this to illustrate the ability of Ferret and OPeNDAP to
! subsample -- making the data transfer much faster.

PAUSE
!      *********************************************************


use "http://satdat1.gso.uri.edu/opendap/Pathfinder/Northwest_Atlantic/6km/raw/1995/1/f95018175608.hdf"

! Performance greatly enhanced through use of strides
shade/levels=50 dsp_band_1[i=1:1024:4, j=1:1024:4]

! We can see Florida and the Carribean islands, but they are upside down. 
! Ferret can use the netCDF library to address this, with the /ORDER qualifier.
cancel data 4
use/order=x-y "http://satdat1.gso.uri.edu/opendap/Pathfinder/Northwest_Atlantic/6km/raw/1995/1/f95018175608.hdf"

! The coordinate axes are just index values, but the longitude/latitude ranges are 
! defined in global attributes. We can redefine the x and y axes to represent 
! longitude and latitude axes.

define axis/x=`..dsp_nav_earth_leflon`:`..dsp_nav_earth_ritlon`/npoints=1024/units=degrees_east `DSP_BAND_1,return=xaxis`
define axis/y=`..dsp_nav_earth_botlat`:`..dsp_nav_earth_toplat`/npoints=1024/units=degrees_north `DSP_BAND_1,return=yaxis`
shade/levels=v dsp_band_1[i=1:1024:4, j=1:1024:4]
go fland 05

set mode/last ignore
