load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" begin OS = systemfunc("uname") ; diri = "./" diri = "/home/skirby/TEMP/" fili = "ruc2.t00z.bgrbf12" ; input GRIB file diro = "./" filo = fili+".nc" fgrb = addfile(diri+fili+".grb", "r") print("fgrb name") print(fgrb) ;exit grib_nc = diro+filo system ("/bin/rm -f " + grib_nc ) ; remove any pre-existing file fnc = addfile(grib_nc ,"c") ; create the netCDF file ;*********************************************** ; assign file attributes ;*********************************************** fAtt = True fAtt@title = "GRIB-to-netCDF: processed by skirby" fAtt@source_file = fili ; fils(nf) fAtt@Conventions = "None" fAtt@System = OS fAtt@creation_date = systemfunc ("date") fileattdef( fnc, fAtt ) ;*********************************************** ; assign file attributes ;*********************************************** names = getfilevarnames(fgrb) ; extract all the variable names from fgrb ; loop through all the variables print("names:" + names) ;print(names) print("dimsizes(names):" + dimsizes(names)) ;print(dimsizes(names)) do i=0,dimsizes(names)-1 print("writing fnc variable: " + names(i)) x = fgrb->$names(i)$ dimx = dimsizes(x) ; dimsizes print("dimx:" + dimx) rank = dimsizes(dimx) ; number of dimensions print("rank:" + rank) ; rename coordinates if (rank.eq.1 .and. dimx(0).eq.50) then x!0 = "z" end if if (rank.eq.1 .and. dimx(0).eq.5) then x!0 = "z5" end if if (rank.eq.1 .and. dimx(0).eq.2) then x!0 = "z2" end if if (rank.eq.2 ) then x!0 = "x" x!1 = "y" end if if (rank.eq.3 .and. dimx(0).eq.50) then x!0 = "z" x!1 = "x" x!2 = "y" end if if (rank.eq.3 .and. dimx(0).eq.5 ) then x!0 = "z5" x!1 = "x" x!2 = "y" end if if (rank.eq.3 .and. dimx(0).eq.2 ) then x!0 = "z2" x!1 = "x" x!2 = "y" end if fnc->$names(i)$ = x delete(x) ; size change on the next iteration delete(dimx) end do La1 = fgrb->gridlon_236@La1 ; retrieve attribute La1@long_name = "first latitude" La1@units = "degrees_north" La1!0 = "nav" Lo1 = fgrb->gridlon_236@Lo1 Lo1@long_name = "first longitude" Lo1@units = "degrees_east" Lo1!0 = "nav" Lov = fgrb->gridlon_236@Lov Lov@long_name = "orientation of grid" Lov@units = "degrees_east" Lov!0 = "nav" Latin = fgrb->gridlon_236@Latin1 Latin@long_name = "conic tangent latitude" Latin@units = "degrees_north" Latin!0 = "nav" fnc->La1 = La1 fnc->Lo1 = Lo1 fnc->Lov = Lov fnc->Latin = Latin ;print("writing nc file") print (fnc) end