[ncl-talk] reading station data

Debasish Hazra debasish.hazra5 at gmail.com
Fri Feb 6 10:05:37 MST 2026


Many thanks Dave. It worked fine. I think I need a way to detect the
position automatically as I found it does not always start at line 7, that
will be helpful.
Also, I am trying to write the columns that I read into a csv file, but not
getting right for the middle column. Any suggestions? Attached the code and
output csv file as well.

Debasish.

On Fri, Feb 6, 2026 at 2:14 AM Dave Allured - NOAA Affiliate <
dave.allured at noaa.gov> wrote:

> Debasish, you have almost everything right, except for the position of
> field names, and start of data.  You have:
>
>       field_names = str_split(lines(0),delim)
>
> But the field names are on line 7, not line 1.  Change this to get the
> field names from line 7.  Since NCL uses zero-based indexing, the correct
> line index is 7 - 1 = 6.
>
>       field_names = str_split(lines(6),delim)
>
> Likewise, data lines start on the next line after the field names, at line
> index 7.  This should clear up the header errors:
>
>       mhs = str_get_field(lines(7:),2,delim)       ... etc.
>
> If you are processing a lot of data, then the start of data can change
> between files.  Can you have start of data hard coded at 7, or do you need
> a way to detect the position automatically?
>
>
> On Thu, Feb 5, 2026 at 9:42 AM Debasish Hazra <debasish.hazra5 at gmail.com>
> wrote:
>
>> Thanks Dave and Dennis for your suggestions. I followed the examples and
>> created a script to read the file I sent earlier, but it seems to be I am
>> still getting some header information in the column I am trying to extract.
>> Attached are output and script that was used, any suggestions to overcome
>> this issue.
>>
>> Debasish.
>>
>> On Tue, Feb 3, 2026 at 5:50 PM Dave Allured - NOAA Affiliate <
>> dave.allured at noaa.gov> wrote:
>>
>>> Debasish, that is a CSV file with header lines.  Use *asciiread* to
>>> read the entire file as strings.  Then use string parsing functions such as
>>> *str_split_csv* and/or *str_get_field* to get individual columns.
>>> Examples *csv_3.ncl* and *csv4_ncl* are close to what you want to do.
>>>
>>>       https://www.ncl.ucar.edu/Applications/read_csv.shtml
>>>
>>>
>>> On Tue, Feb 3, 2026 at 12:38 PM Debasish Hazra via ncl-talk <
>>> ncl-talk at mailman.ucar.edu> wrote:
>>>
>>>> Hi,
>>>> I am trying to read station data with header and column of data, with
>>>> COlumn lengths are not equal in files and have attached one example file in
>>>> the attachment.  Can someone help to point what ascii read command to be
>>>> used to extract time and column information from these files.
>>>> Thanks
>>>> Debasish.
>>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20260206/8a5cf861/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BamendaTest_202404.csv
Type: application/vnd.ms-excel
Size: 5208 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20260206/8a5cf861/attachment.xlb>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: extract.ncl
Type: application/octet-stream
Size: 1432 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20260206/8a5cf861/attachment.obj>


More information about the ncl-talk mailing list