<div dir="ltr">Ascii/text data sets can be a bit of a nuisance to handle. Good bookkeeping is important. For example, what index should be used to start or end a calculation. Sometimes, as in the file you attached, there are characters that you may want to eliminate. In your file, it is the double quote [ " ].<br><br>I've attached a script that, hopefully, addresses a comment by Damjan concerning his original script: "it is not elegant." Obviously, you have to know something about NCL's function libraries. As we know, one 'good' thing about NCL is that it has a lot of functions; the 'bad' thing is that NCL has lots of functions. :-) or :-(<br><br>Here are some for handling text/ascii.<br><br>See:<br> <a href="http://www.ncl.ucar.edu/Document/Functions/string.shtml">http://www.ncl.ucar.edu/Document/Functions/string.shtml</a><br> <a href="http://www.ncl.ucar.edu/Document/Functions/Contributed/readAsciiTable.shtml">http://www.ncl.ucar.edu/Document/Functions/Contributed/readAsciiTable.shtml</a><br> <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/asciiread.shtml">http://www.ncl.ucar.edu/Document/Functions/Built-in/asciiread.shtml</a><br> <a href="http://www.ncl.ucar.edu/Applications/list_io.shtml">http://www.ncl.ucar.edu/Applications/list_io.shtml</a><br> + Read ascii; Read CSV<br> + Output netCDF<br><br>---<br>Some good programming practices<br><br> [0] Write clear code.<br> Nothing fancy/slick that obscures what you are doing. Optimize only when necessary.<br><br> [1] Code development<br> [a] Use 'print' / 'printVarSummary' / 'printMinMax' to look at variables<br> [b] Test code segments.<br><br> [2] Document code<br><br> [3] Indent code blocks for readability<br><br> [4] Isolate specific and/or repetitive tasks in functions or procedures<br><br> [a] functions when 'something' is to be returned and, subsequently, used.<br> See 'create_time' in attached script<br> [b] procedures when performing specific tasks and nothing is to be returned. For example:<br> [i] Generating a plot. In particular, one with many resource settings.<br> [ii] Creating a file or writing a variable to an existing file (See 'create_var_nc)<br><br> [5] Suggestion: create your own library/libraries to avoid rewriting code.<br> Further, these could serve as the basis for newer functions/procedures.<br><br>---<br><br>One nuisance in Damjan's data file is the double quotes [ " ]. As used by both Rashad's script and the attached script, the following NCL function can be used:<br> <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/str_get_dq.shtml">http://www.ncl.ucar.edu/Document/Functions/Built-in/str_get_dq.shtml</a><br><br>FYI: there is a separate function for single quote [ ' ]<br> <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/str_get_sq.shtml">http://www.ncl.ucar.edu/Document/Functions/Built-in/str_get_sq.shtml</a><br><br>===<br>The attached script has numerous 'print' statements to track what is happening. *Please look at the code and the corresponding output.*<br><br>%> ncl TOA5.DamjanJelic.ncl<br><br>%> ncdump -h TOA5_STUP_10s_5.nc >! ncdump.TOA5<br><br>Good Luck<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 24, 2017 at 5:31 AM, Rashed Mahmood <span dir="ltr"><<a href="mailto:rashidcomsis@gmail.com" target="_blank">rashidcomsis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi Damjan,<br></div>Sure you can contact me directly to discuss similar problems... However, to increase your chances of a best possible answer it is always good to discuss questions on NCL forum.<br><br></div>Cheers,<br></div>Rashed<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 24, 2017 at 2:00 PM, Damjan Jelic <span dir="ltr"><<a href="mailto:dnjelic@gmail.com" target="_blank">dnjelic@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Dear Rashed,<br><br></div><div>thank you very much for the script! it solves my problem for sure and i learn from it very much since it shows several function didnt know exist.<br><br></div><div>i will feel free to contact you directly for similar problems if thats ok with you.<br><br></div><div>Sincerely!<br>from Croatia,<br></div><div>Damjan Jelic<br></div></div><div><div class="h5"><div class="m_-8990326002101029454HOEnZb"><div class="m_-8990326002101029454h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jul 23, 2017 at 12:51 PM, Rashed Mahmood <span dir="ltr"><<a href="mailto:rashidcomsis@gmail.com" target="_blank">rashidcomsis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>Hi Damjan,<br></div>The attached script would read variable names, units and data from the file, and write in a netcdf file. It still needs to specify number of header lines, and the line numbers for variable names and units.<br><br></div>Since the variable and unit names in the text files has double quotes, I had to add a "tric" using two do loops to get rid of double quotes from individual strings (lines:22-36, Perhaps there is some proper way for it which I am not aware of). <br><br></div>The script seems to work fine, I think!. Attached are input,output and the script files.<br><br></div>hope that helps,<br></div>Rashed<br><div><br>Date: Fri, 21 Jul 2017 16:50:07 +0200<br>
From: Damjan Jeli? <<a href="mailto:damjan.jelic@fmf.uni-lj.si" target="_blank">damjan.jelic@fmf.uni-lj.si</a>><br>
Subject: [ncl-talk] new variables from rows<br>
To: <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
Message-ID: <<a href="mailto:81b23a5fb192458c543a235e55871440@fmf.uni-lj.si" target="_blank">81b23a5fb192458c543a235e55871<wbr>440@fmf.uni-lj.si</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Dear NCL support,<br>
<br>
i have txt files (attached) containing 35 different variables which im<br>
trying to save in netcdf format. current problem is that i need to<br>
specify every variable on its own and it is not elegant (attached) and<br>
later on it will be problem since columns will be rearranged in random<br>
order from time to time.<br>
Can it be done somehow like this:<br>
.data=asciiread(...<br>
....<br>
variable_5 = (str_get_field(data(1::),5,","<wbr>))<br>
print(variable_5(0)); which is variable name of column 5<br>
print(variable_5(0))=variable_<wbr>5(3:end)<br>
<br>
or in written form:<br>
i load data, ignore first row,<br>
read data by columns<br>
use first row as new variable name<br>
use second row tu set units<br>
skip 3. row and use all the rest as data.<br>
<br>
Kind regards,<br>
Damjan<br><br></div></div>
</blockquote></div><br></div>
</div></div></div></div></blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>