[Thread Prev][Thread Next][Index]

Re: mp_aspect problems



Alice,

It turns out that getting the right aspect ratio in a viewport is rather
tricky.

So we (Steve Hankin and I) have written another script which will help
out.  It will be part of the bug fix release but I thought the ferret
users group would want an answer to this question right away.  Attached,
please find mp_viewport_aspect.jnl which should have enough
documentation to get you going with your plots in viewports.

Let us know how it goes.

-- Jonathan Callahan



a.larkin@ic.ac.uk wrote:
> 
> Hello, right now we all have ferret 5 up and running, perhaps someone could
> help me.
> I CAN do the following to make a polar plot...
> set data Tave_con_stero.cdf
> set window 1
> set region/y=10:90/z=500/l=1
> set grid t_ave
> go mp_stereographic_north
> go mp_aspect
> fill/noaxis/set_up t_ave, x_page, y_page
> ppl fill
> go mp_land
> go mp_graticule 0 360 12 30 90 15
> 
> but when I want to do a number of plots, I tried to the the following that
> doesn't work.
> 
> set data Tave_con_stero.cdf
> set window 1
> set region/y=10:90/z=500/l=1
> set grid t_ave
> go portraitNxN 2 3 15 15
> set viewport 1
> go mp_stereographic_north
> go mp_aspect
> fill/noaxis/set_up t_ave, x_page, y_page
> ppl fill
> go mp_land
> go mp_graticule 0 360 12 30 90 15
> 
> it falls down at go mp_aspect.
> Please could someone tell me how to resolve the problem. I've tried moving the
> order of things around and trying go margins instead but none of this works.
> Thanks
> Alice
\cancel mode verify	
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
! mp_viewport_aspect.jnl -- Calculate the appropriate aspect ratio for the
!                           current region and map projection and then define
!                           a viewport with the appropriate dimensions.
!		    		
! Jonathan Callahan
! 6/99

! Description:  Define a viewport for plotting map projections
!
! Usage:           arg1   arg2   arg3     arg4         arg5
!  go mp_viewport xlolim xhilim ylolim text_factor [viewport_name]
!
! arg 1 - X lo limit [0,1] (as in DEFINE VIEWPORT/XLIMITS=xlolim,xhilim)
! arg 2 - X hi limit [0,1] (as in DEFINE VIEWPORT/XLIMITS=xlolim,xhilim)
! arg 3 - Y lo limit [0,1] (as in DEFINE VIEWPORT/YLIMITS=ylolim,yhilim)
! arg 4 - text prominence  (as in DEFINE VIEWPORT/TEXT=text_factor)
! arg 5 - viewport name

! Example 1: 2 viewports on an 8.5 X 11 plot
!
!  set win/size=.4/aspect=`11/8.5` ! set up desired page size and aspect
!  use coads_climatology
!  set grid sst                    ! out of habit, for map projections
!  shade sst[l=1]                  ! to initialize the window
!  set region/x=80w:40e/y=30n:80n
!  go mp_bonne
!  go margins 0.4 0.4 0.4 0.8      ! to specify narrow margins
!  go mp_viewport_aspect 0 1 0 1 mp_vp1
!  shade/noaxis/nolabel sst[l=7], x_page, y_page
!  go mp_fland
!  go mp_label 340 85 0 0 .3 "@TRJuly SST"
!  go mp_viewport_aspect 0 1 0.5 1 mp_vp2
!  shade/noaxis/nolabel sst[l=1], x_page, y_page
!  go mp_fland
!  go mp_label 340 85 0 0 .3 "@TRJanuary SST"
!

! Getting the right aspect ratio for plots in viewports is rather
! complicated because of the interaction of various elements in 
! plot plus.  In order to get the aspect ratios right, we need to
! calculate and specify the X and Y axis lengths.
!
! The basic equations we need to know are the following:
!
! xaxlen = xfraction * plot_width - right_margin - left_margin
! yaxlen = yfraction * plot_height - top_margin - bottom_margin
! aspect_ratio = yaxlen / xaxlen
!
! For non-viewports xfraction and yfraction are both 1.0.
!
! When using viewports, 
!
! xfraction = scale * (xhilim - xlolim)
! yfraction = scale * (yhilim - ylolim)
! scale = 1 / sqrt(text_factor)
!
! If you know xhilim, xlolim, ylolim, text_factor and the
! various margins, you can solve for yhilim which is what we do
! below.


! First determine the margins that are currently set
!
let/quiet mp_vp_top = `($vp_height) - ($ppl$yorg) - ($ppl$ylen)`
let/quiet mp_vp_bottom = `($ppl$yorg)`
let/quiet mp_vp_left = `($ppl$xorg)`
let/quiet mp_vp_right = `($vp_width) - ($ppl$xorg) - ($ppl$xlen)`

! Get the arguments 
!
let/quiet mp_vp_xlolim=$1"0"
let/quiet mp_vp_xhilim=$2"1"
let/quiet mp_vp_ylolim=$3"0"
let/quiet mp_vp_text_factor = $4"1"
let/quiet mp_vp_fractional_width = mp_vp_xhilim-mp_vp_xlolim

! Calculate the aspect ratio
!
let/quiet mp_vp_x_axis_range = `x_page[i=@max,j=@max]` - `x_page[i=@min,j=@min]`
let/quiet mp_vp_y_axis_range = `y_page[i=@max,j=@max]` - `y_page[i=@min,j=@min]`
let/quiet mp_vp_ratio = mp_vp_y_axis_range / mp_vp_x_axis_range

let mp_vp_xfrac = mp_vp_fractional_width / mp_vp_text_factor^0.5

let mp_vp_fractional_height = (mp_vp_text_factor^0.5/($ppl$height)) * (mp_vp_ratio*(mp_vp_xfrac*($ppl$width)-mp_vp_left-mp_vp_right)+mp_vp_top+mp_vp_bottom)

! Define the new viwport
! Set the new viewport
! Keep the original margin specification
!
define view/xlimits=`mp_vp_xlolim`,`mp_vp_xhilim`/ylimits=`mp_vp_ylolim`,`mp_vp_ylolim+mp_vp_fractional_height`/text=`mp_vp_text_factor` $5"mp_viewport"
set view $5"mp_vewport"
go margins `mp_vp_top` `mp_vp_bottom` `mp_vp_left` `mp_vp_right`

! Clean up our mess
!
cancel variable mp_vp_*

!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
set mode/last verify
 

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement