[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netCDF #ITH-188331]: netcdf data append in f90
- Subject: [netCDF #ITH-188331]: netcdf data append in f90
- Date: Wed, 30 Sep 2009 09:27:00 -0600
Rama,
> I have another issue. When I define a variable in F90 using
> NF90_CHAR, and write it into a netCDF file, the result is truncated.
>
> For example if I want to write a variable "NSS", only "N"
> appears in the result.
>
> Inside my FORTRANT I read from a binary file the above variable.
> In the binary file, the variable is a 3 word character.
> The start Octet for this variable is 1.
>
> CHARACTER(1), DIMENSION(3) :: variable_binary
>
> EQUIVALENCE(data, variable_binary(1))
>
> Then when I print this out in F90 code, it is alright and print as
> "NSS". But when I write it into NetCDF file using NF90_CHAR,
> it appears as "N" in the NetCDF file.
>
> Any idea why is it so ?
Yes, maybe the appended F90 program will make it clearer. When I
compile and run this program, it creates a file named "chartst.nc",
and ncdump shows it has the following data:
$ ncdump chartst.nc
netcdf chartst {
dimensions:
Dim1 = 15 ;
variables:
char Var1(Dim1) ;
char Var2(Dim1) ;
char Var3(Dim1) ;
data:
Var1 = "a" ;
Var2 = "abcde" ;
Var3 = "abcdefghijklmno" ;
}
I hope this clarifies what is going on ...
--Russ
program chartst
use netcdf
integer :: ncid, var1id, var2id, var3id, dim1id
character (len = 1), dimension (15) :: ch = (/"a", "b", "c", "d", "e", &
"f", "g", "h", "i", "j", &
"k", "l", "m", "n", "o" /)
character (len = 5), dimension(3) :: ch5 = (/"abcde","fghij","klmno" /)
character (len = 15) :: ch15 = "abcdefghijklmno"
call check(nf90_create('chartst.nc', nf90_clobber, ncid))
call check(nf90_def_dim(ncid, 'Dim1', 15, dim1id))
call check(nf90_def_var(ncid, 'Var1', nf90_char, (/dim1id/), var1id))
call check(nf90_def_var(ncid, 'Var2', nf90_char, (/dim1id/), var2id))
call check(nf90_def_var(ncid, 'Var3', nf90_char, (/dim1id/), var3id))
call check(nf90_enddef(ncid))
call check(nf90_put_var(ncid, var1id, ch))
call check(nf90_put_var(ncid, var2id, ch5))
call check(nf90_put_var(ncid, var3id, ch15))
call check(nf90_close(ncid))
contains
subroutine check(status)
integer, intent ( in) :: status
if(status /= nf90_noerr) then
print *, trim(nf90_strerror(status))
stop 2
end if
end subroutine check
end program chartst
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu
Ticket Details
===================
Ticket ID: ITH-188331
Department: Support netCDF
Priority: Normal
Status: Closed