dataAggregation.f
********************************************************************************
* This file collects routines for data aggregation in files e.g. in NetCDF
* format for further reading in other programs or in plain text for easy
* plotting in gnuplot
5: * TODO: to be extended
********************************************************************************
SUBROUTINE netCDFCreate(p_fName, p_coodX, p_coodY,
10: c p_latVals, p_lonVals, p_varVals)
************************************************************************
* Stores normal data (as in data on a regular grid with 1-dimensional
* longitudinal and latitudinal axes) in a self-describing NetCDF file
*
15: * NetCDF INFO: http://www.unidata.ucar.edu/software/netcdf/guidef/
*
* Input:
* - p_fName (String): name of the data storage file (the NetCDF extension
* ".nc" is automatically appended!!)
20: * - p_coodX (Integer): regular grid size
* - p_coodY (Integer): regular grid size
* - p_latVals (Real[p_coodY]): latitudes (coordinates on the y axis of the grid)
* - p_latVals (Real[p_coodX]): longitudes (coordinates on the x axis of the grid)
* - p_varVals (Real[p_coodX, p_coodY]): data values on the grid
25: ************************************************************************
IMPLICIT none
INCLUDE 'netcdf.inc'
30: ! longitude in x direction, lattitude in y direction
INTEGER p_coodX, p_coodY !netscdf grid size
REAL p_latVals(p_coodY), p_lonVals(p_coodX) !netcdf arrays
REAL p_varVals(p_coodX, p_coodY) !netcdf array
35: ! net cdf definition vars
INTEGER netCdfId !file id
INTEGER latDimId, lonDimId !Dimensions
INTEGER latId, lonId, varId ! Variables
INTEGER latDims(1), lonDims(1), varDims(2) ! Variable dimensions
40:
DOUBLE PRECISION missingVal
PARAMETER(missingVal=0D0)
INTEGER strlen !funcs
45: CHARACTER p_fName*(*), fName*50 ! file name
fName = p_fName
* Routie start
CALL handleErr(nf_create(
50: c fNAme(1:strlen(fName))//".nc",
c NF_CLOBBER, netCdfId) ) ! open file
! define dimensions
CALL handleErr(
55: c NF_DEF_DIM (netCdfId, "longitude", p_coodX, lonDimId) ) ! define longitude dimension
CALL handleErr(
c NF_DEF_DIM (netCdfId, "latitude", p_coodY, latDimId) ) ! define latitude dimension
60:
! variable dimensions
latDims(1) = latDimId
lonDims(1) = lonDimId
varDims(1) = lonDimId
65: varDims(2) = latDimId
! variables
CALL handleErr(
70: c NF_DEF_VAR (netCdfId, 'longitude',NF_REAL, 1, lonDims, lonId))
CALL handleErr(
c NF_DEF_VAR (netCdfId, 'latitude', NF_REAL, 1, latDims, latId))
75: CALL handleErr(
c NF_DEF_VAR (netCdfId, 'var', NF_REAL, 2, varDims, varId))
! attributes
CALL handleErr(
80: c NF_PUT_ATT_TEXT (netCdfId, latId, 'units', 13,
c 'degrees_north') ) ! lattitude units
CALL handleErr(
c NF_PUT_ATT_TEXT (netCdfId, lonId, 'units', 12,
85: c 'degrees_east') ) ! longitude units
! variable attributes
CALL handleErr(
c NF_PUT_ATT_TEXT (netCdfId, varId, 'comment', 2,
90: c 'no') )
CALL handleErr(
c NF_PUT_ATT_TEXT (netCdfId, varId, 'long_name', 23,
c 'Surface air temperature') ) ! variable long name
95:
CALL handleErr(
c NF_PUT_ATT_TEXT (netCdfId, varId, 'units', 1,
c 'C') ) ! variable unit
100: CALL handleErr(
c NF_PUT_ATT_TEXT (netCdfId, varId, 'grid_name', 11,
c 'lonlat_grid') ) ! grid name
CALL handleErr(
105: c NF_PUT_ATT_TEXT (netCdfId, varId, 'grid_type', 6,
c 'linear') ) ! grid type
CALL handleErr(
c NF_PUT_ATT_DOUBLE (netCdfId, varId, 'missing_value', NF_DOUBLE,
110: c 1, missingVal ) ) ! level description
! global attributes
CALL handleErr(
c NF_PUT_ATT_TEXT (netCdfId, NF_GLOBAL, 'title', 31,
115: c 'auto-generated NetCDF data file') )
! end of definition
CALL handleErr (NF_ENDDEF(netCdfId))
120: ! data storage
CALL handleErr (
c NF_PUT_var_REAL (netCdfId, latId, p_latVals) )
CALL handleErr (
125: c NF_PUT_var_REAL (netCdfId, lonId, p_lonVals) )
CALL handleErr (
c NF_PUT_var_REAL (netCdfId, varId, p_varVals) )
130: CALL handleErr(NF_CLOSE (netCdfId)) ! close: save new netCDF dataset
END
135: SUBROUTINE handleErr (errId)
************************************************************************
* Handles NetCDF errors.
* TODO: extend me, more precise error info
* NetCDF INFO: http://www.unidata.ucar.edu/software/netcdf/guidef/
140: *
* Input: errId(Integer): the ID of the error
************************************************************************
INCLUDE 'netcdf.inc'
145: INTEGER errId
IF (errId .NE. NF_NOERR) THEN
PRINT *, NF_STRERROR(errId)
STOP 'NetCDF file creation'
150: ENDIF
END
Info Section
Warning: externals (function calls) may not be acurate
includes: netcdf.inc
calls: handleerr
back to top
f2html v0.3 (C) 1997,98 Beroud Jean-Marc. Fri Aug 11 17:54:58 CEST 2006