Skip to content

jswhit2/NCEPLIBS-ncio

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NCEPLIBS-ncio Library

module for reading/writing FV3 netcdf lat/lon data.

==============Add cmake for comipling================= 10/25/2019 Hang Lei NOAA/EMC

The Cmake is tested on NOAA WCOSS and Hera need to set up compiler options and library path for sepcific machine.

e.g. on Hera: cmake -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc -DCMAKE_Fortran_COMPILER=ifort -DMPI_LIBRARIES=/apps/intel/compilers_and_libraries_2018/linux/mpi/intel64/lib -DMPI_INCLUDES=/apps/intel/compilers_and_libraries_2018/linux/mpi/intel64/include -DNETCDF_LIBRARY=/apps/netcdf/4.6.1/intel/16.1.150/lib -DNETCDF_INCLUDE=/apps/netcdf/4.6.1/intel/16.1.150/include .

cmake --build .

==============Initial Development of NCIO LIB=========== 10/18/2019 Dr. Jeff Whitaker NOAA/ESRL

NCEPLIBS-ncio

module for reading/writing FV3 netcdf lat/lon data.

  • open a Dataset.
use module_fv3gfs_ncio
type(Dataset) :: ds
ds = open_dataset('gfs.t00z.atmf240.nc')
  • read an attribute.
real(4), allocatable, dimension(:) :: ak,bk
character(len=32) charatt
! ak,bk are allocated and filled.
call read_attribute(ds, 'ak', ak)
call read_attribute(ds, 'bk', bk)
! read character variable attribute
call read_attribute(ds, 'long_name', charatt, 'vgrd')
  • read a variable.
real(4), allocatable, dimension(:) :: lats,lons
real(4), allocatable, dimension(:,:,:) :: psfc
! arrays must be of correct rank (but not necessarily
! the same type). They are allocated and filled.
! The entire variable is read at once.
call read_vardata(ds,'latitudes',lats)
call read_vardata(ds,'latitudes',lons)
call read_vardata(ds,'pressfc',psfc)
  • create a new dataset from a template dataset.
type(Dataset) :: dso
! copy_vardata is optional, default .false. means just copy
! variables, dimensions and attributes and coordinate variable 
! data (don't copy all variable data).
dso = create_dataset('gfs.t00z.atmf240_copy.nc', ds, copy_vardata=.true.)
  • write a variable.
real(8), allocatable, dimension(:) :: times
call read_vardata(dso, 'time', times)
! times is now allocated and filled with values from template dataset.
! now overwrite with new values and write back.
times = times + 6 ! add six hours.
call write_vardata(dso, 'time', times)
  • quantize variable data before writing for better compression.
! Lossy compression controlled by parameter nbits (1-31).
! The floating point data is quantized to improve compression
! See doi:10.5194/gmd-10-413-2017.  The method employed
! here is identical to the 'scaled linear packing' method in
! that paper, except that the data are scaling into an arbitrary
! range (2**nbits-1 not just 2**16-1) and are stored as re-scaled floats
! instead of short integers. The zlib algorithm does almost as
! well packing the rescaled floats as it does the scaled
! integers, and this avoids the need for the client to apply the
! rescaling (plus it allows the ability to adjust the packing range).
data_save = data
nbits = 14
call quantize_data(data_save, data, nbits, compress_err)
! compress_err is the max abs compression error (can be saved
! as a variable attribute.
  • write an attribute.
charatt = 'hours since 2016-01-04 06:00:00'
call write_attribute(dso, 'units', charatt, 'time')
  • access Variable and Dimension derived data types.
type(Variable) :: var
type(Dimension) :: dim
! see module_fv3gfs_ncio.f90 for type definitions.
! type members can be used to the call netcdf-fortran90 interface
! directly.
var = get_var(ds, 'ugrd')
dim = get_dim(ds, 'time')
  • close a dataset.
call close_dataset(ds)
call close_dataset(dso)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Fortran 95.9%
  • CMake 4.1%