Re: how to combine multi-ASCII Files

From: Xi Chang <xi.chang01_at_nyahnyahspammersnyahnyah>
Date: Wed Oct 09 2013 - 06:32:33 MDT

Thanks Dennis and Wei,

your suggestions were really useful. Actually I prefer to implement what
Dennis suggested, since I wrote the codes by combining ncl and C-shell unix
command in a single file.

Thanks,
Xi,

On Tue, Oct 8, 2013 at 4:59 PM, Wei Huang <huangwei@ucar.edu> wrote:

> Do not use NCL for this kind task, please.
>
> A simple C-shell unix command:
>
> cat foo*.txt >> new_combined.txt
>
> will 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:52 AM, Dennis Shea <shea@ucar.edu> wrote:
>
> > 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 Wed Oct 9 06:32:53 2013

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