[ncl-talk] How to select specific strings from input filenames and use it for output filenames

Lyndon Mark Olaguera olagueralyndonmark429 at gmail.com
Mon Sep 25 01:33:49 MDT 2017


Thank you Guido for the fast response.

I got it already. I used the *str_get_cols* to accomplish this.


Sincerely,

Lyndz



On Mon, Sep 25, 2017 at 4:06 PM, Guido Cioni <guidocioni at gmail.com> wrote:

> Yes there is,
> see here https://www.ncl.ucar.edu/Document/Functions/Built-in/
> str_sub_str.shtml and here https://www.ncl.ucar.edu/
> Document/Functions/Built-in/str_split_by_length.shtml.
>
> Il giorno 25 set 2017, alle ore 07:20, Lyndon Mark Olaguera <
> olagueralyndonmark429 at gmail.com> ha scritto:
>
> Dear NCL-experts,
>
> I am trying to read and process multiple csv files. Here is my script:
>
>
> begin
>    diri     = "./"
>    files     = systemfunc("ls *.csv")
>    numfiles = dimsizes(files)
>    do ifil  = 0,numfiles-1
>      lines    = asciiread(files(ifil),-1,"string")
>      data        = lines(1:)
>      ;print(data)
>      rain        = tofloat(str_get_field(data,1,","))
> ;;***************************************************
> ;;Apply 1-2-1 running average (three pentads)
> ;;****************************************************
>   x = wgt_runave(rain, (/0.25, 0.50, 0.25/), 0)
>   x at _FillValue = -9999
> ;;****************************************************
> ;;Save output to a csv file
> ;;****************************************************
>   flname = files(ifil)+"_filt.csv"
>   asciiwrite(flname,x)
>   end do
> end
>
>
> Question:
>
> [1] The output of this script is like this:
>
> *sg_X1980.csv_filt.csv*
>
> I want the output to be like : sg_X1980_filt.csv
>
> Is there a way to "cut" or "select" specific strings from the input
> filename and use it for the output filename.
>
> I'll appreciate any help.
>
> Sincerely,
>
> Lyndz
>
>
>
> _______________________________________________
> ncl-talk mailing list
> 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/20170925/32b6e574/attachment.html>


More information about the ncl-talk mailing list