[netcdfgroup] nf90_def_var - Error

 
Dear all, 
  
After installation of netcdf4 in Ubuntu I am trying to use the netcdf library 
through fortran. I am facing problem in running the code. Here is sample code: 
  
 
 
  
  
 
 
 
program test
use netcdf
implicit none
character(len=10) :: vname 
integer :: ncid, dimid, varid, sta 
vname='lon' 
sta = nf90_create("test.nc", nf90_clobber, ncid)
print *, trim(nf90_strerror(sta)) 
sta = nf90_def_dim(ncid, "lon_dim", 360, dimid)
print *, trim(nf90_strerror(sta)) 
sta = nf90_def_var(ncid, trim(vname) , nf90_float, (/dimid/), varid)
print *, trim(nf90_strerror(sta)) 
sta = nf90_close(ncid) 
end program
~                      
  
This prompts me: 
No error
 No error
 NetCDF: Name contains illegal characters 
  
The nf90_def_var does not works! I also tried to keep 'lon' in place of 
trim(vname). The problem is same. But, creates test.nc! 
  
$ ncdump test.nc 
netcdf test {
dimensions:
    lon_dim = 360 ;
} 
  
Someone please help to overcome this problem. 
  
With thanks and Regards, 
Mahakur