[ncl-talk] Calling binary files

Barry Lynn barry.h.lynn at gmail.com
Thu Dec 21 00:05:48 MST 2017


If you want to access the files within, you need a do loop to indicate
which file you want to read.

Barry

On Thu, Dec 21, 2017 at 8:54 AM, Arka Banerjee <arka354deb at gmail.com> wrote:

> Awesome, thanks!
>
> So for this a do loop is required?
>
> Arka
>
> On Dec 21, 2017 12:22, "Barry Lynn" <barry.h.lynn at gmail.com> wrote:
>
>> Hi:
>>
>> Here is what you need (example)
>>
>>  DATADir = "/data1/wrf/NAM/"
>>
>>   diri = DATADir  ; you can add "+ date" if you have files listed in
>> directories by date.
>>
>>  all_files = systemfunc("ls " + diri + "nam*grb")
>>
>>  print("all_files = " + all_files)
>>
>>  n_files = dimsizes(all_files)
>>
>>  print("n_files = " + n_files)
>>
>> ;do n=0,n_files -1,1
>>
>>
>>  do n=12,14
>>
>>    print("all_files(n) = " + all_files(n))
>>
>>    filename = all_files(n)
>>
>>    print ("filename" + filename)
>>
>>    a = addfile(filename,"r")
>>
>> On Thu, Dec 21, 2017 at 8:31 AM, Arka Banerjee via ncl-talk <
>> ncl-talk at ucar.edu> wrote:
>>
>>> If one write the following line what does it mean?
>>>
>>> Fn=(/"day1.dat","day2.dat","day3.dat","day4.dat"/)
>>>
>>> The above line is not mean that all dat file names are concatenate in
>>> variable Fn?
>>> I required the same thing for 100 files but without manually putting the
>>> file name.
>>>
>>> That was the question.
>>>
>>> Thanks,
>>> Arka
>>>
>>> On Dec 21, 2017 01:37, "Dennis Shea" <shea at ucar.edu> wrote:
>>>
>>> @Arka: Please read the
>>>
>>> https://www.ncl.ucar.edu/Document/Manuals/
>>>
>>>
>>>    - NCL User Guide, V1.1
>>>    <https://www.ncl.ucar.edu/Document/Manuals/NCL_User_Guide>
>>>    - Mini-Language (pdf)
>>>    <https://www.ncl.ucar.edu/Document/Manuals/language_man.pdf>
>>>
>>> ====================================
>>> NCL does allow a user to specify a *variable *which spans multiple
>>> netCDF, grib or HDF files to (effectively) be concatenated via *addfiles
>>> *and the appropriate* ListSetType *options.
>>> *NOTE: the files are not concatenated ....only the specified variable.*
>>> https://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml
>>> https://www.ncl.ucar.edu/Document/Functions/Built-in/ListSetType.shtml
>>>
>>> =====
>>> There is *no *explicit NCL function which concatenates *binary* or
>>> *text* (ascii)* files*.
>>> Please Read: https://www.ncl.ucar.edu/Applications/r-binary.shtml
>>>
>>> ===
>>> Some options:
>>>
>>> [1] On the {U/Li}nix command line:
>>>
>>> %> *cat* LocalBinaryFiles*dat *>!* BigBinary.dat
>>>
>>> The *!* will overwrite 'BigBinary.dat' if the file currently exits.
>>>
>>> Depending on the binary file type, use:
>>>
>>>     Direct Access:            data = *fbindirread* <https://www.ncl.ucar.edu/Document/Functions/Built-in/fbindirread.shtml>("BigBinary.dat",rec,dim,type)
>>>
>>>     Sequential Access:        data = *fbinrecread* <https://www.ncl.ucar.edu/Document/Functions/Built-in/fbinrecread.shtml>("BigBinary.dat",rec,dim,type)
>>>
>>> *Please read* the documentation for these function:
>>>
>>> http://www.ncl.ucar.edu/Document/Functions/Built-in/fbindirread.shtml
>>> http://www.ncl.ucar.edu/Document/Functions/Built-in/fbinrecread.shtml
>>>
>>> also, binary files could be '*BigEndian*" or '*LittleEndian**. *The following allows you to specify
>>>
>>> http://www.ncl.ucar.edu/Document/Functions/Built-in/isbigendian.shtml
>>>
>>>  if (*isbigendian*() ) then   ; is local machine big or little endian?
>>>      *setfileoption* <http://www.ncl.ucar.edu/Document/Functions/Built-in/setfileoption.shtml>("bin","ReadByteOrder","LittleEndian")
>>>  end if
>>>
>>>  x = *fbindirread*(...)
>>>
>>> or
>>>
>>>  c = *fbinrecread*(...)
>>>
>>> Sfter you are finished, you may want to delete the 'BigBinary.dat' file
>>>
>>> %> rm BigBinary.dat
>>>
>>> Or, perhaps the individual binary files and keep the concatenated file:
>>>
>>> %> rm LittleBinary*dat
>>>
>>>
>>> [2]
>>>
>>> diri = ".../"    ; input dir
>>>
>>> if (*.not.fileexists*("BigBinary.dat")) then
>>>
>>>     system("cat LocalBinary*dat >! "BigBinary.dat")
>>>
>>> end if
>>>
>>>
>>>     Direct Access:            data = *fbindirread* <https://www.ncl.ucar.edu/Document/Functions/Built-in/fbindirread.shtml>("BigBinary.dat",rec,dim,type)
>>>
>>>     Sequential Access:        data = *fbinrecread* <https://www.ncl.ucar.edu/Document/Functions/Built-in/fbinrecread.shtml>("BigBinary.dat",rec,dim,type)
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Wed, Dec 20, 2017 at 10:27 AM, Laura Fowler via ncl-talk <
>>> ncl-talk at ucar.edu> wrote:
>>>
>>>> Hi Arka:
>>>>
>>>> I usually use systemfunc, followed with ListSetType, and then addfiles
>>>> to read a bunch of the same kind of files together. There are lots of
>>>> examples on how to use systemfun on the ncl web site.
>>>>
>>>> Hope this helps,
>>>> Laura
>>>>
>>>>
>>>> On Wed, Dec 20, 2017 at 9:13 AM, Arka Banerjee via ncl-talk
>>>> <ncl-talk at ucar.edu> wrote:
>>>> > Hi all,
>>>> >
>>>> > How to concatenate all file names in a single variable in NCL? I have
>>>> 100 of
>>>> > .dat files in a directory and I want to call them all in a variable
>>>> like
>>>> > below;
>>>> >
>>>> > fn=(/"gsmap_nrt.20100805.0600.dat","gsmap_nrt.20100805.0900.dat"/)
>>>> >
>>>> > So that 'fn' will be re-structured for 100 of .dat files in the same
>>>> way of
>>>> > above line.
>>>> >
>>>> >
>>>> > How to execute this thing? Function 'addfiles' helps in this case? As
>>>> I have
>>>> > found it is not for ascii formate.
>>>> >
>>>> >
>>>> > Thanks,
>>>> >
>>>> > Arka
>>>> >
>>>> > _______________________________________________
>>>> > ncl-talk mailing list
>>>> > ncl-talk at ucar.edu
>>>> > List instructions, subscriber options, unsubscribe:
>>>> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>> >
>>>>
>>>>
>>>>
>>>> --
>>>> !-----------------------------------------------------------
>>>> --------------------------------------------------
>>>> Laura D. Fowler
>>>> Mesoscale and Microscale Meteorology Division (MMM)
>>>> National Center for Atmospheric Research
>>>> P.O. Box 3000, Boulder CO 80307-3000
>>>>
>>>> e-mail: laura at ucar.edu
>>>> phone: 303-497-1628
>>>>
>>>> !-----------------------------------------------------------
>>>> --------------------------------------------------
>>>> _______________________________________________
>>>> 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
>>>
>>>
>>
>>
>> --
>> Barry H. Lynn, Ph.D
>> Senior Lecturer,
>> The Institute of the Earth Science,
>> The Hebrew University of Jerusalem,
>> Givat Ram, Jerusalem 91904, Israel
>> Tel: 972 547 231 170
>> Fax: (972)-25662581
>>
>> C.E.O, Weather It Is, LTD
>> Weather and Climate Focus
>> http://weather-it-is.com
>> Jerusalem, Israel
>> Local: 02 930 9525
>> Cell: 054 7 231 170
>> Int-IS: x972 2 930 9525
>> US 914 432 3108 <(914)%20432-3108>
>>
>


-- 
Barry H. Lynn, Ph.D
Senior Lecturer,
The Institute of the Earth Science,
The Hebrew University of Jerusalem,
Givat Ram, Jerusalem 91904, Israel
Tel: 972 547 231 170
Fax: (972)-25662581

C.E.O, Weather It Is, LTD
Weather and Climate Focus
http://weather-it-is.com
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
US 914 432 3108
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171221/5f3ec6f1/attachment.html>


More information about the ncl-talk mailing list