[ncl-talk] About how to use a variable in str_get_filed

Dennis Shea shea at ucar.edu
Wed Dec 7 22:23:57 MST 2016


When I read your code, it is indicated that there are 46 lines of data.
The ascii (text) file has 12 lines (1 header line, 11 lines with dates)

So ..
[a] You included only part of the data
or
[b] the 46 in not what you think its is.
======================================================
The attached script and data produce:
======================================================


(0)    nlines=12
(0)    international_no=1517
(0)    number_of_dataline_str=046
(0)    number_of_dataline=46
(0)    name=KILO


Variable: date
Type: string
Total Size: 80 bytes
            10 values
Number of Dimensions: 1
Dimensions and sizes:    [10]
Coordinates:
(0)    15090118
(1)    15090200
(2)    15090206
(3)    15090212
(4)    15090218
(5)    15090300
(6)    15090306
(7)    15090312
(8)    15090318
(9)    15090400



On Wed, Dec 7, 2016 at 6:14 PM, Tao Lu <hakufu.asano at gmail.com> wrote:

> Hello Shea
>
> Thank you for your reminding.
> I have solved this problem.
>
> Here is my code:
> begin
> ;file = (/"bst_kilo_2015", "bst_etau_2015"/)
> ; read ascii data------------------------------------------------------
> lines = asciiread("./bst_etau_2015",-1,"string")
>
> ; read  data
> delimiter = " "
> international_no = str_get_field(lines(0),2, delimiter)
> number_of_dataline_str = str_get_field(lines(0),3, delimiter)
> number_of_dataline = toint(number_of_dataline_str)
> name = str_get_field(lines(0),8, delimiter)
> date = str_get_field(lines(1:number_of_dataline+1), 1, delimiter)
>
> Here is my data form:
> 66666 1517  046 0017 1517 1 0                 KILO              20151013
> 15090118 002 7 237 1801  945     090     20060 0040 20150 0100
> 15090200 002 5 240 1798  950     080     90060 0060 10150 0120
> 15090206 002 5 244 1794  950     080     90060 0060 80150 0120
> 15090212 002 5 246 1791  965     070     90060 0060 80150 0120
> 15090218 002 5 246 1785  965     070     80070 0050 70150 0120
> 15090300 002 5 247 1782  965     070     80070 0050 90150 0150
> 15090306 002 5 246 1781  965     070     80070 0050 90150 0150
> 15090312 002 5 244 1777  965     070     80070 0050 90150 0150
> 15090318 002 5 241 1775  965     070     80070 0050 90150 0150
> 15090400 002 5 238 1771  970     065     70100 0060 70180 0120
> 15090406 002 5 236 1766  970     065     70100 0060 70200 0120
>
> When I run the script, such error appeared:
> fatal:Subscript out of range, error in subscript #0
> fatal:An error occurred reading lines
> fatal:["Execute.c":8575]:Execute: Error occurred at or near line 19 in
> file best_track_plot.ncl
>
> The problem is at "number_of_dataline+1".
>
> Thank you.
>
> Tao
>
>
>
> On Wed, Dec 7, 2016 at 11:25 PM, Dennis Shea <shea at ucar.edu> wrote:
>
>> Not enough information:  What was the error message?
>>
>> Also, including the, say, first 5 lines of the field being read would be
>> useful.
>>
>> Regards
>>
>>
>>
>>
>> On Wed, Dec 7, 2016 at 3:56 AM, Tao Lu <hakufu.asano at gmail.com> wrote:
>>
>>> Dear ncl-talk
>>>
>>> I wrote some codes to use str_get_field()
>>> ------------------------------------------------------------
>>> ----------------------------------------------------------
>>> number_of_dataline = toint(number_of_dataline_str)
>>> print (number_of_dataline)
>>> name = str_get_field(lines(0),8, delimiter)
>>> date = str_get_field(lines(1:number_of_dataline+1), 1, delimiter)
>>> ------------------------------------------------------------
>>> -----------------------------------------------------------
>>> Error occurred at "date".
>>>
>>> Could you give me some advice?
>>>
>>> Yours sincerely,
>>> Tao
>>>
>>> --
>>> ******************************************************
>>> 盧 涛 (ル タオ) 修士課程2年
>>>
>>> 〒112-8551 東京都文京区春日1-13-27
>>>
>>> 中央大学理工学研究科都市環境学専攻
>>>
>>> 河川・水文研究室(山田正教授)
>>>
>>>
>>> TEL: 03-3817-3406;   Phone: 070-2188-7509
>>> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
>>> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
>>> *******************************************************
>>> ******************************************************
>>> Tao Lu    (M. Eng)
>>> Laboratory of River Engineering and Hydrology,
>>> Dept. of Civil and Environmental Engineering,
>>> Graduate School of Science and Engineering,
>>> Chuo University
>>>
>>> 1-13-27,Kasuga,Bunkyo-ku,Tokyo
>>> 112-8551, Japan
>>> TEL: 03-3817-1805;   Phone: 070-2188-7509
>>> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
>>> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
>>> *****************************************************
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
>
> --
> ******************************************************
> 盧 涛 (ル タオ) 修士課程2年
>
> 〒112-8551 東京都文京区春日1-13-27
>
> 中央大学理工学研究科都市環境学専攻
>
> 河川・水文研究室(山田正教授)
>
>
> TEL: 03-3817-3406;   Phone: 070-2188-7509
> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
> *******************************************************
> ******************************************************
> Tao Lu    (M. Eng)
> Laboratory of River Engineering and Hydrology,
> Dept. of Civil and Environmental Engineering,
> Graduate School of Science and Engineering,
> Chuo University
>
> 1-13-27,Kasuga,Bunkyo-ku,Tokyo
> 112-8551, Japan
> TEL: 03-3817-1805;   Phone: 070-2188-7509
> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
> *****************************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161207/f83b7cdb/attachment.html 
-------------- next part --------------
66666 1517  046 0017 1517 1 0                 KILO              20151013
15090118 002 7 237 1801  945     090     20060 0040 20150 0100          
15090200 002 5 240 1798  950     080     90060 0060 10150 0120          
15090206 002 5 244 1794  950     080     90060 0060 80150 0120          
15090212 002 5 246 1791  965     070     90060 0060 80150 0120          
15090218 002 5 246 1785  965     070     80070 0050 70150 0120          
15090300 002 5 247 1782  965     070     80070 0050 90150 0150          
15090306 002 5 246 1781  965     070     80070 0050 90150 0150          
15090312 002 5 244 1777  965     070     80070 0050 90150 0150          
15090318 002 5 241 1775  965     070     80070 0050 90150 0150          
15090400 002 5 238 1771  970     065     70100 0060 70180 0120          
15090406 002 5 236 1766  970     065     70100 0060 70200 0120          
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TaoLu.ncl
Type: text/x-ncl
Size: 904 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161207/f83b7cdb/attachment.bin 


More information about the ncl-talk mailing list