Re: ascii-read multiple column with comma-delimiter

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sun, 18 Nov 2007 20:43:47 -0700

ALl ...
Erik sent a sample file. [apprneded]

The function readAsciiTable can be used to read a
file which has header records.

http://www.ncl.ucar.edu/Document/Functions/Contributed/readAsciiTable.shtml

===
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
    diri = "./"
    fili = "Daily-short"

    ncol = 8
                          ; skip the first header line
    data = readAsciiTable(diri+fili, ncol, "float", 1)
    print(data)
end
====================

TimeCET,TemperatureF,Dew PointF,Humidity,Sea Level
PressureIn,VisibilityMPH,Wind Direction,Wind SpeedMPH,Gust
SpeedMPH,PrecipitationIn,Events,Conditions<br />
12:00 AM,60.8,39.2,45,30.18,-9999.0,WNW,20.7,-,N/A,,Clear<br />
12:30 AM,60.8,41.0,48,30.21,-9999.0,WNW,17.3,-,N/A,,Clear<br />
<!-- 0.183:0 -->

ern_at_student.matnat.uio.no wrote:
> Hi, thanks for the very quick reply.
> Sorry to maybe have called too soon, think that I managed to see where the
> problem was..
>
> At line 323 in the attached file "read-ascii-month-automatic-ncl.ncl", I
> changed:
>
> "header = read_data(0)" to "header = read_data(1)"
> and
> "data = read_data(1:)" to "data = read_data(2:(nrows_tott-2))"
>
> That way "data" contains what I want.
>
>
> But:
> Another question arose while working with this:
> Since I have so many ascii files which I would like to read I am trying to
> find a way to read them through without having to run the script over
> again. As far as I have understood it is not possible to use something
> like "addfiles" for ascii-files so I was thinking of making a big
> "do-loop" where I change the file to be read every turn.
> (Actually, all the files have the same name, but they are put in folders
> with different names (there is one file in each folder) and it is the
> folder-name that I change in the loop).
> It seems to work fine to change the file to be read in this way -if not in
> a loop-. At line 292 I may change the directory to be read manually (1, 2,
> 3, etc..), and I get the correct data out. But if I use the loop at line
> 291 (it ends at line 505) I get the following message:
>
> fatal:Dimension sizes of left hand side and right hand side of assignment
> do not match
> fatal:Execute: Error occurred at or near line 320 in file
> ASCII/read-ascii-month-automatic-ncl.ncl
>
> where line 320 is:
> read_data = asciiread(filename,-1,"string")
>
> I have been trying several different approaches to define the variable
> "read_data" as
> an array to be able to hold the information in the various ascii files,
> but I don't understand how I could do this.. I have tried to make it as a
> 2d-array since I assume that "read_data" already is a 1d-array, but I am
> not sure how this array should be set up properly (if this at all is the
> right approach..??)
>
> What I then would like to do is to write all the data from the different
> ascii files into the same ascii file.
> Do you have any idea of how this could be done?
>
> Also attached is a short sample of the ascii files that I read in.
>
> Thank you so much for your help-
> Erik
>
>
>
>
>
>
>
>
>
>
>
>> Hello
>>
>> Could you please send the first few lines of the ascii file?
>>
>> THX
>>
>>
>> ern_at_student.matnat.uio.no wrote:
>>> Hi NCL-talk,
>>> I am using the example script:
>>> ascii_delim.ncl
>>> found at:
>>> http://www.ncl.ucar.edu/Applications/ascii_delim.shtml
>>>
>>> This works fine if I use files in the same format as the example-file,
>>> but
>>> now I have files that look like the example-file except from:
>>> an additional blank row at the beginning of the file (before the
>>> "header"), and
>>> an additional row with some text at the end of the file (the last row).
>>>
>>> This does not work (of course..) but I do not know how to change the
>>> script to be able to read the files that I have.
>>>
>>> I could always erase these two additional rows and it all works fine,
>>> but
>>> I have A LOT of files to read so that would take a lot of time.
>>>
>>> Does anyone have an idea of how to modify the "ascii_delim.ncl" -script
>>> to
>>> be able to read files on the format that I have to read.
>>> (-i.e, I want to skip the first and last rows in the files)
>>>
>>> Thanks for your help!
>>> Erik
>>>
>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk_at_ucar.edu
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun Nov 18 2007 - 20:43:47 MST

This archive was generated by hypermail 2.2.0 : Sun Nov 25 2007 - 07:21:25 MST