[ncl-talk] file with each line having varied length
Zhang, Xiao
xiao.zhang at pnnl.gov
Thu May 18 10:18:44 MDT 2017
Dennis and Dave,
Thanks for your help! The question is more complicated than just reading in. I’ll try to explain more clearly.
For example, each line first column refers to an ID (“ID”), and the following are other grid cells associated with this grid (“Vari_ID”). Now I have a mask file and need to select all associated grid cells (Vari_ID) belonging to the mask file and the output file should have same format as input which is ID first and then associate grid cells. As the file has more than 4000 rows, it would be almost impossible to check the column number in each line and then count over. Do you know a good way to solve the problem?
Best,
Xiao
From: Dennis Shea [mailto:shea at ucar.edu]
Sent: Thursday, May 18, 2017 7:44 AM
To: Zhang, Xiao
Cc: ncl-talk at ucar.edu
Subject: Re: [ncl-talk] file with each line having varied length
The question leaves out many details. What is it that you want?
x = asciiread("foo.txt",-1,"integer") ; x will be one-dimensional
nx = dimsizes(x)
print("nx="+nx)
print("---")
print(x)
On Wed, May 17, 2017 at 11:25 PM, Zhang, Xiao <xiao.zhang at pnnl.gov<mailto:xiao.zhang at pnnl.gov>> wrote:
Hi I have a question in processing a file. Each line of this file has different length. For example, first line has 5 integers and second line has 9. And there are over 4000 lines. Is there a good way to deal with it? Thanks!
_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170518/8a839fee/attachment.html
More information about the ncl-talk
mailing list