Re: dealing with the headers in ascii file

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sat Feb 12 2011 - 15:15:43 MST

The following should work:

;============================================
   diri = "./"
   fili = "cairo.txt"
   sdata = asciiread(diri+fili, -1, "string")
   nlines = dimsizes(sdata) ; Total number of lines in file

   ncols = 15
   nrows = 15 ; number of rows per iteration with numbers
   NROWS = nrows+1 ; includes header
   niter = nlines/NROWS ; number of iterations
   print("niter="+niter)

   data = new ( (/niter,nrows,ncols/), "float")

   kline = -1
   do ni=0,niter-1
      nr = -1
     do NR=0,NROWS-1
        kline = kline+1
        if (.not.(kline%NROWS).eq.0) then
            nr = nr+1
            data(ni,nr,:) = tofloat(str_split(sdata(kline)," "))
        end if
     end do
   end do

   wopt = True
   do ni=0,niter-1
      wopt@title = "write_matrix: iteration="+(ni+1)
      write_matrix(data(ni,:,:),ncols + "f9.4",wopt) ; Formatted output
   end do
;================================================

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sat Feb 12 15:15:50 2011

This archive was generated by hypermail 2.1.8 : Tue Feb 15 2011 - 09:43:19 MST