Re: make the script faster

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed Oct 13 2010 - 08:51:38 MDT

Untested ....

  x = f->T ; (time, cell_index)
  iindex = f->$"x-index"$
  jindex = f->$"y-index"$

  dimx = dimsizes(x)
  N = product(dimx)
  ntim = dimx(0)

  ii = conform(x, iindex, 1)
  jj = conform(x, jindex, 1)

  npt = ispan(0,ntim-1,1)
  nn = conform(x, npt, 1)

  data = new ((/N,4/), typeof(x))
  data(:,0) = ndtooned(nn)
  data(:,1) = ndtooned(ii)
  data(:,2) = ndtooned(jj)
  data(:,3) = ndtooned( x)

  delete(x)
  delete(ii)
  delete(jj)

  system("/bin/rm -f foo.txt")

  opt = True
  opt@fout = "foo.txt"
  fmtx = "f5.0, 2f7.1, f10.3"
  write_matrix (data, fmtx, opt)

or

  data = new ((/N,4/), "integer")
  data(:,0) = ndtooned(nn)
  data(:,1) = ndtooned(ii)
  data(:,2) = ndtooned(jj)
  data(:,3) = toint( ndtooned( x)*1000 ) ; scale

  system("/bin/rm -f foo.txt")

  opt = True
  opt@fout = "foo.txt"
  fmtx = "i5, i7, i10"
  write_matrix (data, fmtx, opt)

Then, unscale the 'x' colmn when reading

     x = data(:,3)*0.001

http://www.ncl.ucar.edu/Document/Functions/Built-in/write_matrix.shtml

Good luck

On 10/12/10 3:46 PM, Debasish wrote:
> Hello!
>
> I am trying to convert netcdf to ascii file. I would like to know is there anyway to make my attached NCL program faster.
>
> Thanks
>
> Debasish
>
> The dimension of the file and NCL program are attached below:
> ==============================================
> dimensions:
> cell_index = 451 ;
> date_length = 16 ;
> time = UNLIMITED ; // (10988 currently)
> variables:
> float T(time, cell_index) ;
> T:units = "K" ;
> int x-index(cell_index) ;
> int y-index(cell_index) ;
> char time(time, date_length) ;
>
> ;===============================================
> ;NCL PROGRAM
> ;===============================================
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> begin
> ;************************************
> ; create pointer to several types of
> ; files. Note the syntax is the same
> ;************************************
> f = addfile("Temp_1970_01_01_00_00.nc","r")
> x = f->T
> iindex = f->$"x-index"$
> jindex= f->$"y-index"$
>
> printVarSummary(x)
>
> dimx = dimsizes(x)
> ntim = dimx(0)
> niindex = dimx(1)
>
> npts = 451 ; total number of grid points
>
> fName = "foo.txt"
> data = new( npts, "string")
>
> npt = -1
> do nl=0,niindex-1
>
> print(npt)
> npt = npt + 1
> data(npt) = sprinti("%0.5i", (npt+1) )
> data(npt) = data(npt) + sprintf("%7.1i ",iindex(nl))
> data(npt) = data(npt) + sprintf("%7.1i ",jindex(nl))
>
> do nt=0,ntim-1
> data(npt) = data(npt) + sprintf("%10.3f ", x(nt,nl))
> end do
> end do
>
> asciiwrite (fName , data)
>
> end
>
> _______________________________________________
> 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 Wed Oct 13 08:51:43 2010

This archive was generated by hypermail 2.1.8 : Tue Oct 19 2010 - 14:38:00 MDT