Re: Ascii Read

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed, 2 Aug 2006 10:02:55 -0600 (MDT)

On Wed, 2 Aug 2006, Prince K. XAVIER wrote:

> Hi all,
>
> I have an ascii file in the following format:
>
> R1980_02_26_01_0 I1980_02_26_01_0 M1980_02_26_01_0 B1980_02_26_01_0 F1980_02_26_01_0 W1980_02_26_01_0
> -0.70048E-02 0.15754E-03 0.25603E+03 0.39966E+03 0.78071E+02 0.23911E+02
> -0.93824E-02-0.17659E-02 0.25380E+03 0.45695E+03 0.75446E+02 0.26309E+02
> -0.12501E-01-0.50578E-02 0.25238E+03 0.52589E+03 0.12391E+03 0.45510E+02
> -0.14862E-01-0.80700E-02 0.25033E+03 0.68417E+03 0.20448E+03 0.74260E+02
> -0.14457E-01-0.74378E-02 0.24476E+03 0.66249E+03 0.20077E+03 0.70360E+02
> -0.98752E-02-0.45559E-02 0.23585E+03 0.55852E+03 0.15068E+03 0.53610E+02
> -0.51468E-02-0.65131E-02 0.23764E+03 0.46920E+03 0.11937E+03 0.55666E+02
> ........................................................................
> ........................................................................
>
>
> First line is a string representing the date info. Then there are 721
> lines representing values over a region on that particular date. This
> pattern repeats after every 721 lines. I have troubles in reading this
> data using readAsciiTable.
>
> I need to store the time information from the first line, and then read
> the next 721 lines of the variables and so on. But when i read using
> readAsciiTable for 6 coloumns, the first line is not read properly. Any
> suggestions on how to get rid of this problem?
> Is there any other handy method to read this data?
>
> PS: I would like the date string to look like 1980_02_26_01_0
> (year_month_day_ensembleNo_parameterNo)
> _______________________________________________

Perhaps, something like the following would work.
This assumes

     header-line
     -----------------
     | 721x6 | set 0
     -----------------
     | 721x6 | set 1
     -----------------
     | 721x6 | set 2
     -----------------
           : :

This is untested.

begin
  tab = asciiread ("xavier.ascii", -1, "float")
 ;print(tab)
  ntab = dimsizes( tab )

  date = sprinti("%0.4i", floattointeger(tab(0))) +"_"+ \ ; year
        + sprinti("%0.2i", floattointeger(tab(1))) +"_+" \ ; month
        + sprinti("%0.2i", floattointeger(tab(2))) +"_"+ \ ; day
        + sprinti("%0.2i", floattointeger(tab(3))) +"_"+ \ ; hour
        + sprinti("%0.1i", floattointeger(tab(4))) ; param

  nhead = 30 ; 6 dates * 5
  nrow = 721
  ncol = 6

  nset = (ntab-nhead)/(nrow*ncol)
  x = onedtond ( tab(nhead+1), (/nset,nrow,ncol/) )

  x!0 = "set"
  x!1 = "row"
  x!2 = "col"

  printVarSummary(x)

end
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Aug 02 2006 - 10:02:55 MDT

This archive was generated by hypermail 2.2.0 : Thu Aug 03 2006 - 09:39:57 MDT