1 !***********************************************************************
2 !* GNU Lesser General Public License
4 !* This file is part of the GFDL Flexible Modeling System (FMS).
6 !* FMS is free software: you can redistribute it and/or modify it under
7 !* the terms of the GNU Lesser General Public License as published by
8 !* the Free Software Foundation, either version 3 of the License, or (at
9 !* your option) any later version.
11 !* FMS is distributed in the hope that it will be useful, but WITHOUT
12 !* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 !* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 !* You should have received a copy of the GNU Lesser General Public
17 !* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
18 !***********************************************************************
21 !> @addtogroup fms_io_mod
24 !> Return a flag indicating whether the inputted field exists in the inputted
25 !!file, where the file is associated with an unstructured mpp domain.
26 function fms_io_unstructured_field_exist(file_name, &
29 result(does_field_exist)
32 character(len=*),intent(in) :: file_name !<Name of a file.
33 character(len=*),intent(in) :: field_name !<Name of a field.
34 type(domainUG),intent(in) :: domain !<An unstructured mpp domain.
35 logical(INT_KIND) :: does_field_exist !<Flag telling if the inputted field exists in the inputted file.
38 logical(INT_KIND) :: file_exist !<Flag telling if the inputted file
39 !! or one of its variants exists.
40 character(len=256) :: fname !<Actual name of the found file.
41 logical(INT_KIND) :: read_dist !<Flag telling if the file is "distributed"
42 !! (has IO domain tile id appended onto the end).
43 integer(INT_KIND) :: funit !<A file unit.
44 integer(INT_KIND) :: nfile !<Index of the inputted file in
45 !! the "files_read" module array.
46 integer(INT_KIND) :: i !<Loop variable.
47 integer(INT_KIND) :: ndim !<Number of dimensions in a file.
48 integer(INT_KIND) :: nvar !<Number of fields in a file.
49 integer(INT_KIND) :: natt !<Number of attributes in a file.
50 integer(INT_KIND) :: ntime !<Number of time levels in a file.
51 character(len=64) :: tmp_name !<Name of a field.
52 type(fieldtype),dimension(:),allocatable :: fields !<An array of fields found in the input file.
55 !Set default return value for the function.
56 does_field_exist = .false.
58 !Return if the inputted field name is in valid.
59 if (len_trim(field_name) .eq. 0) then
62 if (field_name(1:1) .eq. ' ') then
66 !Check if the file exists.
67 file_exist = fms_io_unstructured_get_file_name(file_name, &
74 !Get the file unit for the input file.
75 call fms_io_unstructured_get_file_unit(fname, &
81 !Get the number of dimensions, fields, attributes and time levels
83 call mpp_get_info(funit, &
89 !Create an array of all fields contained in the file.
90 allocate(fields(nvar))
91 call mpp_get_fields(funit, &
94 !Loop through the fields to see if the inputted field name matches
95 !any of the fields from the file.
97 call mpp_get_atts(fields(i), &
99 if (lowercase(trim(tmp_name)) .eq. lowercase(trim(field_name))) then
100 does_field_exist = .true.
104 !Deallocate local allocatable.
109 end function fms_io_unstructured_field_exist