source: trunk/LMDZ.MARS/libf/phymars/def_var.F90 @ 1619

Last change on this file since 1619 was 38, checked in by emillour, 14 years ago

Ajout du modè Martien (mon LMDZ.MARS.BETA, du 28/01/2011) dans le rértoire mars, pour pouvoir suivre plus facilement les modifs.
EM

File size: 2.1 KB
Line 
1subroutine def_var(nid,name,title,units,nbdim,dimids,nvarid,ierr)
2
3! This subroutine defines variable 'name' in a (pre-existing and opened)
4! NetCDF file (known from its NetCDF ID 'nid').
5! The number of dimensions 'nbdim' of the variable, as well as the IDs of
6! corresponding dimensions must be set (in array 'dimids').
7! Upon successfull definition of the variable, 'nvarid' contains the
8! NetCDF ID of the variable.
9! The variables' attributes 'title' (Note that 'long_name' would be more
10! appropriate) and 'units' are also set.
11! Modifs: Aug2010 Ehouarn: enforce outputs to be real*4
12
13implicit none
14
15#include "netcdf.inc"
16
17integer,intent(in) :: nid ! NetCDF file ID
18character(len=*),intent(in) :: name ! the variable's name
19character(len=*),intent(in) :: title ! 'title' attribute of variable
20character(len=*),intent(in) :: units ! 'units' attribute of variable
21integer,intent(in) :: nbdim ! number of dimensions of the variable
22integer,dimension(nbdim),intent(in) :: dimids ! NetCDF IDs of the dimensions
23                                              ! the variable is defined along
24integer,intent(out) :: nvarid ! NetCDF ID of the variable
25integer,intent(out) :: ierr ! returned NetCDF staus code
26
27! 1. Switch to NetCDF define mode
28ierr=NF_REDEF(nid)
29
30! 2. Define the variable
31!#ifdef NC_DOUBLE
32!ierr = NF_DEF_VAR (nid,adjustl(name),NF_DOUBLE,nbdim,dimids,nvarid)
33!#else
34ierr = NF_DEF_VAR (nid,adjustl(name),NF_FLOAT,nbdim,dimids,nvarid)
35!#endif
36if(ierr/=NF_NOERR) then
37   write(*,*) "def_var: Failed defining variable "//trim(name)
38   write(*,*) NF_STRERROR(ierr)
39   stop ""
40endif
41
42! 3. Write attributes
43ierr=NF_PUT_ATT_TEXT(nid,nvarid,"title",&
44                     len_trim(adjustl(title)),adjustl(title))
45if(ierr/=NF_NOERR) then
46   write(*,*) "def_var: Failed writing title attribute for "//trim(name)
47   write(*,*) NF_STRERROR(ierr)
48   stop ""
49endif
50
51ierr=NF_PUT_ATT_TEXT(nid,nvarid,"units",&
52                     len_trim(adjustl(units)),adjustl(units))
53if(ierr/=NF_NOERR) then
54   write(*,*) "def_var: Failed writing units attribute for "//trim(name)
55   write(*,*) NF_STRERROR(ierr)
56   stop ""
57endif
58
59! 4. Switch out of NetCDF define mode
60ierr = NF_ENDDEF(nid)
61
62end
Note: See TracBrowser for help on using the repository browser.