[ncl-talk] Regarding text file reading

Dennis Shea shea at ucar.edu
Fri Sep 4 07:59:27 MDT 2015


; read string function documentation
; http://www.ncl.ucar.edu/Document/Functions/string.shtml

  s = asciiread("test_file",-1,"string")
  print(s)   ; whole file

  delim  = " "

  nflda  = str_fields_count(s(0), delim)   ; number of fields in 1st line
  nfldb  = str_fields_count(s(1), delim)   ; number of fields in 2nd line
  print("")
  print("nflda="+nflda +"  nfldb="+nfldb)

; The following are variables of type string

  vals0  = str_get_field(s(0), 8, delim)            ; 8th field
  vals1i = str_get_field(s(1), nfldb   , delim)    ; last value
  vals1f = str_get_field(s(1), nfldb-1, delim)    ; 2nd last value

; 'direct' to numeric types

  VALS0  = toint(   str_get_field(s(0), 8, delim) )              ; 8th field
  VALS1I = toint(   str_get_field(s(1), nfldb  , delim) )       ; last
value
  VALS1F = tofloat( str_get_field(s(1), nfldb-1, delim) )    ; 2nd
last value

  print(VALS0)
  print(VALS1I)
  print(VALS1F)

On Thu, Sep 3, 2015 at 7:56 PM, Umakanth U <umaraj502 at gmail.com> wrote:
> Dear NCL users,
>
> By using using asciiread in string format I am able to read TRMM 3G68 text
> file. But the file has different number of fields in each row.
> For example:
> 3 48 175 428 55 0 0 0 0
> 3 48 175 429 55 3 0.0424 9 68 9 0.1130 5 68 9 0.1805 100
> I wish to read 8th field from first line and last field from second line.
> Any suggestion will be helpful.
>
> --
> Umakanth U
> Research Fellow
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>


More information about the ncl-talk mailing list