! bn_dsg_feature_mask 
! 9/4/2018
! Tests of selecting features via a mask
! PLOT/MASKFEATURE var, mask

use dsg_cross_prime.nc

! Mask must be the length of feature-direction axis
! Incoming missing-flag on the mask is handled internally

let/bad=-99 emask = {1,-99,1}
set data/fmask=emask 1

! Mask info listed with SHOW DATA
show data

! Mask applied on a listing
list sst

! redefine the mask. If the length still matches the mask is replaced.

let emask = {,1,1}  
set data/fmask=emask 1
list sst

! Use a new mask-var
let onefeature = {,1,}  
set data/fmask=onefeature 1
list sst

! Open more datasets and define masks for them.

use WestCoastCarbon_9d9c_f562_77b5_5f8e_5d19_7b1d.nc
set var/units=units pco2

let/title="Where Profile is 80,86,87,88" mask = element_index (profile,{80,86,87,88})

set data/fmask=mask 2
show data
set v ul
plot pco2

let/title="Where Longitude < 121W" mask =  if longitude lt -121 then 1
set v ur
plot pco2 

use DSG_ERDDAP_Tao5daySst.nc

! This mask doesn't have the right nfeatures length for datset 2 so 
! the feature-mask "mask" that was on dataset 2 is canceled.

let/title="Where station is 8s125w, 8s170w, 5n155w, 2s165e"  mask = element_index_str (station, {"8s125w", "8s170w", "5n155w", "2s165e"})

set data/fmask=mask 3

set v lower
set var/title=Temperature/units="Deg C" t_25
plot/color/thick t_25

frame/file=dsg_traj_feature_mask.gif


! All the datasets are still open.  The mask on dataset 2
! is now removed as the variable that defined it was changed.

show data
set data 1
list sst

! Cancel data/FMASK

cancel data/fmask 2
show data 2

show data 1

