subroutine GDNcFileSync(fileid, stat)
  use gtdata_netcdf_file_types, only: GD_NC_FILE_ID_ENTRY
  use gtdata_netcdf_file_internal, only: id_head, id_used
  use gtdata_netcdf_file_generic, only: GDNcFileDataMode
  use netcdf, only: NF90_SYNC, NF90_NOERR
  use dc_error
  integer, intent(in), optional:: fileid
  integer, intent(out), optional:: stat
  integer:: ncid, mystat
  type(GD_NC_FILE_ID_ENTRY), pointer:: identptr
continue
  mystat = NF90_NOERR
  if (present(fileid)) then
    ncid = fileid
    mystat = GDNcFileDataMode(ncid)
    if (mystat /= NF90_NOERR) goto 999
    mystat = NF90_SYNC(ncid)
  else if (id_used) then
    identptr => id_head
    do
      if (.not. associated(identptr)) exit
      ncid = identptr % id
      mystat = GDNcFileDataMode(ncid)
      if (mystat /= NF90_NOERR) exit
      mystat = NF90_SYNC(ncid)
      if (mystat /= NF90_NOERR) exit
      identptr => identptr % next
    enddo
  endif
999 continue
  ! è‡ªç™ºçš„ã«ã¯ StoreError ã—ãªã„ã€‚StoreError ã® SysdepAbort
  ! ã‹ã‚‰ã‚‚å‘¼ã°ã‚Œã‚‹å¯èƒ½æ€§ãŒã‚ã‚‹ãŸã‚ã§ã‚ã‚‹ã€‚
  if (present(stat)) stat = mystat
end subroutine GDNcFileSync