Re: Header lines in ascii input files

From: Mary Haley (haley AT XXXXXX)
Date: Wed Feb 19 2003 - 11:34:56 MST

  • Next message: Dennis Shea: "Re: Header lines in ascii input files"

    >
    > I have an ascii input file that may have a single header
    > line at the beginning that I would like to discard before
    > reading the rest of the file into a single variable.
    > I suspect this falls under "Currently, support for binary
    > or ASCII files containing more than one array is not
    > officially supported" as found in the online NCL data
    > types overview -- but I thought I should check to be sure.
    > I have a means to get around this (by creating a copy of
    > the file without the header) but it would be much nicer
    > to deal with it in NCL somehow.
    >
    > thanks,
    > dave reusch
    >

    Hi Dave,

    You are correct; if your header contains numbers, then there's no way
    to pick off this header and read the rest of the file with one NCL
    command.

    However, if your header doesn't contain any numbers, and the rest of
    the file contains numbers that you want to read into a numeric type
    variable, then you can read this file with one "asciiread" command,
    because it will safely ignore this first line.

    For example, if you have the following 8 line file called "file.txt":

    This is a header line that contains no numbers
       4.35 4.39 0.27 -3.35 -6.90
       4.36 4.66 3.77 -1.66 4.06
       9.73 -5.84 0.89 8.46 10.39
       4.91 4.59 -3.09 7.55 4.56
       1.77 3.68 5.08 0.14 -5.63
      -0.63 -14.12 -2.51 1.76 -1.43
      -4.29 0.07 5.85 0.87 8.65

    You can read in the numbers with the command:

       x = asciiread("file.txt",(/7,5/),"float")

    If the first line contains numbers, then you will need to do what you
    hinted at above, and that is create a copy of the file without the
    header (which you can do from NCL). Or, you can write a C/Fortran
    subroutine that reads the file (header and all), and then use "WRAPIT"
    to create a shared object to allow you to call it from NCL.

    --Mary
    _______________________________________________
    ncl-talk mailing list
    ncl-talk AT ucar.edu
    http://mailman.ucar.edu/mailman/listinfo/ncl-talk



    This archive was generated by hypermail 2b29 : Wed Feb 19 2003 - 11:49:30 MST