[netcdfgroup] problem reading array of strings in F90/C

  • To: netcdfgroup@xxxxxxxxxxxxxxxx
  • Subject: [netcdfgroup] problem reading array of strings in F90/C
  • From: M P <mzp3769@xxxxxxxxx>
  • Date: Thu, 20 Oct 2022 11:16:03 -0600
  • Arc-authentication-results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ed5V36le; spf=pass (google.com: domain of mzp3769@xxxxxxxxx designates 209.85.220.41 as permitted sender) smtp.mailfrom=mzp3769@xxxxxxxxx; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=UQzzBZDB4LYunr6f86Q/IDYHtT0c76m2AguZK2IPnU8=; b=0EaKSAh03GQm643NBZZ4QtZZQYnShMzAT+Y+lw1cvZT8eIT4yY+Qfu4iMgI8MgbOJb 0DOKc3b1fmhpa/ox4AgTNHC4xaM3r5BoA9SBR/tdyHqidPtND3Q4Ngb/Ws4T+Gk33Skh Su/bL+bNHTmSLSjdqvPA1IwJyS2YQ3EBd7MJTCp3eBeL55gphJxyEUIeNs27OvEsytw8 2I2rNY5pm+sOJsrukNEHOPTLHBS/IkKIHp2dZPmjTD7Y2JpkTBSWJ0irtoOUYd6LvAVc 5tqpBKf85qR3i5mIFkZ5CeVnk9y2B0ZJ+Gqh36GU7WbuA/yGjIY7tYSiTA5lJTjVm96i Ho5Q==
  • Arc-seal: i=1; a=rsa-sha256; t=1666286180; cv=none; d=google.com; s=arc-20160816; b=yWh5en/94nnYe0+Dq0Gk6gTxy3o7ikx5GnaeWX0l59rHgpwy/Zv0VPx2iSUVpJ23PJ X4TAdqCQQ6GrMm9SbQP2yb7OFPjAYtpiD1ZVgCMpd0l7W7/a8zkufefMLZOsn4KRYP6P 8Ey42EObXVUa44kQtzIYmEG2iMBm3/97naveFscbwCMcKyCNpZbz0K4MCEqCZUMfMlz0 /6ZrO9MbI4MCox+UtyYniu9nezFkdsAZ8AhfacAo7isE15Aa3VSb5Ws7W08LgGxofV3H Y36gIbj+H9Npmq/M6Q/bwlbEblJsrYS0P76ISMq0xwXhxkzCBxpYnFn7J5FQ48S9UrUC ypQg==
  • Authentication-results: vscanx3.ucar.edu; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Ed5V36le
  • Authentication-results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ed5V36le; spf=pass (google.com: domain of mzp3769@xxxxxxxxx designates 209.85.220.41 as permitted sender) smtp.mailfrom=mzp3769@xxxxxxxxx; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Hello,
>From this group's archive and searches I figured that reading those with
f90 is probably
not possible. I wrote a simple code in C but that also is not successful.
Can you help with solving this problem?
Thanks,
Mark

netcdf file (datetime elements always 20 chars)
....

        int nlocs(nlocs) ;
                nlocs:suggested_chunk_dim = 429LL ;
....
group: MetaData {
  variables:
        string datetime(nlocs) ;
                string datetime:_FillValue = "" ;
                string datetime:units = "" ;


ncdump -v  datetime file.nc
.......
  datetime = "2021-09-30T23:02:25Z", "2021-09-30T23:07:25Z",
      "2021-09-30T23:09:23Z", "2021-09-30T23:17:25Z",
"2021-09-30T23:19:22Z",
.......

C code: (nlocs, length=20 are set to correct values)
...
  int status;
..
  size_t start[] = {0,0};
  size_t count[] = {nlocs,length+1};

  char datetime[nlocs][length+1];
  char *datetime_p[nlocs];

...
  for (i = 0; i < nlocs; i++)
    datetime_p[i] = datetime[i];
...
  if ((status = nc_get_vara_string(grpid, varid, start, count,
                                   datetime_p)))
    ERR(status);
/* Error: NetCDF: Start+count exceeds dimension bound */

  if ((status = nc_get_vara(grpid, varid, start, count,
                                   datetime_p)))
    ERR(status);
/* Error: NetCDF: Start+count exceeds dimension bound* /

  if ((status = nc_get_var(grpid, varid, datetime_p)))
    ERR(status);
/* values in array are garbage */

  if ((status = nc_get_var(grpid, varid, &datetime[0][0])))
    ERR(status);
/* values in array are garbage */
........

f90 code:
.......
INTEGER, PARAMETER :: date_string_length=20
CHARACTER(len=date_string_length), ALLOCATABLE :: aertimestr(:)
.......

CALL check_nc(nf90_inq_grp_ncid(ncid,"MetaData",grpid))
CALL check_nc(nf90_inq_varid(grpid,"datetime",varid))
CALL check_nc(nf90_get_var(grpid,varid,aertimestr))

.......
Error:
NetCDF: Attempt to convert between text & numbers
  • 2022 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: