[Thread Prev][Thread Next][Index]

[ferret_users] Creating a multi-file netcdf data set



Hi there,

 

I have problem to generate descriptor file.

Since the old Perl file (gfdl.noaa.gov/~atw/ferret/make_des) which has been used to create ferret descriptor file has problem to handle the different based date of netCDF files, so I use NCL to do such job, hope it’s useful.

 

Any concern please email me. (NCL is based on version 6.3.0). However if there is better way please email me as well.

 

 

#####################################

# controlling bash file

# make_ferret_des_hxy599.sh

#####################################

 

#!/bin/bash

#PBS -P p66

#PBS -q express

#PBS -l walltime=00:05:00,ncpus=1,mem=4GB

#PBS -N eof

#PBS -l wd

#

 

user=`whoami`

owner="hxy599"

expName="b96pi1"

 

#desc_dir="/g/data1/p66/ACCESSDIR/$owner/ACCESS/output/"$expName"/history/ocn"

desc_dir="/short/p66/$owner/archive/$expName/history/ocn/"

file_type="ocean_month"

nfiles="$desc_dir/$file_type.nc*"

ofile="$expName.$file_type.des"

rm $ofile

 

##################

# Output Header

##################

yyyy=0001 ## 1850 ## 301

mm=01

dd=01

 

# Syntax //DELIMITER//. We use \/ because we need to escape the delimiter.

DICT=(${nfiles// / })

FIRST_PART=${DICT[${1}]}

 

header=1

env \

fName=${FIRST_PART} \

yName=${yyyy} \

mName=${mm} \

dName=${dd} \

desName=${ofile} \

todoNum=${header} \

ncl make_ferret_des_v1.0.0.ncl

 

##################

# Output Start, End, and Delta Time

##################

header=2

for fin in $nfiles

do

 

env \

fName=${fin} \

yName=${yyyy} \

mName=${mm} \

dName=${dd} \

desName=${ofile} \

todoNum=${header} \

ncl make_ferret_des_v1.0.0.ncl

 

done

 

##################

# Output the ending parts

##################

header=3

env \

desName=${ofile} \

todoNum=${header} \

ncl make_ferret_des_v1.0.0.ncl

 

 

 

 

#####################################

# main ncl file

# make_ferret_des_v1.0.0.ncl

#####################################

 

;; make_ferret_des - create descriptor file for ferret

;;

;; history : 16-11-2015 Created  by Arnold Sullivan

;;                                  Hailin Yan

;; E-Mail: arnold.sullivan@xxxxxxxx

;;

;;                      Remove yyyy, mm, dd

;;                      time units get from first netCDF file

;; package : make_ferret_des_vx.x.x.ncl

;; version : 1.0.1

;; how to use:

;;         use bash script to run this script

;;

;; input : iFile   : string, input netCDF file name

;;         desName : string, des file name

;;         todoNum : string, (1: heading), (2: delta time), (3: ending),

;; output: directly write into desName as text

;;

 

;; Procedures

;;

;; get_header - output the header to the descriptor file for ferret

;;

;; input : iFile   : string, input netCDF file name

;;         desName : string, des file name

;;         todoNum : string, (1: heading), (2: delta time), (3: ending),

;; output: directly write into desName as text

;;

undef ("get_header")

function get_header(  iFile:string, desName:string )

begin

 

  ofile = desName

  fName  = iFile

  fin    = addfile(fName,"r")

  ftitle = fin@title

  TIME   = fin->time

  tunits  = TIME@units

  tctype  = TIME@calendar

  new_time_units = tunits

 

header = (/"&FORMAT_RECORD", \

            "   D_TYPE             = '  MC'", \

            "   D_FORMAT           = '  1A'", \

                    "/"/)

tmhead  = (/"", \

            "&BACKGROUND_RECORD", \

            "   D_TITLE            = '"+ftitle+"'", \

            "   D_T0TIME           = '"+tunits+"'", \

            "   D_TIME_UNIT        = 86400", \

            "   D_TIME_MODULO      = .FALSE.", \

            "   D_CALTYPE          = '"+tctype+"'", \

            "/"/)

 

msghead = (/"", \

            "&MESSAGE_RECORD", \

            "   D_MESSAGE          = ' '", \

            "   D_ALERT_ON_OPEN    = .FALSE.", \

            "   D_ALERT_ON_OUTPUT  = .FALSE.", \

            "/"/)

 

exthead = (/"", \

            "&EXTRA_RECORD",\

            "/"/)

 

hlist = [/header/]

tlist = [/tmhead/]

mlist = [/msghead/]

elist = [/exthead/]

 

write_table(ofile, "w", hlist, "%s")

write_table(ofile, "a", tlist, "%s")

write_table(ofile, "a", mlist, "%s")

write_table(ofile, "a", elist, "%s")

 

return(new_time_units)

 

end

 

 

;; get_deltatime - output start, end, and delta time for each netCDF file

;;

;; input : iFile   : string, input netCDF file name

;;         yName   : integer, year num

;;         mName   : integer, month num

;;         dName   : integer, day num

;;         desName : string, des file name

;;         todoNum : string, (1: heading), (2: delta time), (3: ending),

;; output: directly write into desName as text

;;

undef ("get_deltatime")

procedure get_deltatime( iFile:string,  desName:string,new_time_units:string )

begin

 

ofile = desName

  fName  = iFile

  fin    = addfile(fName,"r")

  ftitle = fin@title

  TIME   = fin->time

  tunits  = TIME@units

  tctype  = TIME@calendar

  tsize   = dimsizes(time)

  time    = time_to_newtime(TIME, new_time_units)

 

  if tsize.lt.2 then

    tdelta = 1

  else

    tdelta  = (time(tsize-1) - time(0))/(tsize-1)

  end if

 

endhead = (/"", \

            "&STEPFILE_RECORD",\", \

            "   S_FILENAME         = '"+fName+"'", \

            "   S_AUX_SET_NUM      = 0", \

            "   S_START            = "+time(0), \

            "   S_END              = "+time(tsize-1), \

            "   S_DELTA            = "+tdelta, \

            "   S_NUM_OF_FILES     = 1", \

            "   S_REGVARFLAG       = ' '", \

             "/"/)

 

elist = [/endhead/]

 

 

write_table(ofile, "a", elist, "%s")

 

end

 

 

;; get_ending - output the ending part of the descriptor file for ferret

;;

;; input : desName : string, des file name

;; output: directly write into desName as text

;;

undef ("get_ending")

procedure get_ending( desName:string )

begin

 

ofile = desName

endhead = (/"", \

            "&STEPFILE_RECORD",\", \

            "  S_FILENAME         = '**END OF STEPFILES**'", \

            "/"/)

 

elist = [/endhead/]

 

write_table(ofile, "a", elist, "%s")

end

 

;*************************************************

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

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

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

;************************************************

begin

;************************************************

; variable and file handling

;************************************************

  fName  = getenv("fName") ;; "ocean_month.nc-00970331"

  desName= getenv("desName") ;; "list.des"

  todoNum=getenv("todoNum")

 

  if todoNum.eq.1 then

    ntUnits = get_header(fName,desName)

  else if todoNum.eq.2 then

    get_deltatime(fName,desName,ntUnits)

  else if todoNum.eq.3 then

    get_ending(desName)

  end if

  end if

  end if

 

 

 

 

end

 

 


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement