00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 module ice_fileunits
00032
00033
00034 use ice_kinds_mod
00035 #ifdef CCSMCOUPLED
00036 use shr_file_mod
00037 #endif
00038
00039
00040
00041
00042 implicit none
00043 save
00044
00045 character (len=char_len) ::
00046 diag_type
00047
00048 integer (kind=int_kind) ::
00049 nu_grid ,
00050 nu_kmt ,
00051 nu_nml ,
00052 nu_forcing ,
00053 nu_dump ,
00054 nu_restart ,
00055 nu_dump_aero ,
00056 nu_restart_aero,
00057 nu_dump_age ,
00058 nu_restart_age,
00059 nu_dump_FY ,
00060 nu_restart_FY ,
00061 nu_dump_pond ,
00062 nu_restart_pond,
00063 nu_rst_pointer,
00064 nu_history ,
00065 nu_hdr ,
00066 nu_diag ,
00067 nu_timing
00068
00069 integer (kind=int_kind) ::
00070 diag_level
00071
00072 character (6), parameter ::
00073 nml_filename = 'ice_in'
00074
00075 integer (kind=int_kind), parameter ::
00076 ice_stdin = 5,
00077 ice_stdout = 6,
00078 ice_stderr = 6
00079
00080
00081
00082
00083 integer (kind=int_kind), parameter ::
00084 ice_IOUnitsMinUnits = 11,
00085 ice_IOUnitsMaxUnits = 99
00086
00087 logical (kind=log_kind), dimension(ice_IOUnitsMaxUnits) ::
00088 ice_IOUnitsInUse
00089
00090
00091
00092 contains
00093
00094
00095
00096
00097
00098
00099 subroutine init_fileunits
00100
00101
00102
00103
00104
00105
00106 nu_diag = ice_stdout
00107
00108 #ifdef CCSMCOUPLED
00109 ice_IOUnitsInUse = .false.
00110 ice_IOUnitsInUse(ice_stdin) = .true.
00111 ice_IOUnitsInUse(ice_stdout) = .true.
00112 ice_IOUnitsInUse(ice_stderr) = .true.
00113
00114 nu_grid = shr_file_getUnit()
00115 nu_kmt = shr_file_getUnit()
00116 nu_forcing = shr_file_getUnit()
00117 nu_dump = shr_file_getUnit()
00118 nu_restart = shr_file_getUnit()
00119 nu_dump_aero = shr_file_getUnit()
00120 nu_restart_aero= shr_file_getUnit()
00121 nu_dump_age = shr_file_getUnit()
00122 nu_restart_age = shr_file_getUnit()
00123 nu_dump_FY = shr_file_getUnit()
00124 nu_restart_FY = shr_file_getUnit()
00125 nu_dump_pond = shr_file_getUnit()
00126 nu_restart_pond = shr_file_getUnit()
00127 nu_rst_pointer = shr_file_getUnit()
00128 nu_history = shr_file_getUnit()
00129 nu_hdr = shr_file_getUnit()
00130 nu_timing = shr_file_getUnit()
00131 #else
00132 call get_fileunit(nu_grid)
00133 call get_fileunit(nu_kmt)
00134 call get_fileunit(nu_forcing)
00135 call get_fileunit(nu_dump)
00136 call get_fileunit(nu_restart)
00137 call get_fileunit(nu_dump_aero)
00138 call get_fileunit(nu_restart_aero)
00139 call get_fileunit(nu_dump_age)
00140 call get_fileunit(nu_restart_age)
00141 call get_fileunit(nu_dump_FY)
00142 call get_fileunit(nu_restart_FY)
00143 call get_fileunit(nu_dump_pond)
00144 call get_fileunit(nu_restart_pond)
00145 call get_fileunit(nu_rst_pointer)
00146 call get_fileunit(nu_history)
00147 call get_fileunit(nu_hdr)
00148 call get_fileunit(nu_timing)
00149 #endif
00150
00151 end subroutine init_fileunits
00152
00153
00154
00155
00156
00157
00158 subroutine get_fileunit(iunit)
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 integer (kind=int_kind), intent(out) ::
00173 iunit
00174
00175
00176
00177 integer (kind=int_kind) :: n
00178
00179 logical (kind=log_kind) :: alreadyInUse
00180
00181 #ifdef CCSMCOUPLED
00182 iunit = shr_file_getUnit()
00183 #else
00184 srch_units: do n=ice_IOUnitsMinUnits, ice_IOUnitsMaxUnits
00185 if (.not. ice_IOUnitsInUse(n)) then
00186
00187
00188 INQUIRE (unit=n,OPENED=alreadyInUse)
00189
00190 if (.not. alreadyInUse) then
00191 iunit = n
00192 ice_IOUnitsInUse(n) = .true.
00193 exit srch_units
00194 else
00195
00196
00197 ice_IOUnitsInUse(iunit) = .true.
00198 endif
00199 endif
00200 end do srch_units
00201
00202 if (iunit > ice_IOUnitsMaxUnits) stop 'ice_IOUnitsGet: No free units'
00203 #endif
00204
00205
00206 end subroutine get_fileunit
00207
00208
00209
00210
00211
00212
00213 subroutine release_all_fileunits
00214
00215
00216
00217
00218 call release_fileunit(nu_grid)
00219 call release_fileunit(nu_kmt)
00220 call release_fileunit(nu_forcing)
00221 call release_fileunit(nu_dump)
00222 call release_fileunit(nu_restart)
00223 call release_fileunit(nu_dump_aero)
00224 call release_fileunit(nu_restart_aero)
00225 call release_fileunit(nu_dump_age)
00226 call release_fileunit(nu_restart_age)
00227 call release_fileunit(nu_dump_FY)
00228 call release_fileunit(nu_restart_FY)
00229 call release_fileunit(nu_dump_pond)
00230 call release_fileunit(nu_restart_pond)
00231 call release_fileunit(nu_rst_pointer)
00232 call release_fileunit(nu_history)
00233 call release_fileunit(nu_hdr)
00234 call release_fileunit(nu_timing)
00235 if (nu_diag /= ice_stdout) call release_fileunit(nu_diag)
00236
00237 end subroutine release_all_fileunits
00238
00239
00240
00241
00242
00243
00244 subroutine release_fileunit(iunit)
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 integer (kind=int_kind), intent(in) ::
00258 iunit
00259
00260
00261
00262 #ifdef CCSMCOUPLED
00263 call shr_file_freeUnit(iunit)
00264 #else
00265
00266 if (iunit < 1 .or. iunit > ice_IOUnitsMaxUnits) then
00267 stop 'release_fileunit: bad unit'
00268 endif
00269
00270
00271 ice_IOUnitsInUse(iunit) = .false.
00272 #endif
00273
00274
00275 end subroutine release_fileunit
00276
00277
00278
00279
00280
00281
00282 subroutine flush_fileunit(iunit)
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 #ifdef CCSMCOUPLED
00299 use shr_sys_mod, only : shr_sys_flush
00300 #endif
00301
00302
00303
00304 integer (kind=int_kind), intent(in) ::
00305 iunit
00306
00307
00308
00309
00310
00311
00312
00313
00314 #if (defined IRIX64 || defined CRAY || defined OSF1 || defined SUNOS || defined LINUX || defined NEC_SX | defined UNICOSMP)
00315 call flush(iunit)
00316 #endif
00317 #if (defined AIX)
00318 call flush_(iunit)
00319 #endif
00320
00321 #ifdef CCSMCOUPLED
00322 call shr_sys_flush(iunit)
00323 #endif
00324
00325
00326 end subroutine flush_fileunit
00327
00328
00329
00330 end module ice_fileunits
00331
00332