gdncvaropen.f90
Go to the documentation of this file.
1 != netCDF 変数のオープン
2 !
3 ! Authors:: Yasuhiro MORIKAWA, Eizi TOYODA
4 ! Version:: $Id: gdncvaropen.f90,v 1.2 2009-05-25 09:51:59 morikawa Exp $
5 ! Tag Name:: $Name: $
6 ! Copyright:: Copyright (C) GFD Dennou Club, 2000-2006. All rights reserved.
7 ! License:: See COPYRIGHT[link:../../COPYRIGHT]
8 !
9 ! 以下のサブルーチン, 関数は gtdata_netcdf_generic から提供されます。
10 !
11 
12 recursive subroutine gdncvaropen(var, url, writable, err)
13  use dc_types, only: string
17  use dc_url, only: urlsplit
18  use dc_error, only: storeerror
19  use dc_trace, only: beginsub, endsub
20  use netcdf, only: nf90_noerr, nf90_max_name, nf90_enotvar, nf90_ebaddim, &
21  & nf90_inq_varid, nf90_inq_dimid, nf90_inquire_variable, nf90_inquire
22  implicit none
23  type(gd_nc_variable), intent(out):: var
24  character(len = *), intent(in):: url
25  logical, intent(in), optional:: writable
26  logical, intent(out), optional:: err
27  character(len = STRING):: filename, varname
28  character(len = NF90_MAX_NAME):: dimname
29  integer:: stat, nvars, i
30  type(gd_nc_variable_search):: e
31  character(len = *), parameter:: subname = 'GDNcVarOpen'
32 continue
33  call beginsub(subname)
34  call urlsplit(url, file=filename, var=varname)
35  if (filename == "") filename = "gtool.nc"
36  call gdncfileopen(e%fileid, trim(filename), stat=stat, writable=writable, err=err )
37  if (stat /= 0) goto 999
38  !
39  ! 名前から変数を探し出す
40  !
41  if (varname /= '') then
42  e%varid = 0
43  stat = nf90_inq_varid(e%fileid, trim(varname), e%varid)
44  if (stat == nf90_enotvar) then
45  e%varid = 0
46  stat = nf90_noerr
47  endif
48  else
49  ! 名前が空ならできれば次元変数でない最初の変数をとりだす
50  stat = nf90_inquire(e%fileid, nvariables = nvars)
51  if (stat /= 0) goto 999
52  e%varid = 1
53  do, i = 1, nvars
54  stat = nf90_inquire_variable(e%fileid, i, name = dimname)
55  if (stat /= nf90_noerr) goto 999
56  stat = nf90_inq_dimid(e%fileid, dimname, e%dimid)
57  if (stat == nf90_noerr) cycle
58  if (stat /= nf90_ebaddim) goto 999
59  e%varid = i
60  stat = nf90_noerr
61  exit
62  enddo
63  endif
64  if (stat /= nf90_noerr) goto 999
65  !
66  ! 次元id を調べる
67  !
68  stat = nf90_inq_dimid(e%fileid, trim(varname), e%dimid)
69  if (stat /= nf90_noerr) then
70  if (e%varid <= 0) goto 999
71  e%dimid = 0
72  endif
73  !
74  stat = vtable_add(var, e)
75  if (stat /= nf90_noerr) goto 999
76  call endsub(subname, 'an=%d file=%d var=%d', i=(/var%id, e%fileid, e%varid/))
77  call storeerror(stat, subname, err)
78  return
79  !
80  ! エラー処理 (正常完了時も呼ぶ)
81  !
82 999 continue
83  var = gd_nc_variable(-1)
84  call endsub(subname, 'an=%d err', i=(/var%id/))
85  call storeerror(stat, subname, err, cause_c=url)
86 end subroutine gdncvaropen
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition: dc_error.f90:830
integer function, public vtable_add(var, entry)
subroutine, public beginsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca, version)
Definition: dc_trace.f90:351
subroutine gdncfileopen(fileid, filename, writable, overwrite, stat, err)
Definition: gdncfileopen.f90:2
種別型パラメタを提供します。
Definition: dc_types.f90:49
recursive subroutine gdncvaropen(var, url, writable, err)
Definition: gdncvaropen.f90:13
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118