[ncl-talk] NCL Issue: write_matrix() file output

Dennis Shea shea at ucar.edu
Mon Oct 23 13:34:09 MDT 2017


For clarity, I removed the hard code numbers

        nrow  = 5
        ncol   = 10
        hd_array = *generate_2d_array*(20,20,-1,1,0,(/nrow,ncol/))
        hd_dims = *dimsizes*(hd_array)

        fmtHD  = nrow + "f7.2"
        *write_matrix*(hd_array,fmtHD,False)

        TXTdir = "./"
        TXTout = "example.txt"
        TXTpth = TXTdir + TXTout
        *system*("/bin/rm -f "+TXTpth)    ; rm any pre-existing file

        opt1 = True
        opt1 at fout = TXTpth
        *write_matrix*(hd_array,fmtHD,opt1)

====
Note:
If you are "new to NCL", I suggest that you read the excellent tutorial by
DKRZ at:

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

NCL User Guide, V1.1
<https://www.ncl.ucar.edu/Document/Manuals/NCL_User_Guide>

There are many examples.
====

When posting to ncl-talk, it helps if users include the version of NCL they
are using.

%> ncl -V

====
>From NCL 6.2.0 onward, the following libraries are 'auto-loaded'

    "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
    "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
    "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

Also, you do not need the '*begin*' and '*end*' for the MAIN script

>From NCL 6.4.0 onward, the following libraries are 'auto-loaded'

    "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
    "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
    "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
    "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
    "$NCARG_ROOT/lib/ncarg/nclscripts/csm/bootstrap.ncl"
    "$NCARG_ROOT/lib/ncarg/nclscripts/csm/extval.ncl"
    "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

===

Good luck




On Mon, Oct 23, 2017 at 11:51 AM, David Ross <rossdl2 at appstate.edu> wrote:

> Hello,
>
> I am a new user to NCL, at Appalachian State University in NC. Our
> research group is interested in exporting formatted tables of WRF output
> data into a standard ascii text file. I will use a simplified example
> matrix, as building the real one requires WRF output files and a
> complicated loop structure. My issue is specifically with the
> write_matrix() command.
>
> hd_array = generate_2d_array(20,20,-1,1,0,(/5,10/))
> hd_dims = dimsizes(hd_array)
>
> The matrix "hd_array" has been successfuly built and yields a nicely
> formatted matrix to the standard output (terminal) with the code below:
>
> fmtHD = str_concat((/tostring(hd_dims),"f5.2"/))
> write_matrix(hd_array,fmtHD,False)
>
> However, when the option is set to write the matrix to a text file, the
> file "example.txt" comes up empty even though the command executes without
> giving errors.
>
> What am I missing here?
>
> -David
>
>
>
>
> _______________________________________________
> 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/20171023/752d16b4/attachment.html>


More information about the ncl-talk mailing list