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

Colleagues

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:
194903,17958.00,17965.00,49.00,114.00,-128.95,37.73,10.00,11.69,32.86,24.98,0.02,,,,,

194903,17958.00,17965.00,50.00,95.00,127.46,38.17,10.00,10.20,32.69,25.11,0.02,,,,,

194903,17958.00,17965.00,50.00,104.00,128.11,37.87,10.00,10.51,32.74,25.10,0.02,,,,,

194903,17958.00,17965.00,51.00,85.00,-126.50,38.30,10.00,10.05,32.66,25.11,0.02,,,,,

194903,17958.00,17965.00,52.00,75.00,125.72,38.50,10.00,9.89,32.94,25.36,0.02,,,,,

and from the tail of the file:
201304,41370.00,41394.00,93.30,80.00,120.91,31.18,10.00,14.32,33.29,24.80,0.03,5.99,102.80,0.31,0,0.15

201304,41370.00,41394.00,93.30,90.00,121.59,30.84,10.00,14.80,33.36,24.75,0.03,5.88,101.90,0.28,0,0.13

201304,41370.00,41394.00,93.30,100.00,122.25,30.51,10.00,16.15,33.52,24.57,0.03,5.66,100.90,0.28,0.1,0.08

201304,41370.00,41394.00,93.30,110.00,122.92,30.18,10.00,15.64,33.41,24.61,0.03,5.79,102.10,0.29,0,0.08

201304,41370.00,41394.00,93.40,26.40,-117.28,32.95,10.00,13.67,33.57,25.15,0.03,5.38,91.20,0.81,7.5,2.07

Here is the code which incorporates code from various examples:

;*********************************
;; CalCOFI_10m_properties.ncl
;*********************************

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

begin

;---Read the values in as 1D, since we don't know rows and columns yet.
   filename =
"../../CalCOFI/data/calcofi_hydro/Rpt_10m_Properties_Cruises_no_header.txt"
   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.")
   print(dimsizes(values_2d))

;---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
format
   print("new missing value code: "+values_2d@_FillValue)

;---Pretty print matrix to ascii file
;quit
   opt=True
   opt@fout="../data/calcofi/test.txt"
   print("Fortran format "+ncols+"f7.2")
   write_matrix(values_2d, ncols+"f7.2", opt)

end
;------------------------------

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

smc@caiman:~/Dropbox/dynamic_data/projects2013/new_sardine_index/ncl$
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 http://www.ncl.ucar.edu/ for more details.

(0)
'../../CalCOFI/data/calcofi_hydro/Rpt_10m_Properties_Cruises_no_header.txt'
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

-- 
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 <Sam.McClatchie@noaa.gov>
Office: 858 546 7083, Cellular:  858 752 8495
Research home page <www.fishocean.info>
                    /\
       ...>><xX(¡>
                 //// \\\\
                    <¡)Xx><<
               /////  \\\\\\
                         ><(((¡>
   >><(((¡>   ...>><xX(¡>O<¡)Xx><<

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
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