This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi Scott, > Email Address: address@hidden > Organization: UCLA > Package Version: > Operating System: Linux > > I am trying to read in a Time variable (character) output by WRF using > the C++/netCDF interface. What is the proper way to do this? > > This works: > char timein[NTIM][19]; > if (!timVar->get(&timein[0][0], NTIM)) > return NC_ERR; > > Then, I simply want to extract the year, mo, day and hour into separate > integer or string variables. How can I do this? > > Here is the ncdump -h output: > > dimensions: > Time = UNLIMITED ; // (48 currently) > DateStrLen = 19 ; > west_east = 195 ; > south_north = 126 ; > variables: > char Times(Time, DateStrLen) ; > > and, some examples: > Time[0] DateStrLen[0] Times[0--18]='2012-12-01_12:00:00' > Time[1] DateStrLen[0] Times[19--37]='2012-12-01_13:00:00' > Time[2] DateStrLen[0] Times[38--56]='2012-12-01_14:00:00' > Time[3] DateStrLen[0] Times[57--75]='2012-12-01_15:00:00' > Time[4] DateStrLen[0] Times[76--94]='2012-12-01_16:00:00' Sorry, the netCDF library doesn't have any general string-parsing functions. These date-time strings are all fixed length, so I would think you could do what you want by just indexing into the string and using a library function such as strncpy() from the C libraries or whatever the equivalent is for C++. --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: ZPG-755636 Department: Support netCDF Priority: Normal Status: Closed