[Thread Prev][Thread Next][Index]

Re: [ferret_users] IF-THEN-ELIF-ELSE logic



Hi Ansley,

I should have thought about it. This is definitely a clear solution and easy to keep track. Mine was convoluted so I won't mention it.

BTW, I'd define the third mask by

let mtropic = if (yy ge -23 and yy le 23) then 1 else 0

which appears more straightforward to me. Of course it's my personal taste.

Thank you a lot!
D.

On Fri, Mar 27, 2009 at 6:24 PM, Ansley Manke <Ansley.B.Manke@xxxxxxxx> wrote:
Hi
Yes, I thought that was probably what you were asking. One way to do this is with three masks that can be added:
let mnorth = if yy gt 23 then 2 else 0
let msouth = if yy lt -23 then 3 else 0

let mtropic = if (msouth + mnorth) EQ 0 then 1 else 0

let mask = msouth + mnorth + mtropic

! as a check on what you've defined:
let xzero = 0*x[gx=xvar]
shade/lev=3 mask + xzero
Which is probably what you're thinking of with intermediate variables. It keeps things reasonably simple at the expense of extra command lines.

Then you can do things like this
let topic_data = if mask eq 1 then mask* myvar
...
Ansley

David Wang wrote:
Hi Ansley,

Thanks for asking. Let's me elaborate it. I'd like to define a few regional masks for an ocean model so that I can keep monitoring regional diagnostics without dumping 3d fields when unnecessary. This is by tagging each region with an unique index (number) on a single horizontal field. For the sake of simplicity, let's say I need three masks: tropical ocean (1), north ocean (2), and south ocean (3). In Ferret, I would have:

let yy = y[gy=myvar]
let mask = if yy gt 23.5 then 2 elif yy lt -23.5 then 3 else 1

where myvar is an arbitrary 2d field on the model grid.

I understand one can definitely break down the above definition into two steps using an intermediate variable. But this becomes increasingly awkward when the number of regions increases.

I could miss something obvious. If so, please enlighten me.

Thanks,
D.

On Fri, Mar 27, 2009 at 12:04 PM, Ansley Manke <Ansley.B.Manke@xxxxxxxx> wrote:
Hi David,
Can you write out some Ferret-like commands that show the syntax you're thinking of?  Are you trying to define a variable using a number of cases?  Often there are reasonable alternatives to the way one first thinks of doing something.

Ansley



David Wang wrote:
Hi Ferreters,

Well, I may sound pretty greedy. But is there a plan to extend the IF-THEN-ELSE logic to some kind of IF-THEN-ELIF-ELSE logic? It would be quite useful for multi-region masking. (Note: I'm not talking about conditional execution, which does have ELIF)

Thanks,
D.

--
life grows, death doesn't. there is no dress rehearsal.



--
life grows, death doesn't. there is no dress rehearsal.



--
life grows, death doesn't. there is no dress rehearsal.

[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement