[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 950607: Suggested change to Fortran test routines in netCDF-232



>From: Mike Berkley <address@hidden>
>Keywords: 199506072102.AA06669 netCDF Fortran interface

Hi Mike,

> We are in the process of adding netCDF support to our internal
> software, but have had some problems with the Fortran interface when
> using Fortran auto-double features.
> 
> The confusion arises over the definition of REAL.  With some
> compilers, REAL is sometimes 32 bits and sometimes 64 bits, depending
> upon compiler options.  We would like to suggest a few changes to
> netCDF which would lessen some of the confusion.
> 
> Note that except for ncgen, these changes relate to the Fortran tests,
> not to the netCDF libraries.
> 
> 
> 
> 1. Add a SINGLE_PRECISION definition to the m4 files.
>     - instead of expecting C floats be equivalent to REAL, use an m4
>       declaration, as with the existing DOUBLE_PRECISION declaration
> - ----------------------------------------------------------------------
>     $ diff netcdf-new/fortran/common.m4 netcdf-232pl4/fortran/common.m4
>     55,60d54
>     < 
>     < # FORTRAN declaration for single precision (e.g. real*4 for a Cray)
>     < define(`SINGLE_PRECISION',`real*4')
>     < 
>     < # FORTRAN declaration for double precision (e.g. real*8 for a Cray)
>     < define(`DOUBLE_PRECISION',`real*8')
> - ----------------------------------------------------------------------
>     $ diff netcdf-new/fortran/IRIX.m4 netcdf-232pl4/fortran/irix.m4
>     27c27
>     < define(`LONG_INT',`integer*4')
>     ---
>     > define(`LONG_INT',`integer')
>     35,36c35,36
>     < # FORTRAN declaration for single precision (e.g. real*4 for a Cray)
>     < define(`SINGLE_PRECISION',`real*4')
>     ---
>     > # FORTRAN declaration for double precision (e.g. real for a Cray)
>     > define(`DOUBLE_PRECISION',`double precision')
>     38,40d37
>     < # FORTRAN declaration for double precision (e.g. real*8 for a Cray)
>     < define(`DOUBLE_PRECISION',`real*8')
> - ----------------------------------------------------------------------
> 
> 
> 
> 2. Modify ftest.src accordingly:
> - ----------------------------------------------------------------------
>     $ diff -r netcdf-new/fortran/ftest.src netcdf-232pl4/fortran/ftest.src
>     131c131
>     <       SINGLE_PRECISION flval(2)
>     ---
>     >       real flval(2)
>     336c336
>     <       SINGLE_PRECISION flval(2)
>     ---
>     >       real flval(2)
>     883c883
>     <       SINGLE_PRECISION farray(levels, lats, lons, times)
>     ---
>     >       real farray(levels, lats, lons, times)
>     1009c1009
>     <       SINGLE_PRECISION fvalue
>     ---
>     >       real fvalue
>     1013d1012
>     <       SINGLE_PRECISION fpi
>     1019d1017
>     <       data fpi/3.14159/
>     1045,1046c1043,1044
>     <       if (abs(fvalue - fpi) .gt. epsilon) write(*,*) 'error in ncvgt
>     <      +1 float:', fvalue, ' not close to', fpi
>     ---
>     >       if (abs(fvalue - 3.14159) .gt. epsilon) write(*,*) 'error in ncvgt
>     >      +1 float:', fvalue, ' not close to', 3.14159
>     1099c1097
>     <       SINGLE_PRECISION farray(levels, lats, lons, times)
>     ---
>     >       real farray(levels, lats, lons, times)
>     1184d1181
>     <       SINGLE_PRECISION fpi
>     1192d1188
>     <       data fpi/3.14159/
>     1213c1209
>     <       call ncvpt1 (ncid, fid, findx, fpi, iret)
>     ---
>     >       call ncvpt1 (ncid, fid, findx, 3.14159, iret)
> - ----------------------------------------------------------------------
> 
> 
> 
> 3. Modify ncgen to produce more explicitly typed REAL variables,
>    i.e. REAL*4 for floats and REAL*8 for double precision.

Thanks very much for the suggestion and the supplied fixes.  We'll
incorporate your changes into the netCDF 2.4 release.

______________________________________________________________________________

Russ Rew                                           UCAR Unidata Program
address@hidden                              http://www.unidata.ucar.edu