[Thread Prev][Thread Next][Index]

Re: [ferret_users] accessing statistics symbols in if/then statements



Hi
Russ has a solution if you want the length of the axis. If you want the number of valid points in a variable, you could use the @NGD transformation instead of `return=Lsize`.

  let n_ok = p[x=@ngd,y=@ngd,z=@ngd,t=@ngd]

I'd like to just explain more about what you ran into here:

The command parser evaluates symbols ($symbol_name) as the command is read in, and substitutes those symbols. The commands aren't executed at that time; we are just getting the full command line with any symbols or grave-accent expressions evaluated. When you put a set of commands together with the semicolon, they are parsed as a single command, substituting symbols and grave-accent expressions and then after that, the long input line broken up into separate commands and then finally they are executed. Until the STAT command is executed the value of STAT_NGOOD doesn't exist.

A solution for that is to do the IF statements as a block if within your script. This should work fine:

let p =  psl[d=1,t="16-jan-2000":"16-jan-2010"]
if `6 LT 10` then
  statistics p
  let pnum = ($stat_ngood))
endif






On 9/24/2012 11:29 PM, Jennifer.Abernethy@xxxxxxxx wrote:
Hi,

I'm running into a problem accessing the symbol $STAT_NGOOD when I use the statistics command in an if/then statement. It all works great when not used in an if/then statement.
Can anyone help me make sense of this?


This works great:

let p =  psl[d=1,t="16-jan-2000":"16-jan-2010"]
statistics p
let pnum = ($stat_ngood)

yes? go try_statstest.jnl
let p =  psl[d=1,t="16-jan-2000":"16-jan-2010"]
statistics p
PSL[D=spsl_soi,T="16-jan-2000":"16-jan-2010"]
              LONGITUDE: 0E
              LATITUDE: 0
              Z:  N/A
              TIME: 15-JAN-2000 12:00 to 14-JAN-2010 00:00
              DATA SET: N/A
Total # of data points: 120 (1*1*1*120)
  # flagged as bad  data: 0
  Minimum value: -2.2286
  Maximum value: 3.9071
  Mean    value: -0.13333 (unweighted average)
  Standard deviation: 1.0054
let pnum = ($stat_ngood)
  !-> DEFINE VARIABLE pnum = 120



But then I put it in a if/then statement.  Stat_ngood exists, but I can't save it:

let p =  psl[d=1,t="16-jan-2000":"16-jan-2010"]
if `6 LT 10` then (statistics p; show sym stat*;  let pnum = ($stat_ngood)) endif

yes? go try_statstest.jnl
let p =  psl[d=1,t="16-jan-2000":"16-jan-2010"]
if `6 LT 10` then  (statistics p ; let pnum = ($stat_ngood))  endif
  !-> if 1 then  (statistics p ; let pnum =  )  endif
PSL[D=spsl_soi,T="16-jan-2000":"16-jan-2010"]
              LONGITUDE: 0E
              LATITUDE: 0
              Z:  N/A
              TIME: 15-JAN-2000 12:00 to 14-JAN-2010 00:00
              DATA SET: N/A
Total # of data points: 120 (1*1*1*120)
  # flagged as bad  data: 0
  Minimum value: -2.2286
  Maximum value: 3.9071
  Mean    value: -0.13333 (unweighted average)
  Standard deviation: 1.0054
STAT_MIN = "-2.2286"
STAT_MAX = "3.9071"
STAT_MEAN = "-0.13333"
STAT_STD = "1.0054"
STAT_NGOOD = "120"
STAT_NBAD = "0"
  **ERROR: command syntax: PNUM = ???
DEFINE VARIABLE pnum =
Command file, command group, or REPEAT execution aborted


but it's fine again if I move the statistics command out of the if/then stmt:

!works
let p =  psl[d=1,t="16-jan-2000":"16-jan-2010"]
statistics p
if `6 LT 10` then (let pnum = ($stat_ngood)) endif



I need to have the statistics run in an if/then statement, because my real if test is if the year actually exists in the file (i.e. if it doesn't, can't run stats on it to begin with).

However, the reason I'm using `statistics` is that I need to get the length of p (on the L axis) - any other ways to do this?

Is there also any command that clears all data and symbols, axes, etc in ferret? I see cancel data,symbols etc but it looks like you have to do a bunch of cancel commands, clearing each thing one by one - anything that does it all in one command?

thanks,
jenny





[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement