Re: Convert ascii to a netCDF

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Fri, 20 Oct 2006 16:47:47 -0600 (MDT)

Hello,

The following is not enough information.
Where is a format description of the file?
Where did you get the file?
Did they make available a C or fortran code
that reads the ascii.

What does
          Grid-ref= 1, 148
refer to? Are 1, 148 subscripts for the (720,360) grid?
If subscripts, I assume they are fortran type indexing.

Just taking a look at the info below,
I took a guess at how you could make a netCDF file.
Obviously, it has not been tested.

Good luck

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Hi!
How can I convert an archive ascii to netCDF.

clim.6190.lan.pre
----------------------------------------------------------------------------
---------------------------------
Tyndall Centre grim file created on 12.01.2004 at 11:44 by Dr. Tim Mitchell
.pre = precipitation (mm)
0.5deg lan clim:1961-90 MarkNew
[Long=-180.00, 180.00] [Lati= -90.00, 90.00] [Grid X,Y= 720, 360]
[Boxes= 67420] [Years=1975-1975] [Multi= 0.1000] [Missing=-999]
Grid-ref= 1, 148
 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
... (12 values with number "1")
Grid-ref= 2, 313
  450 270 260 200 190 260 430 510 460 390 510 390
...(12 values with number "2")
...
Grid-ref= 720, 323
  170 80 80 90 110 170 300 340 260 180 210 90
----------------------------------------------------------------------------
-----------------------

I have doubts if has "teams" variavel and if it is used as attribute of
"precipitacao" like lat and lon.
I wait the reply!
Thanks!

Luciana F.

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
  ntim = 12
  nlat = 360
  mlon = 720
  lat = latGlobeFo (nlat, "lat", "latitude", "degrees_north")
  lon = lonGlobeFo (mlon, "lon", "longitude", "degrees_east")
  lon = (/ lon -180 /)
  lon&lon = lon

  prc = new ( (/ntim,nlat,mlon/), "float", -999.)
  prc_at_long_name = "precipitation"
  prc_at_units = "mm"
  prc!0 = "time"
  prc!1 = "lat"
  prc!2 = "lon"
  prc&lat = lat
  prc&lon = lon

  x = asciiread("clim.6190.lan.pre", -1, "float")
 ;print(x)
  nx = dimsizes(x)

  year = floattoint( x(14) )
  time = year*100 + ispan(1,12,1)
  time!0 = "time"
  time_at_long_name = "time"
  time_at_units = "yyyymm"
  prc&time = time

  ngrup = 14 ; 14 = two subscripts + 12 values
  nStrt = 18
  nLast = nStrt+ngrup-1
  npts = (nLast-nStrt+1)/ngrup
  print(npts)

  do n=0,npts
     jlat = floattoint( x(nStrt ) ) - 1
     ilon = floattoint( x(nStrt+1) ) - 1
     prc(:,jlat,ilon) = (/ x(nStrt+2:nStrt:14) /)
     nStrt = nStrt + ngrup
     nLast = nLast + ngrup
  end do

  printVarSummary( prc )
  printMinMax( prc, True )

  fnc = "prc."+year+".nc"
  system("'rm' -f "+fnc) ; remove any pre-existing file
  ncdf= addfile( fnc ,"c") ; open output netCDF file

      ; make time and UNLIMITED dimension
  filedimdef(ncdf,"time",-1,True)
  ncdf->PRC = prc

end

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Oct 20 2006 - 16:47:47 MDT

This archive was generated by hypermail 2.2.0 : Sat Oct 21 2006 - 07:36:59 MDT