Re: reading ASCII file

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed, 14 Mar 2007 22:21:36 -0600 (MDT)

On Wed, 14 Mar 2007, Debasish Pai Mazumder wrote:
> Hi all,
> I have an ascii file in the form,
> 000031.795000031.795000031.795000031.795000031.795000031.795000031.795000031
> .795000031.795000031.795000031.795000031.795000031.795000031.795000031.79500
> 0031.795000031.795000031.795000031.795000031.795000031.795000031.795000031.7
> 95000031.795000031.568000031.568000031.568000031.568000031.568000031.5680000
> 31.568000031.568000031.568000031.568000031.568000031.568000031.568000031.568
> 000031.568000031.568000031.568000031.568000031.568000031.568000031.568000031
> .568000031.568000031.568000031.568000031.568000031.568000031.568000031.56800
> 0031.568000031.568000031.568000031.568000031.568000031.568000031.568000031.5
> 68000031.568000031.568000031.568000031.568000031.568000031.568000031.5680000
> 31.568000031.568000031.568000031.568000024.636000024.636000024.636000024.636
> 0000.............
> Description of the file : This is a 2.5 degree Square latitude/longitude
> grid, and is usually used for display purposes. The grid is 144 x 72
> (longitude x latitude) and has a total of 10368 boxes. 0 degrees latitude, 0
> degrees longitude is a box corner. Longitude varies first, and begins at
> -180 degrees and proceeds eastward to +180 degrees. Latitude begins at -90
> degrees and proceeds northward to +90 degrees. Data is written 80 characters
> per record. Each record contains values for 8 grid boxes, each with a field
> width of 10 characters. The precision is 3 decimal places.
>
> So I have total 144X72=10368 numbers of values in the file.
>
> I try to read the file using the examples from
> http://www.ncl.ucar.edu/Document/Functions/Built-in/asciiread.shtml . But I
> can read the first value correctly and in case of other values I did not get
> the integer part and I got only decimal part.
>
> Someone please tell me how will I read the file and convert the file in
> netcdf format correctly.
>
> Any help will be appreciated
-------------------------------------------------------------------------

[1] NCL look for logical breaks [eg, spaces, commas, etc] so
    it knows how to break numbers up. There are no such breaks
    in this numeric sequence. How is any language that *automatically*
    reads the file supposed to know where a number starts/ends?

    IMHO ... this is a very poor file.

[2] You need a language that allows user defined granularity, eg fortran.

    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
    external DEBASH "./rdascii.so"
    
    nlat = 72
    mlon = 144

    lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north")

    lon = lonGlobeFo(mlon, "lon", "longitude", "degrees_east")
    lon = (/ lon - 180. /) ; subtract 180 from all values
    lon&lon = lon ; update coordinates

    x = new ( (/nlat,mlon/), "float" )
    x_at_long_name = "..."
    x_at_units = "..."

    DEBASH::rdascii( nlat, mlon, x)

    printVarSummary(x)
    printMinMax(x, True)

[3] fortran: rdascii.f

C NCLFORTSTART
      subroutine rdascii(nlat,mlon,z)
      implicit none
      integer nlat, mlon
      real (nlat,mlon)
C NCLEND
      open(10, file="....") ! put file name here
      read(10,"(8f10.3)") x

      return
      end

    
[4] WRAPIT rdascii.f

    will create .so
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Mar 14 2007 - 22:21:36 MDT

This archive was generated by hypermail 2.2.0 : Thu Mar 15 2007 - 09:15:24 MDT