Re: plot a 2-dimentional contour figure using some data with irregular grids

From: Mary Haley (haley AT XXXXXX)
Date: Fri Oct 03 2003 - 08:59:31 MDT

  • Next message: Paul Nutter: "line style suggestion"

    >
    > Hi,
    >
    > I want to use NCL to plot a 2-dimentional contour figure using some data with
    > irregular grids. Here is one example:
    >
    > x y z
    > 0.6 2 -0.8772757
    > 0.5 2 -0.9400954
    > ...
    > 0.1 6 -1.141822
    > 0.3 6 -1.159819
    >
    >
    > How can I plot a contour figure using this data?
    >
    > Thanks for any help in advance.
    > Qiaozhen
    >

    Dear Qiaozhen,

    You can use one of our interpolation packages to first interpolate the
    random points to a grid, and then use "gsn_contour" or
    "gsn_csm_contour" to plot it.

    Assuming that your file is called "q.dat", and that it only has three
    columns of numbers in it (and no labels), then your NCL script might
    look something like this:

    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

    begin
    ;
    ; Get number of points in file.
    ;
      npts = stringtointeger(systemfunc("wc -l q.dat"))
    ;
    ; Read values from file into local variable.
    ;
      q = asciiread("q.dat",(/npts,3/),"float")

      x = q(:,0) ; Column 1 of file contains X values.
      y = q(:,1) ; Column 2 of file contains Y values.
      z = q(:,2) ; Column 3 of file contains Z values.

    ;
    ; Define output grid for call to "natgrids".
    ;
      nxo = 20
      nyo = 20
      xmin = min(x)
      ymin = min(y)
      xmax = max(x)
      ymax = max(y)
      xc = (xmax-xmin)/(nxo-1)
      yc = (ymax-ymin)/(nyo-1)
      xo = xmin + ispan(0,nxo-1,1)*xc
      yo = ymin + ispan(0,nyo-1,1)*yc

    ;
    ; Interpolate random points to a grid using "natgrids".
    ; The output grid "zo" will be dimensioned nxo x nyo.
    ;
      zo = natgrids(x, y, z, xo, yo)

    ;
    ; Name the dimensions of "zo" and assign coordinate arrays.
    ; By doing this, "gsn_csm_contour" will then use the xo/yo values
    ; to set up the X/Y axis system.
    ;
      zo!0 = "x"
      zo!1 = "y"
      zo&x = xo
      zo&y = yo

      wks = gsn_open_wks("x11","test") ; Open an X window.

    ;
    ; Define a variable to hold resources, although we only setting
    ; one here.
    ;

      cnres = True
      cnres@gsnMaximize = True ; maximize size of plot in frame

      contour = gsn_csm_contour(wks, zo(y|:,x|:), cnres)

    end

    -------------------------------------------------
    Mary Haley haley@ucar.edu
    NCAR/SCD/VETS 303-497-1254 (voice)
    1850 Table Mesa Dr 303-497-1804 (fax)
    Boulder, CO 80305
    -------------------------------------------------
    _______________________________________________
    ncl-talk mailing list
    ncl-talk@ucar.edu
    http://mailman.ucar.edu/mailman/listinfo/ncl-talk



    This archive was generated by hypermail 2b29 : Fri Oct 03 2003 - 09:00:40 MDT