.brian & Verica:
NCL "tutorial"

Utilization of Meta Data stored in the file

It is useful to learn the content of the file, either for the debugging purposes or for utilizing meta data in the calculations in addition to the pure values of the variables.

; open the file
fi=addfile("rain-profiles.cdf","r")

  • NCL provides tools for utilizing meta data in the calculations. For instance, one can find out how many variables is stored in the file, what are their names, attributes of each variable in the file, etc.

    ; learn names of variables in the file
    varnames = getfilevarnames(fi)
    print(varnames)

    ; learn how many variables is there
    nmbvar = dimsizes(varnames)
    print(nmbvar)

    ; learn size of dimension variables in the file
    dmnsns = getfiledimsizes(fi)
    print(dmnsns)

    ; learn attributes of each variable
    do i = 0, nmbvar-1
      varatrb = getfilevaratts(fi,varnames(i))
      print(" "+varnames(i))
      print(" "+varatrb)
      delete(varatrb)
    end do

    ; learn dimensions of each variable
    do i = 0, nmbvar-1
      print(" "+varnames(i))
      vardm = getfilevardims(fi,varnames(i))
      vardms = getfilevardimsizes(fi,varnames(i))
      print(" "+vardm)
      print(" "+vardms)
      delete(vardm)
      delete(vardms)
    end do

    ; learn type of each variable
    do i = 0, nmbvar-1
      vartp = getfilevartypes(fi,varnames(i))
      print(" "+varnames(i))
      print(" "+vartp)
      delete(vartp)
    end do

  • NCL also allows for quick check on the file content that cannot be utilized in the code, but is useful for debugging.

    ; learn about the meta data for each variable

    ; either as:
    do i = 0, nmbvar-1
      printVarSummary(fi->$varnames(i)$)
    end do

    ; or as:
    do i = 0, nmbvar-1
      printFileVarSummary(fi, varnames(i))
    end do

    ; learn file attributes and meta data for each variable
    print(fi)

    ; learn just names of the file attributes
    print(getvaratts(fi))

    ; learn just names of the dimensions in the file
    print(getvardims(fi))