NetCDF-Fortran  4.4.4
netcdf4_file.f90
Go to the documentation of this file.
1 ! This is part of netCDF-4. Copyright 2006 UCAR. See COPYRIGHT file
2 ! for details.
3 
4 ! This file contains the netcdf-4 file open and create functions.
5 
6 ! $Id: netcdf4_constants.f90,v 1.14 2010/05/25 13:53:00 ed Exp $
7 ! -------
8 function nf90_open(path, mode, ncid, chunksize, cache_size, cache_nelems, &
9  cache_preemption, comm, info)
10  implicit none
11  character (len = *), intent(in) :: path
12  integer, intent(in) :: mode
13  integer, intent(out) :: ncid
14  integer, optional, intent(inout) :: chunksize
15  integer, optional, intent(in) :: cache_size, cache_nelems
16  real, optional, intent(in) :: cache_preemption
17  integer, optional, intent(in) :: comm, info
18  integer :: size_in, nelems_in, preemption_in
19  integer :: size_out, nelems_out, preemption_out, ret
20  integer :: nf90_open
21 
22  ! If using parallel, both comm and info must be provided.
23  if (present(comm) .and. .not. present(info)) then
24  nf90_open = nf90_einval;
25  return
26  end if
27 
28  ! If the user specified chuck cache parameters, use them. But user
29  ! may have specified one, two, or three settings. Leave the others
30  ! unchanged.
31  if (present(cache_size) .or. present(cache_nelems) .or. &
32  present(cache_preemption)) then
33  ret = nf_get_chunk_cache(size_in, nelems_in, preemption_in)
34  if (ret .ne. nf90_noerr) then
35  nf90_open = ret
36  return
37  end if
38  if (present(cache_size)) then
39  size_out = cache_size
40  else
41  size_out = size_in
42  end if
43  if (present(cache_nelems)) then
44  nelems_out = cache_nelems
45  else
46  nelems_out = nelems_in
47  end if
48  if (present(cache_preemption)) then
49  preemption_out = cache_preemption
50  else
51  preemption_out = preemption_in
52  end if
53  nf90_open = nf_set_chunk_cache(size_out, nelems_out, preemption_out)
54  if (nf90_open .ne. nf90_noerr) return
55  end if
56 
57  ! Do the open.
58  if(present(chunksize)) then
59  nf90_open = nf__open(path, mode, chunksize, ncid)
60  else
61  if (present(comm)) then
62  nf90_open = nf_open_par(path, mode, comm, info, ncid)
63  else
64  nf90_open = nf_open(path, mode, ncid)
65  end if
66  end if
67  if (nf90_open .ne. nf90_noerr) return
68 
69  ! If settings were changed, reset chunk chache to original settings.
70  if (present(cache_size) .or. present(cache_nelems) .or. &
71  present(cache_preemption)) then
72  nf90_open = nf_set_chunk_cache(size_in, nelems_in, preemption_in)
73  end if
74 
75 end function nf90_open
76 ! -------
77 function nf90_create(path, cmode, ncid, initialsize, chunksize, cache_size, &
78  cache_nelems, cache_preemption, comm, info)
79  implicit none
80  character (len = *), intent(in) :: path
81  integer, intent(in) :: cmode
82  integer, intent(out) :: ncid
83  integer, optional, intent(in) :: initialsize
84  integer, optional, intent(inout) :: chunksize
85  integer, optional, intent(in) :: cache_size, cache_nelems
86  integer, optional, intent(in) :: cache_preemption
87  integer, optional, intent(in) :: comm, info
88  integer :: size_in, nelems_in, preemption_in
89  integer :: size_out, nelems_out, preemption_out, ret
90  integer :: nf90_create
91  integer :: fileSize, chunk
92  integer :: x
93 
94  ! Just ignore options netCDF-3 options for netCDF-4 files, or
95  ! netCDF-4 options, for netCDF-3 files, so that the same user code
96  ! can work for both cases.
97 
98  ! If using parallel, but comm and info must be provided.
99  if (present(comm) .and. .not. present(info)) then
100  nf90_create = nf90_einval;
101  return
102  end if
103 
104  ! If the user specified chuck cache parameters, use them. But user
105  ! may have specified one, two, or three settings. Leave the others
106  ! unchanged.
107  if (present(cache_size) .or. present(cache_nelems) .or. &
108  present(cache_preemption)) then
109  nf90_create = nf_get_chunk_cache(size_in, nelems_in, preemption_in)
110  if (nf90_create .ne. nf90_noerr) return
111  if (present(cache_size)) then
112  size_out = cache_size
113  else
114  size_out = size_in
115  end if
116  if (present(cache_nelems)) then
117  nelems_out = cache_nelems
118  else
119  nelems_out = nelems_in
120  end if
121  if (present(cache_preemption)) then
122  preemption_out = cache_preemption
123  else
124  preemption_out = preemption_in
125  end if
126  nf90_create = nf_set_chunk_cache(size_out, nelems_out, preemption_out)
127  if (nf90_create .ne. nf90_noerr) return
128  end if
129 
130  ! Do the file create.
131  if(.not. (present(initialsize) .or. present(chunksize)) ) then
132  if (present(comm)) then
133  nf90_create = nf_create_par(path, cmode, comm, info, ncid)
134  else
135  nf90_create = nf_create(path, cmode, ncid)
136  end if
137  else
138  ! Default values per man page
139  filesize = 0; chunk = nf90_sizehint_default
140  if(present(initialsize)) filesize = initialsize
141  if(present(chunksize )) chunk = chunksize
142  nf90_create = nf__create(path, cmode, filesize, chunk, ncid)
143  ! Pass back the value actually used
144  if(present(chunksize )) chunksize = chunk
145  end if
146  if (nf90_create .ne. nf90_noerr) return
147 
148  ! If settings were changed, reset chunk chache to original settings.
149  if (present(cache_size) .or. present(cache_nelems) .or. &
150  present(cache_preemption)) then
151  nf90_create = nf_set_chunk_cache(size_in, nelems_in, preemption_in)
152  end if
153 
154 
155 end function nf90_create
function nf__create(path, cmode, initialsz, chunksizehintp, ncid)
Definition: nf_control.F90:81
integer function nf__open(path, mode, chunksizehintp, ncid)
Definition: nf_control.F90:199
integer function nf90_create(path, cmode, ncid, initialsize, chunksize)
integer function nf_open(path, mode, ncid)
Definition: nf_control.F90:163
integer function nf_set_chunk_cache(chunk_size, nelems, preemption)
Definition: nf_nc4.f90:2600
integer function nf_create(path, cmode, ncid)
Definition: nf_control.F90:37
integer function nf_create_par(path, cmode, comm, info, ncid)
Definition: nf_nc4.f90:38
integer function nf90_open(path, mode, ncid, chunksize)
Definition: netcdf3_file.f90:9
integer function nf_get_chunk_cache(chunk_size, nelems, preemption)
Definition: nf_nc4.f90:2626
integer function nf_open_par(path, mode, comm, info, ncid)
Definition: nf_nc4.f90:71

Return to the Main Unidata NetCDF page.
Generated on Tue Jul 17 2018 12:21:03 for NetCDF-Fortran. NetCDF is a Unidata library.