[Thread Prev][Thread Next][Index]
Re: How to extract file name to symbol?
Following the suggestions from Steve Hankin, I wrote two scripts that can
be used for extracting the file name from datasets in Ferret. I'm posting
them here in hopes that someone will find them useful...
Andrew
----------------------------------------------------------------------
Andrew Wittenberg Program in Atmospheric and Oceanic Sciences
andyw@splash.princeton.edu Sayre Hall, Forrestal Campus
Princeton University
Princeton, NJ 08544-0710
----------------------------------------------------------------------
!=====================================================================
\can mode verify
! def_path_from_num.jnl
! Description: Set a symbol to the file pathname of a dataset number.
! $1 $2
! GO def_path_from_num dset_num [symbol]
!
! $1: number of a dataset
! $2: output symbol name (default=PATH)
!
! EXAMPLES:
! Suppose we are using two datasets:
! 1> /data/sst.nc --> contains variable SST
! 2> /data/winds.nc (default) --> contains variable WIND_U
! yes? go def_path_from_num 2; show sym path
! PATH = "/data/winds.nc"
! yes? go def_path_from_num 1 sst_path; show sym sst_path
! SST_PATH = "/data/sst.nc"
list/q/clobber/i=1/j=1/k=1/l=1/file="dp.tmp" x[d=$1]
sp grep 'DATA SET:' dp.tmp | awk '{print "def sym dp_tmp \"" $3 "\""}' > dp.tmp.jnl
go dp.tmp.jnl
sp rm -f dp.tmp dp.tmp.jnl
def sym $2"path" "($dp_tmp)"
can sym dp.tmp
set mode/last verify
!=====================================================================
!=====================================================================
\can mode verify
! def_path_from_var.jnl
! Description: Set a symbol to the file pathname of a variable.
! $1 $2
! GO def_path_from_var varname [symbol]
!
! $1: variable name
! $2: output symbol name (default=PATH)
!
! EXAMPLES:
! Suppose we are using two datasets:
! 1> /data/sst.nc --> contains variable SST
! 2> /data/winds.nc (default) --> contains variable WIND_U
! yes? go def_path_from_var wind_u; show sym path
! PATH = "/data/winds.nc"
! yes? go def_path_from_var sst[d=1] sst_path; show sym sst_path
! SST_PATH = "/data/sst.nc"
!
! NOTE: varname must be a direct reference to a file variable,
! since Ferret v5.22 does not list the complete path for
! user-defined variables. E.g. the following is an error:
! yes? let v = sst[d=1]; go def_path_from_var v; show sym path
! yes? PATH = " "
!
list/q/clobber/i=1/j=1/k=1/l=1/file="dp.tmp" $1
sp grep 'DATA SET:' dp.tmp | awk '{print "def sym dp_tmp \"" $3 "\""}' > dp.tmp.jnl
go dp.tmp.jnl
sp rm -f dp.tmp dp.tmp.jnl
def sym $2"path" "($dp_tmp)"
can sym dp.tmp
set mode/last verify
!=====================================================================
[Thread Prev][Thread Next][Index]
Dept of Commerce /
NOAA /
OAR /
PMEL /
TMAP
Contact Us | Privacy Policy | Disclaimer | Accessibility Statement