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.
> Organization: NCAR/CGD/CMS > Keywords: 199402091734.AA18782 Hi Charlie, > hi, i'm having conceptual problems with fortran netcdf on the > cgd suns. it's not behaving at all like i expect it to. i have > codes written in C that work flawlessly reading and writing netcdf files, > and i have fortran codes that have no problem reading netcdf files > created with C language netcdf routines, but i can't get my fortran > codes to write netcdf files. i've simplified things by only using > type NCFLOAT and NCLONG and do not use any implicit double > precision (-r8) flags. i use the default sun integer length of 4 bytes. > my netcdf routine is getting the correct values but not writing them > out correctly and i have no idea what i'm doing wrong. in the future > i will want the my fortran to work with the -r8 flag so any pointers > on that will be appreciated as well. i am enclosing the subroutine > (which is not standalone because it has two other include files for > the C preprocessor) in case you are interested. the resulting netcdf > file is all Floatinf's except the one integer i write which is turned > into a garbage integer. any help would be appreciated, It's hard to tell what's going on in a large code like this without access to included files and calling routines, but I see a couple of errors that may be causing the problems you are seeing. First, I can't tell from the code you provided whether the variables "plev" and "plevp" are ever initialized before they are used as parameters in NCDDEF calls to define the associatred dimensions: > plev_dim=ncddef(cdfid,'plev',plev,rcode) > plevp_dim=ncddef(cdfid,'plevp',plevp,rcode) Assuming these are OK, your NCVDEF calls look OK too. A second problem is that you never call NCENDF after defining dimensions and variables but before atempting to write values into the variables. I'm surprised you didn't get an error the first time you tried to call NCVPT after your last NCVDEF call without an intervening NCENDF call. Perhaps you had set set error handling so that netCDF erors are nonfatal in preceding code. In that case you should be checking the values of the return code. You should also be creating your attributes while in define mode, before the call to NCENDF preceding your calls to NCVPT. __________________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden P.O. Box 3000 (303)497-8645 Boulder, Colorado 80307-3000