incorrectly writing a matrix to a text file

From: Sam McClatchie (NOAA Federal) <sam.mcclatchie_at_nyahnyahspammersnyahnyah>
Date: Fri Aug 09 2013 - 12:56:02 MDT


I am doing something incorrectly when attempting to write a matrix to a
text file. The content of my text file suggests that I am not formatting
the output correctly:

This is what the content looks like (i.e. rubbish!):

Here is a snippet of the data from the head of the file:





and from the tail of the file:





Here is the code which incorporates code from various examples:

;; CalCOFI_10m_properties.ncl

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"


;---Read the values in as 1D, since we don't know rows and columns yet.
   filename =
   values_1d = asciiread(filename,-1,"string")
   ncols = dimsizes(str_split(values_1d(0),","))
   nrows = dimsizes(values_1d)

;---Reshape as 2D array
   values_2d = tofloat(onedtond(values_1d,(/nrows,ncols/)))
   print("'" + filename + "' has " + nrows + " rows and " + ncols + \
   " columns of data.")

;---Check for missing value and convert to printable length
   if(any(ismissing(values_2d))) then
     print("Your data contains some missing values. Beware.")
   end if
   print("missing value code: "+values_2d@_FillValue)
   xmsg = values_2d@_FillValue ; save _FillValue
   values_2d@_FillValue = -9999.0 ; change to fit printable
   print("new missing value code: "+values_2d@_FillValue)

;---Pretty print matrix to ascii file
   print("Fortran format "+ncols+"f7.2")
   write_matrix(values_2d, ncols+"f7.2", opt)


The script runs fine, except for the specified problem, e.g.:

ncl CalCOFI_10m_properties.ncl

  Copyright (C) 1995-2012 - All Rights Reserved
  University Corporation for Atmospheric Research
  NCAR Command Language Version 6.1.0
  The use of this software is governed by a License Agreement.
  See for more details.

has 32468 rows and 12 columns of data.
(0) 32468
(1) 12
(0) missing value code: 9.96921e+36
(0) new missing value code: -9999
(0) Fortran format12f7.2

Any hints as to where I am going wrong here, please? I suspect that it
is something to do with the lack of a missing value code in the loaded
file, but I was expecting that this would have been filled with the
default _FillValue when I read in the values? OK, I'm going back to the
documentation ...

Best fishes


Sam McClatchie,
Supervisory oceanographer, Fisheries oceanography
Southwest Fisheries Science Center, NOAA,
8901 La Jolla Shores Dr.
La Jolla, CA 92037-1509, U.S.A.
email <>
Office: 858 546 7083, Cellular:  858 752 8495
Research home page <>
                 //// \\\\
               /////  \\\\\\
   >><(((>   ...>><xX(>O<)Xx><<

ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
Received on Fri Aug 9 12:56:15 2013

This archive was generated by hypermail 2.1.8 : Wed Aug 14 2013 - 18:35:09 MDT