Select Git revision
main.f90 6.62 KiB
! This is part of the netCDF package.
! Copyright 2006 University Corporation for Atmospheric Research/Unidata.
! See COPYRIGHT file for conditions of use.
! This is an example program which writes some 4D pressure and
! temperatures. It is intended to illustrate the use of the netCDF
! fortran 90 API. The companion program pres_temp_4D_rd.f shows how
! to read the netCDF data file created by this program.
! This program is part of the netCDF tutorial:
! http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-tutorial
! Full documentation of the netCDF Fortran 90 API can be found at:
! http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-f90
! $Id: pres_temp_4D_wr.f90,v 1.7 2007/01/24 19:32:10 russ Exp $
program pres_temp_4D_wr
use netcdf
implicit none
! This is the name of the data file we will create.
character (len = *), parameter :: FILE_NAME = "pres_temp_4D.nc"
integer :: ncid
! We are writing 4D data, a 2 x 6 x 12 lvl-lat-lon grid, with 2
! timesteps of data.
integer, parameter :: NDIMS = 4, NRECS = 2
integer, parameter :: NLVLS = 2, NLATS = 6, NLONS = 12
character (len = *), parameter :: LVL_NAME = "level"
character (len = *), parameter :: LAT_NAME = "latitude"
character (len = *), parameter :: LON_NAME = "longitude"
character (len = *), parameter :: REC_NAME = "time"
integer :: lvl_dimid, lon_dimid, lat_dimid, rec_dimid
! The start and count arrays will tell the netCDF library where to
! write our data.
integer :: start(NDIMS), count(NDIMS)
! These program variables hold the latitudes and longitudes.
real :: lats(NLATS), lons(NLONS)
integer :: lon_varid, lat_varid
! We will create two netCDF variables, one each for temperature and
! pressure fields.
character (len = *), parameter :: PRES_NAME="pressure"
character (len = *), parameter :: TEMP_NAME="temperature"
integer :: pres_varid, temp_varid
integer :: dimids(NDIMS)
! We recommend that each variable carry a "units" attribute.
character (len = *), parameter :: UNITS = "units"
character (len = *), parameter :: PRES_UNITS = "hPa"
character (len = *), parameter :: TEMP_UNITS = "celsius"
character (len = *), parameter :: LAT_UNITS = "degrees_north"
character (len = *), parameter :: LON_UNITS = "degrees_east"
! Program variables to hold the data we will write out. We will only
! need enough space to hold one timestep of data; one record.
real :: pres_out(NLONS, NLATS, NLVLS)
real :: temp_out(NLONS, NLATS, NLVLS)
real, parameter :: SAMPLE_PRESSURE = 900.0
real, parameter :: SAMPLE_TEMP = 9.0
! Use these to construct some latitude and longitude data for this
! example.
real, parameter :: START_LAT = 25.0, START_LON = -125.0
! Loop indices
integer :: lvl, lat, lon, rec, i