Due to the current gap in continued funding from the U.S. National Science Foundation (NSF), the NSF Unidata Program Center has temporarily paused most operations. See NSF Unidata Pause in Most Operations for details.
Thanks for the tip, looks like a good starting point, Mark On Fri, Oct 21, 2022 at 9:20 AM Dave Allured - NOAA Affiliate < dave.allured@xxxxxxxx> wrote: > MP, download a copy of the netcdf-c source code. In the test directories, > I think there are valid working examples of reading and writing string > arrays with C. In particular, look for files tst_string*.c. This should > get you started. > > If desired, you can then write a fortran-callable C routine that reads > string arrays, using a memory structure of your own choice. > > > On Thu, Oct 20, 2022 at 12:34 PM M P <mzp3769@xxxxxxxxx> wrote: > >> 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 >> >
netcdfgroup
archives: