[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netCDF #AOX-617597]: 2D character string array (Fortran 90)
- Subject: [netCDF #AOX-617597]: 2D character string array (Fortran 90)
- Date: Wed, 20 May 2009 09:04:32 -0600
Ruslan,
> Just one more question. If you want to have Dim2 as unlimited dimension,
> the same approuch doesn't work because unlimited dimension should go first
> in CDL file.
> What can I do in this case?
A corresponding CDL file is:
netcdf test {
dimensions:
Dim1 = 3 ;
Dim2 = UNLIMITED ; // (2 currently)
Dim3 = 20 ;
variables:
char Var1(Dim2, Dim1, Dim3) ;
data:
Var1 =
"string A, length 20.",
"string B, length 20.",
"string C, length 20.",
"string D, length 20.",
"string E, length 20.",
"Here is F string 35 " ;
}
A Fortran-77 program that writes the corresponding netCDF file
is not much different from the previous one and is attached.
--Russ
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu
Ticket Details
===================
Ticket ID: AOX-617597
Department: Support netCDF
Priority: Normal
Status: Closed
program chartst
include 'netcdf.inc'
integer ncid, var1id, dim1id, dim2id, dim3id
integer ndims
parameter(NDIMS = 3)
parameter(LEN1 = 3, LEN2 = 2, LEN3 = 20)
integer dimids(NDIMS), start(NDIMS), count(NDIMS)
integer stride(NDIMS), amap(NDIMS)
integer status
character*35 :: array(LEN1,LEN2)
data array /
* "string A, length 20.",
* "string B, length 20.",
* "string C, length 20.",
* "string D, length 20.",
* "string E, length 20.",
* "Here is F string 35 characters long"
* /
status = nf_create('test.nc', nf_clobber, ncid)
if(status .ne. nf_noerr) then
print *, nf_strerror(status)
stop 1
endif
status = nf_def_dim(ncid, 'Dim1', LEN1, dim1id)
if(status .ne. nf_noerr) then
print *, nf_strerror(status)
stop 1
endif
status = nf_def_dim(ncid, 'Dim2', NF_UNLIMITED, dim2id)
if(status .ne. nf_noerr) then
print *, nf_strerror(status)
stop 1
endif
status = nf_def_dim(ncid, 'Dim3', LEN3, dim3id)
if(status .ne. nf_noerr) then
print *, nf_strerror(status)
stop 1
endif
dimids(1) = dim3id
dimids(2) = dim1id
dimids(3) = dim2id
status = nf_def_var(ncid, 'Var1', nf_char, NDIMS, dimids, var1id)
if(status .ne. nf_noerr) then
print *, nf_strerror(status)
stop 1
endif
status = nf_enddef(ncid)
if(status .ne. nf_noerr) then
print *, nf_strerror(status)
stop 1
endif
start(1) = 1
start(2) = 1
start(3) = 1
count(1) = LEN3
count(2) = LEN1
count(3) = LEN2
stride(1) = 1
stride(2) = 1
stride(3) = 1
amap(1) = 1
amap(2) = 35
amap(3) = 35*LEN1
c status = nf_put_vara_text(ncid, var1id, start, count, array)
c if(status .ne. nf_noerr) then
c print *, nf_strerror(status)
c stop 1
c endif
status = nf_put_varm_text(ncid, var1id, start, count,
* stride, amap, array)
if(status .ne. nf_noerr) then
print *, nf_strerror(status)
stop 1
endif
status = nf_close(ncid)
if(status .ne. nf_noerr) then
print *, nf_strerror(status)
stop 1
endif
end