[ncl-talk] *addfiles* function to span multiple files

Dennis Shea shea at ucar.edu
Fri Aug 12 06:52:07 MDT 2016


NCL uses the order returned by {u/li}nix 'ls' command.

%>  ls ./simulation*.nc

---
So, if the files are named as follows

    simulation_001.nc
    simulation_002.nc
    ...
    simulation_100.nc

you will get this order and you can use the:

    diri = "./"   ; input directory
    fili   = systemfunc("cd "+diri+" ; ls simulation*nc")
    f      = addfiles( diri+fili)

==============

However, the files are named

    simulation_1.nc
    simulation_2.nc
    ...
    simulation_9.nc
    simulation_10.nc
    ...
    simulation_20.nc
    ...
    simulation_30.nc
    ...
    ...
    simulation_100.nc

====
You will get

simulation_1.nc
simulation_10.nc
simulation_100.nc
simulation_2.nc
simulation_20.nc
simulation_30.nc
simulatiom_9.nc

Likely, this is not chronological order.

========================

I just wrote the attached function. If it is in a file named (say)
'myLib.ncl', It can be tested with:

load "./myLib.ncl"

fileName = (/ "simulation_1.nc" ,"simulation_10.nc" ,"simulation_100.nc" \
             , "simulation_2.nc" ,"simulation_20.nc" ,"simulation_30.nc"  \
             , "simulatiom_9.nc" /)
 print(fileName)
print("============")

 filUp     =  filename_reorder_test(fileName, 2, "_.",  1)
 filDown =  filename_reorder_test(fileName, 2, "_.", -1)

 print(fileName+"  "+ filUp+ "  "+filDown)

++++++++++++++++++++++++++++++++++++++++++++++

In your usage case, something like:

load "./myLib.ncl"

   diri = "./"   ; input directory
   fili  = systemfunc("cd "+diri+"  ;  ls simulation*nc")

   fili_new =  filename_reorder_test(fili, 2, "_.",  1)
   print(fili_new)
   print("=====")

; read files in sorted order

   f = addfiles(diri+fili_new, "r")

   temp = f[:]->TEMP
   printVarSummary(temp)
   printMinMax(temp,0)


   Good luck






On Fri, Aug 12, 2016 at 3:43 AM, Michele Petrini <mpetrini139 at yahoo.it>
wrote:

> Dear NCL helpdesk,
>
> I have a question re the *addfiles* function. I am using this function in
> order to read data from an ensemble of 101 NetCDF files - let's say from
> *simulation000*.*nc* to *simulation100*.*nc*.
>
> My question is, what is the order the files are read with? Can I assume is
> from 000 to 100 if I have
>
>  all_files = *systemfunc* <http://www.ncl.ucar.edu/Document/Functions/Built-in/systemfunc.shtml> ("ls ./simulation*.nc")
>      fall      = *addfiles* (all_files, "r")
>
> I ask this because I had a missing value error for the last file - but
> simulation100.nc file seems to be ok. Do you have any clue why this could
> happen?
>
> Thank you for your help,
>
> Best regards
> Michele Petrini
>
> --
>
> ***
> Michele Petrini
>
> Ph.D. student in Earth Science and Fluid Mechanics
>
> Università degli studi di Trieste,
> Dipartimento di Matematica e Geoscienze
> Palazzina C - via Weiss 1, 34128 Trieste, Italy
>
> Email: mpetrini139 at yahoo.it
> Skype: michele.petrins
> Mobile: +39 3398367372
>
>
> _______________________________________________
> 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/20160812/cfdf181b/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: myLib.ncl
Type: text/x-ncl
Size: 706 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160812/cfdf181b/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst_reorder.ncl
Type: text/x-ncl
Size: 741 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160812/cfdf181b/attachment-0001.bin 


More information about the ncl-talk mailing list