Re: Merging two XY plot

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon May 06 2013 - 08:02:36 MDT

Hi,

Thanks for including a nice script with the error highlighted.

I think the problem is with having the "gsn_open_wks" call that is inside the do loop.

When you create a plot, it has a "parent" object, which is the workstation (PS file) that it draws to.
You can't overlay plots that have different workstation parents, which is what happens when you do:

> overlay(plot1(0),plot1(nf))

My suggestion is to try moving the "gsn_open_wks" call outside the do loop. Since you are only
drawing one plot anyway, there's no need to have multiple calls.

So, instead of this:

> do nf=0,nfili-1
> f = addfile (diri+fili(nf),"r")
> t = f->temperature(0,:,0,0)
> s = f->salinity(0,:,0,0)
> sfx = get_file_suffix(fili(nf),0)
> pname = sfx@fBase
> wks = gsn_open_wks ("ps",pname)

Try this:

> wks = gsn_open_wks ("ps","pacific") ; Use whatever name you like here

> do nf=0,nfili-1
> f = addfile (diri+fili(nf),"r")
> t = f->temperature(0,:,0,0)
> s = f->salinity(0,:,0,0)
> sfx = get_file_suffix(fili(nf),0)
> pname = sfx@fBase

Furthermore, you don't need this line, so remove it:

> plot = new (2, "graphic")

--Mary

On May 5, 2013, at 10:54 PM, nand_s wrote:

> Dear Recipient,
>
> I’m trying to merge two XY into one frame but still its generating errors. I have projected separate graphs for TEMPERATURE versus Pressure and SALINITY versus PRESSURE but am still finding difficulties in merging the graphs. I have tried to merge the profiles using following code but it’s still generating errors as given below this CODE:
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> ;************************************************
> begin
> ;************************************************
> ; get list of files
> ;************************************************
> diri = "pacific-12-2012/pacific/2012/12/" ; input directory
> fili = systemfunc("cd "+diri+" ; ls nodc_R5901391*nc")
> print(fili)
> nfili = dimsizes(fili)
>
>
> ;************************************************
> ; plot resources
> ;************************************************
> res = True ; plot mods desired
> res@trYReverse = True ; reverse Y-axis
> res@xyLineThicknessF = 2 ; choose dash patterns
> res@gsnDraw = False
> res@gsnFrame = False
>
>
> resP = True
> resP@gsnMaximize = True
>
> plot = new (2, "graphic")
> plot1 = new(nfili,"graphic")
> plot2 = plot
>
> do nf=0,nfili-1
> f = addfile (diri+fili(nf),"r")
> t = f->temperature(0,:,0,0)
> s = f->salinity(0,:,0,0)
> sfx = get_file_suffix(fili(nf),0)
> pname = sfx@fBase
> wks = gsn_open_wks ("ps",pname)
> res@xyLineColor = (/"blue"/)
> plot1(nf) = gsn_csm_xy (wks,t,t&pressure,res) ; create plot
> res@xyLineColor = (/"red"/)
> plot2(nf) = gsn_csm_xy (wks,s,s&pressure,res) ; create plot
> if (nf.ne.0) then
> overlay(plot1(0),plot1(nf))
> overlay(plot1(0),plot2(nf)) ……………………………………………………………………..ERROR OCCURS NEAR OR IN THIS LINE.
> delete([/t,s/])
> end if
> end do
> resP@txString = fili(nf)
> gsn_panel(wks,(/plot1(0),plot2(0)/),(/2,1/),resP)
> end
>
>
>
> Error is generated after compilation and execution as given below:
>
> <image001.png>
>
>
>
> Can anyone assist me please as am the self-learner of NCL…..???
>
> Thanks and best regards.
>
> Sachin Ravilesh Nand | Software Engineer (Consultant)
> B.C.A (Bangalore University-India)
> European Union Global Climate Change Alliance Project.
> Pacific Centre for Environment and Sustainable Development.
> University of the South Pacific.
> E: sachin.nand@usp.ac.fj
> T: (+679) 32 32205
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon May 6 08:02:44 2013

This archive was generated by hypermail 2.1.8 : Tue May 07 2013 - 08:38:33 MDT