[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Characters arrays with f90



>To: address@hidden
>From: Francois Vandenberghe <address@hidden>
>Subject: Characters arrays with f90
>Organization: UCAR/Unidata
>Keywords: 200210091704.g99H48109566


Hi,

> I have a problem understanding the way NETCDF f90 interface can load
> an array of characters. I tried to follow page 66 (7.7 Reading and writing
> character string values) of the documentation vserion 3 (February 200)
> but it doesn't work as I would like.
> 
> The problem is the following: I have a station names arrays "Staname"
> which contains "recNum" names (22 in that case) of "stanamLen" characters
> (6 in that case).
> 
> After reading both dimension recNum and stanamLen, I have the following
> statements:
> 
> CHARACTER, DIMENSION (:,:), ALLOCATABLE :: staName
> 
> ALLOCATE (staName (recNum,StanamLen))
> 
> iret = NF90_GET_VAR (nc_id, var_id (n), staName , map = (/ stanamLen, 1 /))
> 
> The output however gives:
> 
> 10:31:06 staName (  1) = C
> 10:31:06 staName (  2) = F
> 10:31:06 staName (  3) = L
> 10:31:06 staName (  4) = M
> 10:31:06 staName (  5) = O
> 10:31:06 staName (  6) = P
> 10:31:06 staName (  7) = R
> 10:31:06 staName (  8) = S
> 10:31:06 staName (  9) = C
> 10:31:06 staName ( 10) = G
> 10:31:06 staName ( 11) = G
> 10:31:06 staName ( 12) = L
> 10:31:06 staName ( 13) = L
> 10:31:06 staName ( 14) = N
> 10:31:06 staName ( 15) = O
> 10:31:06 staName ( 16) = P
> 10:31:06 staName ( 17) = P
> 10:31:06 staName ( 18) = S
> 10:31:06 staName ( 19) = W
> 10:31:06 staName ( 20) = S
> 10:31:06 staName ( 21) = V
> 10:31:06 staName ( 22) = A
> 
> while I am trying to read (from ncdump):
> 
>  staName =
>   "CCDNH ",
>   "FMEMD ",
>   "LAXCA ",
>   "MCGQU ",
>   "ONTCA ",
>   "PLTCO ",
>   "RUTNJ ",
>   "STWMA ",
>   "CCOCA ",
>   "GLACA ",
>   "GVYCA ",
>   "LHSCA ",
>   "LVRCA ",
>   "NPTOR ",
>   "OREMA ",
>   "PSPNY ",
>   "PYMMA ",
>   "SCHNY ",
>   "WFDCA ",
>   "SACCA ",
>   "VISCA ",
> 
> Any ideas what I am not doing correctly?

I'm not a Fortran90 expert, but I think you have reversed the
dimension orders in the ALLOCATE statement, which I would write:

 ALLOCATE (staName (StanamLen,recNum))

because the StanamLen dimension is the most rapidly varying, so it
should appear first.  The output of ncdump uses the opposite dimension
order from Fortran, so that may the cause of the confusion.

--Russ

_____________________________________________________________________

Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu