FMS  2025.04
Flexible Modeling System
mpp_read_distributed_ascii.inc
1 !***********************************************************************
2 !* Apache License 2.0
3 !*
4 !* This file is part of the GFDL Flexible Modeling System (FMS).
5 !*
6 !* Licensed under the Apache License, Version 2.0 (the "License");
7 !* you may not use this file except in compliance with the License.
8 !* You may obtain a copy of the License at
9 !*
10 !* http://www.apache.org/licenses/LICENSE-2.0
11 !*
12 !* FMS is distributed in the hope that it will be useful, but WITHOUT
13 !* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied;
14 !* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 !* PARTICULAR PURPOSE. See the License for the specific language
16 !* governing permissions and limitations under the License.
17 !***********************************************************************
18 
19 !> @file
20 !> @brief Routines for reading distributed ascii files for @ref mpp_io_mod
21 
22 !> @addtogroup mpp_io_mod
23 !> @{
24 
25 #undef MPP_READ_DISTRIBUTED_ASCII_1D_
26 #define MPP_READ_DISTRIBUTED_ASCII_1D_ mpp_read_distributed_ascii_r1D
27 #undef MPP_TYPE_
28 #define MPP_TYPE_ real
29 #include <mpp_read_distributed_ascii.fh>
30 
31 #undef MPP_READ_DISTRIBUTED_ASCII_1D_
32 #define MPP_READ_DISTRIBUTED_ASCII_1D_ mpp_read_distributed_ascii_i1D
33 #undef MPP_TYPE_
34 #define MPP_TYPE_ integer
35 #include <mpp_read_distributed_ascii.fh>
36 
37 subroutine mpp_read_distributed_ascii_a1d(unit,fmt,ssize,data,iostat)
38  integer, intent(in) :: unit
39  character(*), intent(in) :: fmt
40  integer, intent(in) :: ssize
41  character(len=*), dimension(:), intent(inout) :: data
42  integer, intent(out) :: iostat
43 
44  integer, allocatable :: pelist(:)
45  logical :: is_ioroot=.false.
46 
47 
48  if(.not.module_is_initialized) call mpp_error(fatal,'mpp_read_distributed_ascii_a1D: module not initialized')
49 
50  iostat = 0
51  call mpp_dist_io_pelist(ssize,pelist)
52  if(.not. ALLOCATED(pelist)) &
53  call mpp_error(fatal,'mpp_read_distributed_ascii_a1D: pelist allocation failed')
54  is_ioroot = mpp_is_dist_ioroot(ssize)
55  if(is_ioroot) then
56  if(trim(fmt)=='*')then
57  read(unit,*,iostat=iostat) data
58  else
59  read(unit,fmt=trim(fmt),iostat=iostat) data
60  endif
61  if(iostat /= 0) return ! Calling routine must handle error
62  endif
63 
64  call mpp_broadcast(data,len(data(1)),pelist(1),pelist)
65  deallocate(pelist) ! Don't forget to deallocate pelist
66 end subroutine mpp_read_distributed_ascii_a1d
67 !> @}