[ncl-talk] Fwd: Reading multiple binary files using addfiles

Dennis Shea shea at ucar.edu
Mon Mar 21 07:41:53 MDT 2016


Kyle is correct. You must read the documentation more carefully. The
'addfiles' and 'addfile' function documentation clearly state they  are for
grib-1/2, netCDF-3/4, hdf-4/5.

If you Click on 'Functions' ... then 'Category' ... then 'File IO' you will
see a list of all IO related functions. Look at the 'binary' file suite.

The 'cpcuni_1.ncl
<http://www.ncl.ucar.edu/Applications/Scripts/cpcuni_1.ncl>' example at

   http://www.ncl.ucar.edu/Applications/HiResPrc.shtml

contains a GrADS control file outlining the contents and structure of the
file. Please look at this.

It is not clear to me if the data should be scaled. I did scale the data
prior to plotting and writing to netCDF. Please change appropriately.

===
Really ... just minor changes to the 'cpcuni_1.ncl
<http://www.ncl.ucar.edu/Applications/Scripts/cpcuni_1.ncl>' example are
necessary.
See Attached script

I prefer to loop over each binary file and create a corresponding netCDF
file. Then, use the 'ncrcat' operator to concatenate all the files; then
delete the intermediate daily netCDF files. This is done via the 'system'
procedure.

===
If you are new to NCL, please read the

http://www.ncl.ucar.edu/Document/Manuals/

(pdf) Mini-Language Manual

An excellent tutorial is at:

DKRZ: NCL Tutorial Version 1.1
<https://dl.dropboxusercontent.com/u/8357888/homepage/tutoriais/ncl/NCL_Tutorial_V1.1.pdf>
and
DKRZ: Examples and Exercises
<https://dl.dropboxusercontent.com/u/8357888/homepage/tutoriais/ncl/NCL_Exercises_and_Tasks_all.pdf>



On Fri, Mar 18, 2016 at 9:28 PM, Kyle Griffin <ksgriffin2 at wisc.edu> wrote:

> I would suggest starting with the section on "Reading Binary Files" under
> File I/O examples on the NCL website.
>
> http://www.ncl.ucar.edu/Applications/r-binary.shtml
>
> You'll see that 'addfiles' is not the best way to read in such files, as
> it will be expecting certain data structures that a binary file won't have.
> 'fbindirread' is the most common function I've used, although I work with
> only limited binary files, none of which are from CPC. Hopefully your data
> source provides a bit more info on the type of binary file to help you
> choose the correct reading function and the correct settings for
> 'setfileoption' function calls, if necessary.
>
> Good luck!
>
>
> Kyle
>
> On Fri, Mar 18, 2016 at 5:36 PM Samar Min Allah <minallah at umich.edu>
> wrote:
>
>> I am trying to convert multiple binary files (CPC_Unified precip data) to
>> netcdf format using the following NCL script:
>> https://www.ncl.ucar.edu/Applications/Scripts/cpcuni_1.ncl
>>
>> I modified the script to read multiple files together by adding the
>> following;
>>
>> diri   = "./"
>> fil   = systemfunc("cd "+diri+" ; ls PRCP_CU_GAUGE_V1.0GLB_0.50deg.lnx.*")
>> nfil = dimsizes(fil)
>>
>> do nf = 0,nfil-1
>>    fili = addfiles(diri+fil(nf),"r")
>> netCDF = True
>>    PLOT   = False
>>
>>    if (netCDF) then
>>        ncDir   = "./"
>>        ncFil   = fili+".nc"
>>    end if
>> .
>> .
>> . *(the remaining code is same as the script)*
>> end do
>>
>> When I run the code; I get this error "*Could not coerce values for
>> operation*"
>> Also, I believe addfiles require a file extension but when I add .bin
>> next to the file name I get the message "*...has no file extension,
>> can't determine type of file to open*"
>>
>> I have also attached two sample files.
>>
>> Thanks!
>>
>> ​​
>>
>>
>>
>>
>> _______________________________________________
>> 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/20160321/da0a6a38/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cpc2nc.ncl
Type: application/octet-stream
Size: 8195 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160321/da0a6a38/attachment.obj 


More information about the ncl-talk mailing list