Re: Writing netCDF binary to flat binary

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Mon May 14 2012 - 14:25:04 MDT

You do not need to reorder.

NCL is row major. The leftmost dimension varies slowest
and the rightmost dimension varies fastest.

Matlab is column major. The leftmost dimension varies fastest
and the rightmost dimension varies slowest.

The 'rule' is fastest varying dimension maps into fastest varying dimension.

So ...

netCDF (same as NCL): data(time,lat,lon)

maps into

Mtalab, fortran, R: data(lon,lat,time)

----
No looping required:
    fo = "outfile.bin"
    f1 = addfile ("infile.nc", "r")
    data = f1->data
    fbindirwrite(fo, data )
or, even
    fbindirwrite(fo, f1->data )
=====
Different language/tool indexing and ordering:
  NCL/C/C++:  0-based        ; leftmost dimension varies slowest
                               rightmost dimension varies fastest
  fortran, Matlab, R: 1-based; rightmost dimension varies slowest
                               leftmost dimension varies fastest
  IDL:        0-based        ; rightmost dimension varies slowest
                               leftmost dimension varies fastest
On 5/14/12 11:08 AM, Noel Aloysius wrote:
> Hello NCL-talk:
>
> For further clarification, I am posting this question I previously asked
> and answered.
>
> For an analysis I need to convert netCDF output to flat binary  - netCDF
> array size data(time,lat,lon) = data(1200,180,360).
>
> The output binary is read by a matlab program as data(lon,lat,time) =
> data(360,180,1200).
>
> Do I have to rotate the dimensions before writing the binary?
>
> The following scripts does the conversion.
>
> f1 = addfile ("infile.nc <http://infile.nc>", "r")
> data = f1->data
> fo = "outfile.bin"
> data1 = data(time|:,lon|:,lat|:)             ;each time step has 360
> lons and 180 lats
> nt = 1200
>
> do nt=0,(nt-1 )
>       fbindirwrite(fo, vals(nt,:,:) )
> end do
>
> Thanks,
> Noel
>
>
>
> _______________________________________________
> 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 Mon May 14 14:25:16 2012

This archive was generated by hypermail 2.1.8 : Thu May 17 2012 - 13:42:02 MDT