source: trunk/MESOSCALE/LMDZ.MARS/libf_gcm/phymars/def_var.F90 @ 1242

Last change on this file since 1242 was 57, checked in by aslmd, 14 years ago

mineur LMD_MM_MARS: ajout du GCM ancienne physique, systeme maintenant complet sur SVN (ne manque que la base de donnees d'etats initiaux)

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
12implicit none
13
14#include "netcdf.inc"
15
16integer,intent(in) :: nid ! NetCDF file ID
17character(len=*),intent(in) :: name ! the variable's name
18character(len=*),intent(in) :: title ! 'title' attribute of variable
19character(len=*),intent(in) :: units ! 'units' attribute of variable
20integer,intent(in) :: nbdim ! number of dimensions of the variable
21integer,dimension(nbdim),intent(in) :: dimids ! NetCDF IDs of the dimensions
22                                              ! the variable is defined along
23integer,intent(out) :: nvarid ! NetCDF ID of the variable
24integer,intent(out) :: ierr ! returned NetCDF staus code
25
26! 1. Switch to NetCDF define mode
27ierr=NF_REDEF(nid)
28
29! 2. Define the variable
30#ifdef NC_DOUBLE
31ierr = NF_DEF_VAR (nid,adjustl(name),NF_DOUBLE,nbdim,dimids,nvarid)
32#else
33ierr = NF_DEF_VAR (nid,adjustl(name),NF_FLOAT,nbdim,dimids,nvarid)
34#endif
35if(ierr/=NF_NOERR) then
36   write(*,*) "def_var: Failed defining variable "//trim(name)
37   write(*,*) NF_STRERROR(ierr)
38   stop ""
39endif
40
41! 3. Write attributes
42ierr=NF_PUT_ATT_TEXT(nid,nvarid,"title",&
43                     len_trim(adjustl(title)),adjustl(title))
44if(ierr/=NF_NOERR) then
45   write(*,*) "def_var: Failed writing title attribute for "//trim(name)
46   write(*,*) NF_STRERROR(ierr)
47   stop ""
48endif
49
50ierr=NF_PUT_ATT_TEXT(nid,nvarid,"units",&
51                     len_trim(adjustl(units)),adjustl(units))
52if(ierr/=NF_NOERR) then
53   write(*,*) "def_var: Failed writing units attribute for "//trim(name)
54   write(*,*) NF_STRERROR(ierr)
55   stop ""
56endif
57
58! 4. Switch out of NetCDF define mode
59ierr = NF_ENDDEF(nid)
60
61end
Note: See TracBrowser for help on using the repository browser.