[Thread Prev][Thread Next][Index]

Re: How to make ferret handle a variable number of arguments?



Hi,
Yes, you should be able to do this.  Often an easy way to
deal with arguments to a script is to have a second script
which does the real work, in this case, the plotting.  For this
very simple example you could just issue the plot command in
place of the call to the journal file do_plot, but I show how to
use a plot script because in general your plot would take
more than one command to plot.

! callplot.jnl
! Reads the number of sensors and passes inputs to the plot script.

LET numsensors = $1
IF `numsensors GE 1` THEN GO do_plot $2

IF `numsensors GT 1` THEN
  REPEAT/I=2:`numsensors` (GO do_plot $`I+1` /OVERLAY)
ENDIF
EXIT


Where do_plot.jnl has just the commands to plot the variable.
In general, this script would be more complex than just a single
line.
! do_plot.jnl
! Arguments
!   $1 the variable to plot
!   $2 arguments to the plot command e.g. /overlay

PLOT/THICK$2" " $1   ! these are the arguments to do_plot.jnl
EXIT


Then you could run all of this as follows:

yes? let var1 = sin(x[x=1:100]/5)
yes? let var2 = sin(x[x=1:100]/6)
yes? let var3 = sin(x[x=1:100]/7)
yes? let var4 = sin(x[x=1:100]/8)
yes? let var5 = sin(x[x=1:100]/9)
yes? go callit 5 var1 var2 var3 var4 var5

 I hope this example will get you started.

Ansley Manke


Chi Ding wrote:

> Dear Ferret users
> I'm building a web site for mooring data where the user can select a
> variable number of sensors ( up to 10 )
> and draw the plots for each sensor in one picture. Ferret is the backend
> application for my site.
> I'm wondering how to make ferret process a variable number of arguments?
> This is essential to
> me since the user can select different number of sensors.
> I'm gonna try it in this way before I find a better solution. As the
> maximum number of sensors is 10, so I can fix the number of sensors
> passed to ferret to be a constant number 10. I will pass the selected
> sensor names and missing values for the rest to the ferret script. For
> examples, if the user selected " salinity" and "temperature", I will
> pass them and 8 missing values. Then the ferret script can check the
> arguments and plot accordingly.
> I'm wondering whether it is possible to pass the actual selected number
> of sensors plus the sensor names to ferret, then the ferret script can
> check the first arguement, i.e. the actual selected number, and
> accordingly plot the sensors. For example, if the user selected "
> salinity" and "temperature", I will pass "2", "salinity" and
> "temperature" instead of 10 sensor names.
> I'm looking forward to any suggestion.
> Thanks a lot, Ding

--
Ansley Manke  Pacific Marine Environmental Laboratory  Seattle WA




[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement