[ncl-talk] Selecting same date
Dennis Shea
shea at ucar.edu
Tue Mar 3 20:17:18 MST 2020
If the text files are structured like the example file (date grouped
together).
Please look at the printed output.
Basically, it is a book-keeping issue.
--
diri = "./"
fili = "test_vanucia.txt"
pthi = diri+fili
asciifile = asciiread( pthi, -1, "string" )
nlines = dimsizes( asciifile )
dates = str_get_field( asciifile(1:nlines-1), 1, " " ) ; skip 1st line
print(dates)
ndates= dimsizes(dates)
inew = ind(dates(0:ndates-2).ne.dates(1:)) ; index values
print(inew)
ngroup = dimsizes(inew)
iStrt = 0
iLast = inew(0)
diro = "./"
do ng=1,ngroup
print("---")
print(""+asciifile(iStrt+1:iLast+1))
filo = dates(iStrt)+".txt"
ptho = diro+filo
system("/bin/rm -f "+ptho) ; remove any prexisting
file
asciiwrite(ptho,asciifile(iStrt+1:iLast+1))
if (ng.ne.ngroup) then
iStrt = iLast+1
iLast = inew(ng)
end if
end do
On Tue, Mar 3, 2020 at 11:39 AM Vanúcia Schumacher via ncl-talk <
ncl-talk at ucar.edu> wrote:
> Hi Mateus.
> Thanks for the feedback, but this is not what I intend to do.
>
> In my ascii file, I have several lines with the same date (e.g.
> 2018-01-01, ...) and in this proposed way, I would save 1 file for each
> line. However, what I need is to save each file for each unique date.
> With the "test.txt" data I have 9 different dates, which I need to save as
> 9 different ascii files, containing all the information.
> The function I used selects the dates in common, but I am missing
> something in the loop to save joining this information.
>
> Thanks for the advance
> ------------------------------
> *De:* Mateus da Silva Teixeira <mateusstex at gmail.com>
> *Enviado:* terça-feira, 3 de março de 2020 15:19
> *Para:* Vanúcia Schumacher <vanucia-schumacher at hotmail.com>
> *Cc:* ncl-talk at ucar.edu <ncl-talk at ucar.edu>
> *Assunto:* Re: [ncl-talk] Selecting same date
>
> Hi Vanucia,
>
> Take a look at the following lines:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> * asciifile = asciiread( "test.txt", -1, "string" ) nlines = dimsizes(
> asciifile ) dates = str_get_field( asciifile(1:nlines-1), 1, ";" )
> dates_nano = str_get_field( asciifile(1:nlines-1), 2, ";" ) lat =
> str_get_field( asciifile(1:nlines-1), 3, ";" ) lon = str_get_field(
> asciifile(1:nlines-1), 4, ";" ) pico_ka = str_get_field(
> asciifile(1:nlines-1), 5, ";" ) print( dates ) print( dates_nano )
> print( lat ) print( lon ) print( pico_ka )*
>
> After reading all data, you can easily save them in an ascii file. Of
> course, if you want to make some calculations with these data you should
> convert from string to float.
>
> Best regards,
> Mateus
>
>
> Em ter., 3 de mar. de 2020 às 12:01, Vanúcia Schumacher via ncl-talk <
> ncl-talk at ucar.edu> escreveu:
>
> Hi users,
>
> I need help to fix my ncl script,
> what I'm trying to do is select all the same dates from the ascii file
> (test.txt) and save it
> in a new ascii file (refers to each date), but I'm not able to get all the
> values for each date.
>
> I attached the test data and the script
>
> I appreciate any help
>
> Cheers
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> 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/20200303/aedb091b/attachment.html>
More information about the ncl-talk
mailing list