NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
Dear all,This time around I have come up with a problem concerning compound types. I scripted a FORTRAN subroutine to write data in compound form into a .nc file and it compiles perfectly, however, it gives exactly the error "Unknown error" when I run the model calling the ncwrite function after model run once is completed. My FORTRAN subroutine file is attached. It gives the error when it reaches the line with "nf90_def_compound" function. My netCDF version is 4.1.3 and fortran compiler is gfortran 4.4.5. I had compiled netCDF with --disable-netcdf-4 option. Could this be the cause of the problem?
Regards, Ekin On 02/23/2012 10:58 AM, Ekin Akoglu wrote:
Dear all,I have come up with an answer to my question, that is, user-defined "compound types" in netCDF. The compound types are not very well documented under FORTRAN API, however, section for C API gives also an example where one can develop on for FORTRAN. If you are also interested please see: http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-f90/Compound-Types.html#Compound-TypesThank you... Ekin On 02/22/2012 10:03 PM, Ekin Akoglu wrote:Dear all,I am quite inexperienced in using netCDF FORTRAN API and netCDF format in storing data. Currently I am struggling on a problem. I have user derived data types in FORTRAN with multiple components, i.e. fields, such as:ep_data%biomass ep_data%pob .... ms_data%biomass ms_data%age ...Is there a way to envelope the fields (after % sign) under e.g. "ms_data" and "ep_data" defined types when writing in a single netcdf file so that the "biomass" field of "ms_data" does not interfere with the "biomass" field of "ep_data" while reading it from the .nc file? I would be glad to hear if you have suggestions on the matter.Regards, -- *Ekin Akoglu* Research Assistant Institute of Marine Sciences Middle East Technical University P.O. Box 28, 33731 Erdemli, Mersin Turkey Web: www.ims.metu.edu.tr Email: ekin@xxxxxxxxxxxxxxx <mailto:ekin@xxxxxxxxxxxxxxx> Phone: +90 324 521 34 34 GSM: +90 506 554 03 90 Fax: +90 324 521 23 27 _______________________________________________ netcdfgroup mailing list netcdfgroup@xxxxxxxxxxxxxxxxFor list information or to unsubscribe, visit:http://www.unidata.ucar.edu/mailing_lists/-- *Ekin Akoglu* Research Assistant Institute of Marine Sciences Middle East Technical University P.O. Box 28, 33731 Erdemli, Mersin Turkey Web: www.ims.metu.edu.tr Email: ekin@xxxxxxxxxxxxxxx <mailto:ekin@xxxxxxxxxxxxxxx> Phone: +90 324 521 34 34 GSM: +90 506 554 03 90 Fax: +90 324 521 23 27 _______________________________________________ netcdfgroup mailing list netcdfgroup@xxxxxxxxxxxxxxxx For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/
-- *Ekin Akoglu* Research Assistant Institute of Marine Sciences Middle East Technical University P.O. Box 28, 33731 Erdemli, Mersin Turkey Web: www.ims.metu.edu.tr Email: ekin@xxxxxxxxxxxxxxx <mailto:ekin@xxxxxxxxxxxxxxx> Phone: +90 324 521 34 34 GSM: +90 506 554 03 90 Fax: +90 324 521 23 27
subroutine ncwrite(nvars, nstanzas, drows, dcols, ep_data, ms_data, ep_diet) use statevartypesEcopath_mod use netcdf implicit none ! This is the name of the data file we will read. character (len = *), parameter :: FILE_NAME = "ecopath_results.nc" ! variables inherited from Ecopath model integer, intent(in) :: nvars, nstanzas, drows, dcols type(ecopath_data), intent(in) :: ep_data type(multi_stanza), intent(in) :: ms_data(nstanzas) real(4), intent(in) :: ep_diet(drows, dcols) ! in-subroutine variable declarations integer :: ncid, typeid, field_typeid ! Create the netCDF file. The nf90_clobber parameter tells netCDF to ! overwrite this file, if it already exists. call check( nf90_create(FILE_NAME, NF90_CLOBBER, ncid) ) call check( nf90_def_compound(ncid, sizeof(ep_data), "ecopath_data", typeid) ) call check( nf90_insert_compound(ncid, typeid, "biomass", 1, field_typeid) ) call check( nf90_enddef(ncid) ) call check( nf90_put_vara(ncid, typeid, field_typeid, nvars, ep_data%biomass) ) ! Close the file. This frees up any internal netCDF resources ! associated with the file, and flushes any buffers. call check( nf90_close(ncid) ) print *, "*** SUCCESS writing Ecopath output file ecopath_results.nc! " contains subroutine check(status) integer, intent ( in) :: status if(status /= nf90_noerr) then print *, trim(nf90_strerror(status)) stop "Stopped" end if end subroutine check function nf90_def_compound(ncid, size, name, typeid) integer, intent(in) :: ncid integer(8), intent(in) :: size character (len = *), intent(in) :: name integer, intent(out) :: typeid integer :: nf90_def_compound end function nf90_def_compound function nf90_insert_compound(ncid, xtype, name, offset, field_typeid) integer, intent(in) :: ncid integer, intent(in) :: xtype character (len = *), intent(in) :: name integer, intent(in) :: offset integer, intent(in) :: field_typeid integer :: nf90_insert_compound end function nf90_insert_compound function nf90_put_vara(ncid, typeid, field_typeid, array_size, data) integer, intent(in) :: ncid integer, intent(in) :: typeid integer, intent(in) :: field_typeid integer, intent(in) :: array_size real(4), intent(in) :: data(array_size) integer :: nf90_put_vara end function nf90_put_vara end subroutine ncwrite
netcdfgroup
archives: