Re: Plot user-defined functions

From: Karin Meier-Fleischer <meier-fleischer_at_nyahnyahspammersnyahnyah>
Date: Mon Sep 30 2013 - 08:52:53 MDT

Hello Anna,

you have to define an data array and an x array which must have the same size.
See below.

Bye,
Karin

;************************************************************
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"
;************************************************************
undef("temp") ;Erstellen von f(x)
function temp(x)
begin
   fx = 9.44-0.0065 * x ; Definition von f(x)
   return (fx)
end

begin
   answer = temp(10)
   print(answer) ; Ausgeben der Temperatur

;***********************************Plot*************************************************************************
   wks_type = "pdf"
   wks = gsn_open_wks(wks_type,"Temperaturprofil1")

   res = True
   res@gsnDraw = False ; don't draw
   res@gsnFrame = False
   ;res@trYReverse = True ;reverser Y-axis
   ;res@trXMinF = 200
   ;res@trXMaxF = 310

   res@tiXAxisString = "Temperatur / K"
   res@tiYAxisString = "Druck / hPa"
   res@xyLineColors = (/"red"/)

   nx = 5
   data = new(nx,"float")
   x = new(nx,"integer")
   
   do i=0,nx-1
      data(i) = temp(i)
      x(i) = i
   end do

   plot1 = gsn_csm_xy(wks, data,x,res)

   draw(plot1)
   frame(wks)

end

Am 29.09.2013 um 14:47 schrieb anna@hbittnersth.de:

>
> I like to creat my own function f(x)= 9.44* 0.0065 *x and I like to plot this function.
> I can creat the function and get values for different x. But I can draw this function. Can you pleas help me.
> Here is my code and my error message:
> Thanks.
> ;************************************************************
> 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
>
> undef("temp") ;Erstellen von f(x)
> function temp(x)
> begin
> fx = 9.44-0.0065 * x ; Definition von f(x)
> return (fx)
> end
> answer = temp(10)
> print(answer) ; Ausgeben der Temperatur
>
> ;***********************************Plot*************************************************************************
> wks_type = "pdf"
> wks = gsn_open_wks(wks_type,"Temperaturprofil1")
> res = True
> res@gsnDraw = False ; don't draw
> res@gsnFrame = False
> ;res@trYReverse = True ;reverser Y-axis
> ;res@trXMinF = 200
> ;res@trXMaxF = 310
> res@tiXAxisString = "Temperatur / K"
> res@tiYAxisString = "Druck / hPa"
> res@xyLineColors =(/"red"/)
> do x=0,4
> plot1 = gsn_csm_xy(wks, temp(x),x,res)
> end do
> draw(plot1)
> frame(wks)
>
> end
> fatal:CheckArray:Each vector in the caXArray array must have at least 2 elements
> fatal:CoordArraysInitialize:caXArray resource is invalid
> fatal:Unable to initialize layer-Can't Create
> fatal:Unable to access object with id:-4
> fatal:Unable to access object with id:-4
> warning:Unable to add DataItem "(null)" to DataList "xyCoordData"
> fatal:CompileDataList:DataList has no valid members
> fatal:Unable to access object with id:-4
> warning:Unable to add DataItem "(null)" to DataList "xyCoordData"
> fatal:CompileDataList:DataList has no valid members
> fatal:Argument type mismatch on argument (0) of (attsetvalues_check) can not coerce
> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 11955 in file $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl
> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 5016 in file $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl
> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 40 in file Standardtemp.ncl
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_________________________________
Karin Meier-Fleischer
Deutsches Klimarechenzentrum GmbH

Application Support

Visualization

Bundesstrasse 45a
D-20146 Hamburg, Germany

E-Mail:
meier-fleischer@dkrz.de

Internet:
http://www.dkrz.de/

Phone: +49 40 460094 126
Fax: +49 40 460094 270

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Sep 30 08:53:11 2013

This archive was generated by hypermail 2.1.8 : Tue Oct 01 2013 - 14:41:43 MDT