[ncl-talk] avoiding loops

Dennis Shea shea at ucar.edu
Sun Sep 22 10:09:38 MDT 2019


As noted by Rashed:

*addfiles*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml>
also:* setfileoption*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/setfileoption.shtml>
These work with netCDF, GRIB and HDF

Say the GFS files begin with: *gfs *and are GRIB [grib1 or grib2]

    *setfileoption*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/setfileoption.shtml>("
*grb*","SingleElementDimensions", (/"Initial_time","Forecast_time"/))
    diri = "..."
    fili  = *systemfunc*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/systemfunc.shtml>("cd
"+diri+"* ; *ls gfs*)
    fgfs = *addfiles*(diri+fili,"r")
    x     = fgfs->X
    printVarSummary(x)   ; ( initial_time0_hours, *forecast_time0,* lat,
lon)

These are concatenated initial times and forecast times
or, if no file extension on the source files, add
   * f*ili = fili + ".grb"
    fgfs = *addfiles*(diri+fili,"r")

Good Luck
D

On Sun, Sep 22, 2019 at 9:39 AM Micah Sklut via ncl-talk <ncl-talk at ucar.edu>
wrote:

> Hi Rashed,
>
> I’m using addfiles to add all of the files, but I want to take the 384
> hours of Data and make one array that has the hourly data concatenated for
> each latitude and longitude.
>
> As far as I can see, loops are the only way to go. I just need a lot of
> memory to pull it off.
>
> On Sun, Sep 22, 2019 at 8:02 AM Rashed Mahmood <rashidcomsis at gmail.com>
> wrote:
>
>> Hi Micah,
>> Did you try using the addfiles function in NCL:
>>
>> https://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml
>>
>> For example:
>>
>>    fils = *systemfunc* <https://www.ncl.ucar.edu/Document/Functions/Built-in/systemfunc.shtml> ("ls *.nc") ; file paths
>>    f    = *addfiles* (fils, "r")
>>
>>
>> You would need to make sure that "ls *.nc" results in the correct order
>> with respect to time and day.
>>
>> Cheers,
>> Rashed
>>
>>
>>
>>
>> On Sat, Sep 21, 2019 at 1:53 PM Micah Sklut via ncl-talk <
>> ncl-talk at ucar.edu> wrote:
>>
>>> Hi,
>>>
>>> I have a task to take GFS data and concatenate variables across all the
>>> forecast hours, for each grid point.
>>>
>>> For example, taking a temperature variable for each grid point, for all
>>> latitude and longitudes, and creating a string that represents the values
>>> for each forecast hour.
>>> So, if we have for latitude y, and longitude x, there would be a string
>>> value like "70.5,71.5,71.5,72.0,...nHours".  The end product will be a line
>>> for each grid point for the variables i"m looking at that will be written
>>> to a file to be imported into a database.
>>>
>>> Creating loops through all hours, latitudes, and longitudes will get the
>>> job done, but is expensive and was looking to see if there were any NCL
>>> functions that would help here.
>>>
>>> Thank you.
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>> --
> Micah Sklut
>
> _______________________________________________
> 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/20190922/f9b308f1/attachment.html>


More information about the ncl-talk mailing list