Hi Frank, > you have added a Null-termination to the charracter. Transfering the > character to the C-style. From what I have found, the problem lies in the not > automaticly filling of missing blanks. If I have a 40 character long string > and I add a 32 character long string the remaining 8 character in the > netcdf-file are random. It looks like the solution is: > call check(nf90_put_var(iNcid, iVarStationName_ID , > cStationName,istart(1:2),iCount(1:2))) > > replacing the trim(cStationName) with the full cStationName. > > If a Null-termination is needed at the last place (shown in your example), it > should be from my point of view not inside the given 40 characters. But is > it realy necessary? > > I am not sure but from my point of view, an automatic filling of the > remaining characters with blanks would be helpful (and if needed the > Null-termination). Fortran programmers are not used to both. There is some advice about this in the netCDF Fortran documentation, in the section on "Reading and Writing Character String Values" in the netCDF Fortran documentation: https://www.unidata.ucar.edu/netcdf/docs/netcdf-f90/Reading-and-Writing-Character-String-Values.html where it says: ... Furthermore, variable-length strings are not supported by the netCDF classic interface except by convention; for example, you may treat a zero byte as terminating a character string, but you must explicitly specify the length of strings to be read from and written to netCDF variables. ... In Fortran 90, fixed-length strings may be written to a netCDF dataset without a terminating character, to save space. Variable-length strings should follow the C convention of writing strings with a terminating zero byte so that the intended length of the string can be determined when it is later read by either C or Fortran 90 programs. It is the users responsibility to provide such null termination. With netCDF-4, support for a "string" data type was added to the enhanced data model. If you use it, your data files will have to be stored in the netCDF-4 format which uses HDF5 underneath, and can only be accessed by software updated to handle netCDF-4 string data. If you assume you can use the full netCDF-4 data model with its support for compound structures (like C structs or Fortran-90 derived types), you can represent profile data more faithfully, but there are no CF Conventions yet for use of netCDF-4 strings or compound types. --Russ > Frank > > > > -----UrsprÃngliche Nachricht----- > Von: Unidata netCDF Support [mailto:address@hidden > Gesendet: Mittwoch, 19. MÃrz 2014 20:11 > An: address@hidden > Cc: address@hidden > Betreff: [netCDF #PKG-241010]: Fortran code exaple for netcdf > > Hi Frank, > > > due to a first help i was able to produce a first example. It is included > > as attachment. > > Thanks very much for making this available! > > > There is one problem left. Writing and reading the station_name as a > > char variable is producing additional character items in the nc-file > > and in the retrieved character value as a result of nf90_get_var > > > > Is there a solution? > > You sent a subsequent email saying you found a solution for the problem. As > you've noted, the StationName values are not terminated, since they're > represented as counted arrays of characters. My solution was just to replace > > write(6,'(1a,1i1,1a,1a)') "Station ",iStationNo,", StationName: > ",trim(cStationName) > > with > > write(6,'(1a,1i1,1a,1a)') "Station ",iStationNo,", StationName: > ",cStationName(1:(index(cStationName,char(0))-1)) > > but please let me know if you have a better or shorter fix. My Fortran is a > bit rusty ... > > > There is no problem, if you want to keep this example (after solving the > > remaining problem). > > Yes, I'd like to include it (with credit) as an extra example on our examples > page. > > --Russ > > > -----UrsprÃngliche Nachricht----- > > Von: Unidata netCDF Support [mailto:address@hidden > > Gesendet: Dienstag, 18. MÃrz 2014 20:42 > > An: address@hidden > > Cc: address@hidden > > Betreff: [netCDF #PKG-241010]: Fortran code exaple for netcdf > > > > Hi Frank, > > > > > I do not know if the support is free and so on... so if it is free > > > and there is some one who can help ... > > > > > > i have searched throughout the unidata webpage, but haven't found a > > > usable example to create, write and read station data with > > > netcdf-Fortran based on the Example H.3. Time series of station data > > > in the incomplete multidimensional array representation out of the > > > cf-convention 1.6. > > > > > > Is it possible to provide an example for the creation, writing and > > > reading of example H3 based on netcdf-Fortran(90)? > > > > I assume you're referring to the CF Conventions version 1.6, and the > > appendix H on Discrete Sampling Geometries. Sorry, but we don't even > > have good examples in C yet for those data structures. It would > > certainly be useful to provide more realistic examples, using the CF > > Conventions, than the primitive examples we currently make available > > at: > > > > http://www.unidata.ucar.edu/netcdf/examples/programs/ > > > > It's possible someone in the CF community may have written some test code > > or examples for these relatively new profile conventions, first introduced > > in the version 1.6 CF Conventions. You may want to inquire on the CF > > mailing list: > > > > http://mailman.cgd.ucar.edu/mailman/listinfo/cf-metadata > > > > --Russ > > > > Russ Rew UCAR Unidata Program > > address@hidden http://www.unidata.ucar.edu > > > > > > > > Ticket Details > > =================== > > Ticket ID: PKG-241010 > > Department: Support netCDF > > Priority: Normal > > Status: Closed > > > > > Russ Rew UCAR Unidata Program > address@hidden http://www.unidata.ucar.edu > > > > Ticket Details > =================== > Ticket ID: PKG-241010 > Department: Support netCDF > Priority: Normal > Status: Closed > > Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: PKG-241010 Department: Support netCDF Priority: Normal Status: Closed
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.