>
>I need some help reading an ASCII file with NCL. The file
>contains a mixture of text, floats, and times and has the
>following format:
>
> YY/MM/DD HH:MM HH.MM Kd Kn Max Ratio
> 01/08/12 00:00 0.00 547.5 439.3 528.9 1.04
> 01/08/12 00:05 0.08 414.2 321.6 517.5 0.80
> 01/08/12 00:10 0.17 562.6 445.5 494.5 1.14
> 01/08/12 00:15 0.25 426.3 338.7 482.7 0.88
> 01/08/12 00:20 0.33 486.2 382.8 470.9 1.03
> 01/08/12 00:25 0.42 480.9 383.2 459.0 1.05
> 01/08/12 00:30 0.50 339.6 262.6 434.8 0.78
> 01/08/12 00:35 0.58 382.8 296.0 422.6 0.91
> 01/08/12 00:40 0.67 360.7 284.4 410.3 0.88
> 01/08/12 00:45 0.75 308.9 237.7 397.9 0.78
> 01/08/12 00:50 0.83 407.4 314.5 372.8 1.09
> 01/08/12 00:55 0.92 357.3 275.9 360.2 0.99
> 01/08/12 01:00 1.00 249.2 187.5 347.5 0.72
> 01/08/12 01:05 1.08 242.9 182.8 334.7 0.73
> <rest of file deleted>
>
>I would like to skip the header and read each column into a
>vector of appropriate type. If I use the following command
Hello
Normally I read this type of file via a fortran subroutine.
It is quite easy, in particular, if you have the
WRAPIT tool that has been distributed with the more recent
versions of NCL.
I know that you has a very old version of NCL (4.2.0.a009)
so you do not have WRAPIT. Still using fortran from with NCL
is reasonably straightforward. However,
upon examing your file, it appears that it has *2*
carriage controls at the end of each line. This results
is some strange behavior.
Anyway here is a script that will read your file.
begin
diri = "./"
fili = "ascii.data"
dStr = asciiread (diri+fili, -1, "string")
dChr = stringtochar (dStr)
;print(dChr)
; FYI only
;nRow = dimsizes(dStr) ; includes header
;nrow = nRow-1 ; number of numeric rows
; note the (1:,..) ; this array syntax causes the 1st row to be skipped
yy = stringtointeger( chartostring(dChr(1:,1:2)) )
mo = stringtointeger( chartostring(dChr(1:,4:5)) )
dd = stringtointeger( chartostring(dChr(1:,7:8)) )
hh = stringtointeger( chartostring(dChr(1:,10:11)) )
mm = stringtointeger( chartostring(dChr(1:,13:14)) )
hhmm = stringtofloat( chartostring(dChr(1:,16:20)) )
Kd = stringtofloat( chartostring(dChr(1:,22:27)) )
Kn = stringtofloat( chartostring(dChr(1:,30:35)) )
zMax = stringtofloat( chartostring(dChr(1:,38:43)) )
rat = stringtofloat( chartostring(dChr(1:,47:51)) )
print (yy+" "+mo+" "+dd+" "+hh+" "+mm+" "+hhmm+" "+ \
Kd+" "+Kd+" "+Kn+" "+zMax+" "+rat)
end
======
Regards
Dennis Shea
This archive was generated by hypermail 2b29 : Tue Mar 19 2002 - 14:32:19 MST