[ncl-talk] avoiding loops

Micah Sklut micahs2005 at gmail.com
Sun Sep 22 11:28:01 MDT 2019


Hi, thanks,

My problem is more on the output side. I do addfiles, and then I'm reading
in the variables with NCL, like this:

u = f[:]->UGRD_P0_L103_GLL0(:,{latNGFS:latSGFS},{lonWGFS:lonEGFS})
v = f[:]->VGRD_P0_L103_GLL0(:,{latNGFS:latSGFS},{lonWGFS:lonEGFS})
prate = f[:]->PRATE_P0_L1_GLL0(:,{latNGFS:latSGFS},{lonWGFS:lonEGFS})
t = f[:]->TMP_P0_L103_GLL0(:,{latNGFS:latSGFS},{lonWGFS:lonEGFS})

Currently, I'm passing this data to a Fortran wrapper, because it's always
seemed easier than writing data in NCL. I loop through time, lat, lon to
create concatenated strings for each variable (u,v,prate,t). Then, I loop
through lat, and lon to write 1 line to a file for each latitude and
longitude. So, the output lines will look something like this:
-77.5,0,"15.36;15.25,14.5...","354;350;349,...","273.3;274.5;275.8...","0;0;0;...","999;1002;1002;..."

The first 2 values represent latitude and longitude, and then the
concatenated strings for wind speed, wind direction (converting u and v),
prate, and t. There would be exactly latitude x longitude lines in the
output file. So, again, just wondering if there is a more efficient way to
write this output file.



On Sun, Sep 22, 2019 at 12:09 PM Dennis Shea <shea at ucar.edu> wrote:

> 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
>
>

-- 
Micah Sklut
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190922/2e8d4a47/attachment.html>


More information about the ncl-talk mailing list