00001
00002
00003
00004
00005
00006
00007 program sibdrive
00008
00009 use kinds
00010 use timetype
00011 use sib_const_module
00012 use sib_io_module
00013 use sibtype
00014 implicit none
00015
00016
00017 type(sib_t), dimension(:), allocatable :: sib
00018 type(time_struct) :: time
00019 integer(kind=long_kind) :: t
00020 integer(kind=int_kind) :: i,j
00021 integer(kind=int_kind) :: rank
00022 integer(kind=int_kind) :: nchunks
00023 integer, external :: iargc
00024 real(kind=dbl_kind) del_store
00025 real(kind=dbl_kind) sum_flux
00026 real(kind=dbl_kind) residual
00027 character*100 filename
00028
00029
00030 real etime
00031 real elapsed(2)
00032 real total
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 character(len=4) :: one, two
00054 character(len=4) :: dfdfd
00055
00056
00057 call getarg( 1, one )
00058 if ( one == '' .or. one == '>' ) then
00059 rank = 1
00060 nchunks = 1
00061 else
00062 call getarg( 2, two )
00063 if ( two == '' .or. two == '>' ) then
00064 stop 'Command line arguments incorrect: SiBD3 rank nchunks'
00065 else
00066 read( one, * ) rank
00067 read( two, * ) nchunks
00068 if ( rank > nchunks ) stop 'nchunks greater than rank'
00069 if ( rank < 1 .or. nchunks < 1 ) stop 'rank or nchunks < 1'
00070 endif
00071 endif
00072
00073
00074
00075
00076
00077 call init_grid( rank, nchunks )
00078
00079
00080 allocate( sib(subcount) )
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 call init_var(sib)
00092
00093
00094 call init_sibdrv( sib, time )
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 call time_check( time)
00128
00129
00130 call output_control( sib, time, rank )
00131
00132
00133 do t = time%start_second, time%end_second - time%dtsib, time%dtsib
00134
00135
00136 if ( time%sec_day == time%dtsib ) then
00137 print*, time%month_names(time%month),time%day,time%year
00138
00139 endif
00140
00141
00142
00143 if ( time%new_day ) call solar_dec( time )
00144
00145
00146 if ( time%read_driver ) then
00147 if ( drvr_type == 'ecmwf' ) then
00148 call sibdrv_read_ecmwf( sib, time )
00149 elseif ( drvr_type == 'ncep1' ) then
00150 call sibdrv_read_ncep1( sib, time )
00151 elseif ( drvr_type == 'ncep2' ) then
00152 call sibdrv_read_ncep2( sib, time )
00153 elseif ( drvr_type == 'geos4' ) then
00154 call sibdrv_read_geos4( sib, time )
00155 elseif ( drvr_type == 'single' ) then
00156 call sibdrv_read_single( sib, time )
00157 elseif ( drvr_type == 'ncp_sngl' ) then
00158 call sibdrv_read_ncep2_single( sib, time )
00159
00160
00161 else
00162 stop 'Invalid drvr_type specified'
00163 endif
00164
00165
00166 call mean_zenith_angle( sib, time )
00167 endif
00168
00169 if(time%switch_bc .OR. time%read_bc) then
00170 print*,time%sec_day,time%switch_bc,time%read_bc
00171 endif
00172
00173
00174
00175 if ( time%switch_bc ) then
00176 if ( drvr_type == 'single' .OR. drvr_type == 'ncp_sngl') then
00177 write (filename, "(a,i4)") trim(param_path), time%year+1
00178 call open_single_td( sib, time, filename)
00179 else
00180 write (filename, "(a,i4,a3)") trim(param_path), time%year+1, '.nc'
00181
00182 call open_global_td( sib, time, filename)
00183 endif
00184 print*, 'switch parameter file to ', trim(filename)
00185 endif
00186
00187
00188 if ( time%read_bc ) then
00189 if ( drvr_type == 'single'.OR. drvr_type == 'ncp_sngl' ) then
00190
00191 call read_single_td_param(sib,time)
00192 else
00193
00194 call read_global_td_param(sib,time)
00195 endif
00196 endif
00197
00198
00199 if (t > time%start_second + time%dtsib) call need_to_switch(sib,time)
00200
00201
00202 if ( time%new_day ) call bc_interp( sib, time )
00203
00204
00205
00206 call sibdrv_interp( sib, time )
00207
00208
00209 dtt = time%dtsib
00210 dti = 1./dtt
00211 tau = time%sec_year
00212
00213
00214 do i = 1, subcount
00215
00216
00217 if (sib(i)%param%zlt == 0.0 .OR. sib(i)%param%aparc == 0.0) then
00218 sib(i)%param%zlt = 0.1
00219 sib(i)%param%vcover = 0.1
00220 sib(i)%param%aparc = 0.1
00221 sib(i)%param%green = 0.1
00222 sib(i)%param%z0d = 0.1
00223 endif
00224
00225 call sib_main( sib(i) )
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 enddo
00242
00243
00244
00245 call respfactor_control( sib, time, rank )
00246
00247
00248 call time_manager( time, drvr_type, roll_respf )
00249 sib(:)%stat%julday = time%doy
00250
00251
00252
00253
00254
00255
00256
00257 call output_control( sib, time, rank )
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 if ( time%write_restart ) then
00278
00279
00280 do i= 1,subcount
00281 phys_loop_d13c : do j=1,5
00282 if ( sib(i)%param%physfrac(j) == 0.0 ) then
00283 sib(i)%param%d13c_auto(j) = 0.0
00284 cycle phys_loop_d13c
00285 else
00286 sib(i)%param%d13c_auto(j) = sib(i)%param%d13c_psn(j) / sib(i)%param%psn_accum(j)
00287 endif
00288 enddo phys_loop_d13c
00289
00290
00291 do j = 1,physmax
00292 sib(i)%param%d13c_psn(j) = 0.0_dbl_kind
00293 sib(i)%param%psn_accum(j) = 0.0_dbl_kind
00294 enddo
00295
00296 enddo
00297 endif
00298
00299
00300
00301
00302 if ( time%write_restart ) then
00303
00304 call rtape_sib( sib, time, rank )
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 endif
00335
00336
00337 del_store=sib(1)%prog%cas-sib(1)%prog%cas_old
00338 sum_flux=sib(1)%diag%resp_grnd*dtt
00339 sum_flux=sum_flux-sib(1)%diag%assimn(6)*dtt
00340 sum_flux=sum_flux-sib(1)%diag%cflux*dtt
00341 residual=del_store-sum_flux-sib(1)%prog%expand
00342
00343 enddo
00344
00345
00346
00347 call file_closer
00348
00349
00350 print*, 'end simulation'
00351 total = etime(elapsed)
00352 print *, 'End: total=', total, ' user=', elapsed(1),' system=', elapsed(2)
00353
00354 end program sibdrive