Re: how to combine multi-ASCII Files

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Tue Oct 08 2013 - 08:52:09 MDT

I had just about finished when I saw Wei's post.
Her is what I had ... untested.

1] untested

      Use unix 'cat' via 'system' procedure.
      This would be the most efficient approach

      txtDir = "./"
      txtFiles = systemfunc("cd "+txtDir+" ; ls foo*.txt")

      system("cd "+txtDir+" ; cat foo*.txt >! FOOTXT")

      nRow = numAsciiRow(txtDir+"FOOTXT") ; contributed
      nCol = ????

      data = asciiread(txtDir+"FOOTXT", (/nRow,nCol/), "float"))
      printVarSummary(data)

      system("/bin/rm -f "+txtDir+"FOOTXT") ; optional

[2] untested

undef ("readMultAsciiFiles")
function readMultAsciiFiles(txtPath[*]:string, nCol[1]:integer,
txtType[1]:string)
local nRow, nt, nRowTot, data, nrStrt, nrLast
begin

     nRow = new( ntxt, "integer")
     do nt=0,ntxt-1
        nRow(nt) = numAsciiRow(txtDir+txtFiles(nt))
     end do

     print(nRow)
     print("===")
     nRowTot = sum(nRow)
     print("nRowTot="+nRowTot)

     data = new ( (/nRowTot,nCol/), txtType)

     nrStrt = 0
     nrLast = 0
     do nt=0,ntxt-1
        nrLast = nrStrt + nRow(nt) - 1
        data(nrStrt:nrLast,...) = asciiread (txtDir+txtFiles(nt),
(/nRow(nt),ncol/), "float") )
        nrStrt = nrLast+1
     end do

     return(data)
end

; Main

     txtDir = "./"
     txtFiles = systemfunc("cd "+txtDir+" ; ls foo*.txt")
     ntxt = dimsizes(txtFiles)
     nCol = ???
     data = readMultAsciiFiles(txtDir_txtFiles, nCol, "float")
     printVarSummary(data)

On 10/8/13 8:35 AM, Wei Huang wrote:
> NCL can do that job, but it is abuse of NCL.
> A simple Unix "cat" command should do the work.
>
> Wei
>
> huangwei@ucar.edu
> VETS/CISL
> National Center for Atmospheric Research
> P.O. Box 3000 (1850 Table Mesa Dr.)
> Boulder, CO 80307-3000 USA
> (303) 497-8924
>
>
>
>
>
>
> On Oct 8, 2013, at 8:03 AM, Xi Chang <xi.chang01@gmail.com> wrote:
>
>> Hallo People,
>>
>> I have multi ASCII files containing 1 column and different rows per each file:
>> foo1.txt, foo2.txt, etc..
>>
>> I need to combine them into a single ascii file,
>> any solution to do this task in NCL?
>> Thank you,
>>
>> Xi,
>> _______________________________________________
>> 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
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Oct 8 08:52:08 2013

This archive was generated by hypermail 2.1.8 : Tue Oct 22 2013 - 10:35:27 MDT