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 module mct_mod
00031
00032
00033
00034 use shr_kind_mod
00035 use shr_sys_mod
00036 use shr_mpi_mod
00037 use shr_const_mod
00038
00039 use shr_log_mod ,only: s_loglev => shr_log_Level
00040 use shr_log_mod ,only: s_logunit => shr_log_Unit
00041
00042 use m_MCTWorld ,only: mct_world_init => init
00043
00044 use m_AttrVect ,only: mct_aVect => AttrVect
00045 use m_AttrVect ,only: mct_aVect_init => init
00046 use m_AttrVect ,only: mct_aVect_clean => clean
00047 use m_AttrVect ,only: mct_aVect_zero => zero
00048 use m_AttrVect ,only: mct_aVect_lsize => lsize
00049 use m_AttrVect ,only: mct_aVect_indexIA => indexIA
00050 use m_AttrVect ,only: mct_aVect_indexRA => indexRA
00051 use m_AttrVect ,only: mct_aVect_importRattr => importRattr
00052 use m_AttrVect ,only: mct_aVect_exportRattr => exportRattr
00053 use m_AttrVect ,only: mct_aVect_getIList => getIList
00054 use m_AttrVect ,only: mct_aVect_getRList => getRList
00055 use m_AttrVect ,only: mct_aVect_exportIList2c=> exportIListToChar
00056 use m_AttrVect ,only: mct_aVect_exportRList2c=> exportRListToChar
00057 use m_AttrVect ,only: mct_aVect_nIAttr => nIAttr
00058 use m_AttrVect ,only: mct_aVect_nRAttr => nRAttr
00059 use m_AttrVect ,only: mct_aVect_copy => Copy
00060 use m_AttrVect ,only: mct_aVect_permute => Permute
00061 use m_AttrVect ,only: mct_aVect_unpermute => Unpermute
00062 use m_AttrVectComms ,only: mct_aVect_scatter => scatter
00063 use m_AttrVectComms ,only: mct_aVect_gather => gather
00064 use m_AttrVectComms ,only: mct_aVect_bcast => bcast
00065
00066 use m_Accumulator ,only: mct_accum => Accumulator
00067 use m_Accumulator ,only: mct_accum_init => init
00068 use m_Accumulator ,only: mct_accum_zero => zero
00069 use m_Accumulator ,only: mct_accum_accumulate => accumulate
00070
00071
00072 use m_GeneralGrid ,only: mct_gGrid => GeneralGrid
00073 use m_GeneralGrid ,only: mct_gGrid_init => init
00074 use m_GeneralGrid ,only: mct_gGrid_clean => clean
00075 use m_GeneralGrid ,only: mct_gGrid_dims => dims
00076 use m_GeneralGrid ,only: mct_gGrid_lsize => lsize
00077 use m_GeneralGrid ,only: mct_ggrid_indexIA => indexIA
00078 use m_GeneralGrid ,only: mct_gGrid_indexRA => indexRA
00079 use m_GeneralGrid ,only: mct_gGrid_exportRattr => exportRattr
00080 use m_GeneralGrid ,only: mct_gGrid_importRattr => importRattr
00081 use m_GeneralGrid ,only: mct_gGrid_exportIattr => exportIattr
00082 use m_GeneralGrid ,only: mct_gGrid_importIattr => importIattr
00083 use m_GeneralGrid ,only: mct_gGrid_permute => permute
00084 use m_GeneralGridComms ,only: mct_gGrid_scatter => scatter
00085 use m_GeneralGridComms ,only: mct_gGrid_gather => gather
00086 use m_GeneralGridComms ,only: mct_gGrid_bcast => bcast
00087
00088 use m_Transfer ,only: mct_send => Send
00089 use m_Transfer ,only: mct_recv => Recv
00090
00091 use m_GlobalSegMap ,only: mct_gsMap => GlobalSegMap
00092 use m_GlobalSegMap ,only: mct_gsMap_init => init
00093 use m_GlobalSegMap ,only: mct_gsMap_clean => clean
00094 use m_GlobalSegMap ,only: mct_gsMap_lsize => lsize
00095 use m_GlobalSegMap ,only: mct_gsMap_gsize => gsize
00096 use m_GlobalSegMap ,only: mct_gsMap_gstorage => GlobalStorage
00097 use m_GlobalSegMap ,only: mct_gsMap_ngseg => ngseg
00098 use m_GlobalSegMap ,only: mct_gsMap_nlseg => nlseg
00099 use m_GlobalSegMap ,only: mct_gsMap_maxnlseg => max_nlseg
00100 use m_GlobalSegMap ,only: mct_gsMap_activepes => active_pes
00101 use m_GlobalSegMap ,only: mct_gsMap_copy => copy
00102 use m_GlobalSegMap ,only: mct_gsMap_increasing => increasing
00103 use m_GlobalSegMap ,only: mct_gsMap_orderedPoints=> OrderedPoints
00104 use m_GlobalSegMapComms ,only: mct_gsMap_bcast => bcast
00105
00106 use m_Rearranger ,only: mct_rearr => Rearranger
00107 use m_Rearranger ,only: mct_rearr_init => init
00108 use m_Rearranger ,only: mct_rearr_clean => clean
00109 use m_Rearranger ,only: mct_rearr_rearrange => rearrange
00110
00111 use m_Router ,only: mct_router => Router
00112 use m_Router ,only: mct_router_init => init
00113
00114 use m_SparseMatrixToMaps ,only: mct_sMat_2XgsMap => SparseMatrixToXGlobalSegMap
00115 use m_SparseMatrixToMaps ,only: mct_sMat_2YgsMap => SparseMatrixToYGlobalSegMap
00116 use m_SparseMatrix ,only: mct_sMat => SparseMatrix
00117 use m_SparseMatrix ,only: mct_sMat_Init => init
00118 use m_SparseMatrix ,only: mct_sMat_Vecinit => vecinit
00119 use m_SparseMatrix ,only: mct_sMat_Clean => clean
00120 use m_SparseMatrix ,only: mct_sMat_indexIA => indexIA
00121 use m_SparseMatrix ,only: mct_sMat_indexRA => indexRA
00122 use m_SparseMatrix ,only: mct_sMat_lsize => lsize
00123 use m_SparseMatrix ,only: mct_sMat_nrows => nRows
00124 use m_SparseMatrix ,only: mct_sMat_ncols => nCols
00125 use m_SparseMatrix ,only: mct_sMat_SortPermute => SortPermute
00126 use m_SparseMatrix ,only: mct_sMat_GNumEl => GlobalNumElements
00127 use m_SparseMatrix ,only: mct_sMat_ImpGRowI => ImportGlobalRowIndices
00128 use m_SparseMatrix ,only: mct_sMat_ImpGColI => ImportGlobalColumnIndices
00129 use m_SparseMatrix ,only: mct_sMat_ImpLRowI => ImportLocalRowIndices
00130 use m_SparseMatrix ,only: mct_sMat_ImpLColI => ImportLocalColumnIndices
00131 use m_SparseMatrix ,only: mct_sMat_ImpMatrix => ImportMatrixElements
00132 use m_SparseMatrix ,only: mct_sMat_ExpGRowI => ExportGlobalRowIndices
00133 use m_SparseMatrix ,only: mct_sMat_ExpGColI => ExportGlobalColumnIndices
00134 use m_SparseMatrix ,only: mct_sMat_ExpLRowI => ExportLocalRowIndices
00135 use m_SparseMatrix ,only: mct_sMat_ExpLColI => ExportLocalColumnIndices
00136 use m_SparseMatrix ,only: mct_sMat_ExpMatrix => ExportMatrixElements
00137 use m_SparseMatrixComms ,only: mct_sMat_ScatterByRow => ScatterByRow
00138 use m_SparseMatrixComms ,only: mct_sMat_ScatterByCol => ScatterByColumn
00139 use m_SparseMatrixPlus ,only: mct_sMatP => SparseMatrixPlus
00140 use m_SparseMatrixPlus ,only: mct_sMatP_Init => init
00141 use m_SparseMatrixPlus ,only: mct_sMatP_Vecinit => vecinit
00142 use m_SparseMatrixPlus ,only: mct_sMatP_clean => clean
00143 use m_MatAttrVectMul ,only: mct_sMat_avMult => sMatAvMult
00144 use m_GlobalToLocal ,only: mct_sMat_g2lMat => GlobalToLocalMatrix
00145
00146 use m_List ,only: mct_list => list
00147 use m_List ,only: mct_list_init => init
00148 use m_List ,only: mct_list_get => get
00149 use m_List ,only: mct_list_nitem => nitem
00150 use m_List ,only: mct_list_clean => clean
00151 use m_string ,only: mct_string => string
00152 use m_string ,only: mct_string_clean => clean
00153 use m_string ,only: mct_string_toChar => toChar
00154 use m_die ,only: mct_perr_die => mp_perr_die
00155 use m_die ,only: mct_die => die
00156 use m_inpak90
00157
00158
00159 use m_Permuter ,only: mct_permute => Permute
00160
00161 use m_MergeSorts ,only: mct_indexset => IndexSet
00162 use m_MergeSorts ,only: mct_indexsort => IndexSort
00163
00164 implicit none
00165
00166
00167
00168
00169 integer,parameter,private :: R8 = SHR_KIND_R8
00170 integer,parameter,private :: IN = SHR_KIND_IN
00171 integer,parameter,private :: CL = SHR_KIND_CL
00172
00173
00174 contains
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 subroutine mct_aVect_info(flag,aVect,comm,pe,fld,istr)
00205
00206
00207
00208
00209
00210 integer(IN) ,intent(in) :: flag
00211 type(mct_aVect),intent(in) :: aVect
00212 integer(IN) ,intent(in),optional :: comm
00213 integer(IN) ,intent(in),optional :: pe
00214 character(*) ,intent(in),optional :: fld
00215 character(*) ,intent(in),optional :: istr
00216
00217
00218
00219
00220 integer(IN) :: i,j,k,n
00221 integer(IN) :: ks,ke
00222 integer(IN) :: nflds
00223 integer(IN) :: nsize
00224 type(mct_string) :: item
00225 character(CL) :: itemc
00226 integer(IN) :: comm_loc
00227 integer(IN) :: pe_loc
00228 logical :: commOK
00229 logical :: peOK
00230 real(R8),allocatable :: minl(:)
00231 real(R8),allocatable :: ming(:)
00232 real(R8),allocatable :: maxl(:)
00233 real(R8),allocatable :: maxg(:)
00234
00235
00236 character(*),parameter :: subName = '(mct_aVect_info) '
00237 character(*),parameter :: F00 = "('(mct_aVect_info) ',8a)"
00238 character(*),parameter :: F01 = "('(mct_aVect_info) ',a,i9)"
00239 character(*),parameter :: F02 = "('(mct_aVect_info) ',240a)"
00240 character(*),parameter :: F03 = "('(mct_aVect_info) ',a,2es11.3,i4,2x,a)"
00241
00242
00243
00244
00245
00246 commOK = .false.
00247 peOK = .false.
00248
00249 if (present(pe)) then
00250 peOK = .true.
00251 pe_loc = pe
00252 endif
00253 if (present(comm)) then
00254 commOK = .true.
00255 comm_loc = comm
00256 if (.not.PEOK) then
00257 call shr_mpi_commrank(comm,pe_loc,subName)
00258 peOK = .true.
00259 endif
00260 endif
00261
00262 nsize = mct_aVect_lsize(aVect)
00263
00264 if (present(fld)) then
00265 nflds = 1
00266 ks = mct_aVect_indexRA(aVect,fld,perrWith=subName)
00267 ke = ks
00268 else
00269 nflds = mct_aVect_nRAttr(aVect)
00270 ks = 1
00271 ke = nflds
00272 endif
00273
00274 if (flag >= 1) then
00275 if (present(istr)) then
00276 if (s_loglev > 0) write(s_logunit,*) trim(istr)
00277 endif
00278 if (s_loglev > 0) write(s_logunit,F01) "local size =",nsize
00279 if (associated(aVect%iList%bf)) then
00280 if (s_loglev > 0) write(s_logunit,F02) "iList = ",aVect%iList%bf
00281 endif
00282 if (associated(aVect%rList%bf)) then
00283 if (s_loglev > 0) write(s_logunit,F02) "rList = ",aVect%rList%bf
00284 endif
00285 endif
00286
00287 if (flag >= 2) then
00288
00289 allocate(minl(nflds))
00290 allocate(maxl(nflds))
00291
00292 do k=ks,ke
00293 minl(k) = minval(aVect%rAttr(k,:))
00294 maxl(k) = maxval(aVect%rAttr(k,:))
00295 enddo
00296
00297 if (flag >= 4 .and. commOK) then
00298 allocate(ming(nflds))
00299 allocate(maxg(nflds))
00300 ming = 0._R8
00301 maxg = 0._R8
00302 call shr_mpi_min(minl,ming,comm,subName)
00303 call shr_mpi_max(maxl,maxg,comm,subName)
00304 endif
00305
00306 do k=ks,ke
00307 call mct_aVect_getRList(item,k,aVect)
00308 itemc = mct_string_toChar(item)
00309 call mct_string_clean(item)
00310 if (s_loglev > 0) write(s_logunit,F03) 'l min/max ',minl(k),maxl(k),k,trim(itemc)
00311 if (flag >= 3 .and. commOK) then
00312 if ((peOK .and. pe_loc == 0) .or. .not.peOK) then
00313 if (s_loglev > 0) write(s_logunit,F03) 'g min/max ',ming(k),maxg(k),k,trim(itemc)
00314 endif
00315 endif
00316 if (flag >= 4 .and. commOK) then
00317 if ((peOK .and. pe_loc == 0) .or. .not.peOK) then
00318 if (s_loglev > 0) write(s_logunit,*) trim(subName),'g min/max ',ming(k),maxg(k),k,trim(itemc)
00319 endif
00320 endif
00321 enddo
00322
00323 deallocate(minl)
00324 deallocate(maxl)
00325 if (flag >= 4 .and. commOK) then
00326 deallocate(ming)
00327 deallocate(maxg)
00328 endif
00329
00330 endif
00331
00332 call shr_sys_flush(s_logunit)
00333
00334 end subroutine mct_aVect_info
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 subroutine mct_aVect_getRAttr(aVect,str,data,rcode)
00359
00360
00361
00362 type(mct_aVect),intent(in) :: aVect
00363 character(*) ,intent(in) :: str
00364 real(R8) ,intent(out) :: data(:)
00365 integer(IN) ,intent(out) :: rcode
00366
00367
00368
00369
00370 integer(IN) :: k,n,m
00371 integer(IN) :: aVsize
00372
00373
00374 character(*),parameter :: subName = "(mct_aVect_getRAttr) "
00375 character(*),parameter :: F00 = "('(mct_aVect_getRAttr) ',8a)"
00376
00377
00378
00379
00380
00381 rcode = 0
00382
00383 n = mct_aVect_lsize(aVect)
00384 m = size(data)
00385 if (n /= m) then
00386 if (s_loglev > 0) write(s_logunit,*) subName,"ERROR: size aV,data,attr = ",n,m,trim(str)
00387 data = SHR_CONST_SPVAL
00388 rcode = 1
00389 return
00390 end if
00391
00392 k = mct_aVect_indexRA(aVect,trim(str) ,perrWith=subName)
00393 if ( k < 1) then
00394 if (s_loglev > 0) write(s_logunit,*) subName,"ERROR: attribute not found, var = ",trim(str),", k=",k
00395 data = SHR_CONST_SPVAL
00396 rcode = 2
00397 return
00398 end if
00399
00400 data(:) = aVect%rAttr(k,:)
00401
00402 end subroutine mct_aVect_getRAttr
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 subroutine mct_aVect_putRAttr(aVect,str,data,rcode)
00426
00427
00428
00429 type(mct_aVect),intent(out) :: aVect
00430 character(*) ,intent(in) :: str
00431 real(R8) ,intent(in) :: data(:)
00432 integer(IN) ,intent(out) :: rcode
00433
00434
00435
00436
00437 integer(IN) :: k,n,m
00438 integer(IN) :: aVsize
00439
00440
00441 character(*),parameter :: subName = "(mct_aVect_putRAttr) "
00442 character(*),parameter :: F00 = "('(mct_aVect_putRAttr) ',8a)"
00443
00444
00445
00446
00447
00448 rcode = 0
00449
00450 n = mct_aVect_lsize(aVect)
00451 m = size(data)
00452 if (n /= m) then
00453 if (s_loglev > 0) write(s_logunit,*) subName,"ERROR: size aV,data,attr = ",n,m,trim(str)
00454 rcode = 1
00455 return
00456 end if
00457
00458 k = mct_aVect_indexRA(aVect,trim(str) ,perrWith=subName)
00459 if ( k < 1) then
00460 if (s_loglev > 0) write(s_logunit,*) subName,"ERROR: attribute not found, var = ",trim(str),", k=",k
00461 rcode = 2
00462 return
00463 end if
00464
00465 aVect%rAttr(k,:) = data(:)
00466
00467 end subroutine mct_aVect_putRAttr
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495 subroutine mct_aVect_accum(aVin, rList, TrList, iList, TiList, aVout)
00496
00497
00498
00499
00500 use m_die , only : die
00501 use m_stdio , only : stderr
00502 use m_String , only : String_toChar => toChar
00503 use m_String , only : String
00504 use m_String , only : String_init
00505 use m_String , only : String_clean => clean
00506 use m_List , only : List
00507 use m_List, only : List_get => get
00508 use m_List, only : List_nullify => nullify
00509 use m_List, only : List_clean => clean
00510 use m_List, only : init,nitem
00511 use m_AttrVect, only : AttrVect
00512 use m_AttrVect, only : lsize
00513 use m_AttrVect, only : SharedAttrIndexList
00514
00515 implicit none
00516
00517
00518
00519 type(AttrVect) ,intent(in) :: aVin
00520 character(*), optional,intent(in) :: iList
00521 character(*), optional,intent(in) :: rList
00522 character(*), optional,intent(in) :: TiList
00523 character(*), optional,intent(in) :: TrList
00524 type(AttrVect) ,intent(inout) :: aVout
00525
00526
00527
00528
00529 type(List) :: rcpList
00530 type(List) :: icpList
00531 type(List) :: TrcpList
00532 type(List) :: TicpList
00533 type(String) :: attr
00534 type(String) :: attr2
00535 integer(IN) :: i,j
00536 integer(IN) :: rcode
00537 integer(IN) :: inx,outx
00538 integer(IN) :: num_indices
00539
00540
00541 integer(IN), dimension(:), pointer :: aVinindices, aVoutindices
00542
00543 character(7) :: data_flag
00544
00545
00546 character(*),parameter :: myname_='mct_accum'
00547
00548
00549
00550
00551
00552 call List_nullify(rcpList)
00553 call List_nullify(icpList)
00554 call List_nullify(TrcpList)
00555 call List_nullify(TicpList)
00556
00557 if (lsize(aVin) .ne. lsize(aVout)) then
00558 write(stderr,'(2a)')myname_, &
00559 'MCTERROR: Input aV and output aV do not have the same size'
00560 write(stderr,*)myname_, &
00561 'MCTERROR: ',lsize(aVin),lsize(aVout)
00562 call die(myname_,'lsize check',rcode)
00563 endif
00564
00565
00566
00567
00568 if ( present(rList)) then
00569 if( len_trim(rList)>0 ) then
00570
00571 call init(rcpList,rList)
00572
00573
00574 if ( present(TrList) ) then
00575 if(len_trim(TrList)>0 ) then
00576 call init(TrcpList,TrList)
00577 if ( nitem(rcpList) .ne. nitem(TrcpList)) then
00578 write(stderr,'(2a)')myname_, &
00579 'MCTERROR: Input rList and TrList do not have the same size'
00580 call die(myname_,'nitem TrList check',rcode)
00581 endif
00582 endif
00583 endif
00584
00585 if (nitem(rcpList) .ge. 1) then
00586 do i=1,lsize(aVin)
00587 do j=1,nitem(rcpList)
00588 call List_get(attr,j,rcpList)
00589 if (present(TrList)) then
00590 call List_get(attr2,j,TrcpList)
00591 else
00592 call String_init(attr2,attr)
00593 endif
00594 inx=mct_aVect_indexRA(aVin,String_toChar(attr),dieWith=myname_//'real aVin')
00595 outx=mct_aVect_indexRA(aVout,String_toChar(attr2),dieWith=myname_//'real aVout')
00596 aVout%rAttr(outx,i)=aVout%rAttr(outx,i)+aVin%rAttr(inx,i)
00597 call String_clean(attr)
00598 call String_clean(attr2)
00599 enddo
00600 enddo
00601 endif
00602
00603 call List_clean(rcpList)
00604 if (present(TrList)) call List_clean(TrcpList)
00605
00606 endif
00607 endif
00608
00609
00610
00611
00612 if ( present(iList) ) then
00613 if (len_trim(iList)>0 ) then
00614
00615 call init(icpList,iList)
00616
00617
00618 if ( present(TiList) ) then
00619 if (len_trim(TiList)>0 ) then
00620 call init(TicpList,TiList)
00621 if ( nitem(icpList) .ne. nitem(TicpList)) then
00622 write(stderr,'(2a)')myname_, &
00623 'MCTERROR: Input iList and TiList do not have the same size'
00624 call die(myname_,'nitem TiList check',rcode)
00625 endif
00626 endif
00627 endif
00628
00629 if (nitem(icpList) .ge. 1) then
00630 do i=1,lsize(aVin)
00631 do j=1,nitem(icpList)
00632 call List_get(attr,j,icpList)
00633 if (present(TiList)) then
00634 call List_get(attr2,j,TicpList)
00635 else
00636 call String_init(attr2,attr)
00637 endif
00638 inx =mct_aVect_indexIA(aVin ,String_toChar(attr) ,dieWith=myname_//'int aVin')
00639 outx=mct_aVect_indexIA(aVout,String_toChar(attr2),dieWith=myname_//'int aVout')
00640 aVout%iAttr(outx,i)=aVout%iAttr(outx,i)+aVin%iAttr(inx,i)
00641 call String_clean(attr)
00642 call String_clean(attr2)
00643 enddo
00644 enddo
00645 endif
00646
00647 call List_clean(icpList)
00648 if (present(TrList)) call List_clean(TicpList)
00649
00650 endif
00651 endif
00652
00653
00654
00655
00656 if ( .not.present(rList) .and. .not.present(iList)) then
00657
00658 data_flag = 'REAL'
00659 call SharedAttrIndexList(aVin, aVout, data_flag, num_indices, &
00660 aVinindices, aVoutindices)
00661 if (num_indices .gt. 0) then
00662 #ifdef CPP_VECTOR
00663 do j=1,num_indices
00664
00665
00666 do i=1,lsize(aVin)
00667 #else
00668 do i=1,lsize(aVin)
00669 do j=1,num_indices
00670 #endif
00671 aVout%rAttr(aVoutindices(j),i)= &
00672 & aVout%rAttr(aVoutindices(j),i)+aVin%rAttr(aVinindices(j),i)
00673 enddo
00674 enddo
00675 endif
00676 deallocate(aVinindices, aVoutindices,stat=rcode)
00677 if (rcode /= 0) call die(myname_,'deallocate real(Vinindices...',rcode)
00678
00679 data_flag = 'INTEGER'
00680 call SharedAttrIndexList(aVin, aVout, data_flag, num_indices, &
00681 aVinindices, aVoutindices)
00682 if (num_indices .gt. 0) then
00683 #ifdef CPP_VECTOR
00684 do j=1,num_indices
00685
00686
00687 do i=1,lsize(aVin)
00688 #else
00689 do i=1,lsize(aVin)
00690 do j=1,num_indices
00691 #endif
00692 aVout%iAttr(aVoutindices(j),i)= &
00693 & aVout%iAttr(aVoutindices(j),i)+aVin%iAttr(aVinindices(j),i)
00694 enddo
00695 enddo
00696 endif
00697 deallocate(aVinindices, aVoutindices,stat=rcode)
00698 if (rcode /= 0) call die(myname_,'deallocate int(Vinindices...',rcode)
00699
00700 endif
00701
00702 end subroutine mct_aVect_accum
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727 subroutine mct_avect_mult(av,av1,fld1,avlist)
00728
00729
00730
00731
00732
00733 type(mct_aVect) ,intent(inout) :: av
00734 type(mct_aVect) ,intent(in) :: av1
00735 character(*) ,intent(in) :: fld1
00736 character(*),optional,intent(in) :: avlist
00737
00738
00739
00740
00741 integer(IN) :: n,m
00742 integer(IN) :: npts
00743 integer(IN) :: nfld
00744 integer(IN) :: nfldi
00745 integer(IN) :: nptsx
00746 integer(IN) :: nptsi
00747 integer(IN) :: kfld
00748 integer(IN),dimension(:),allocatable :: kfldin
00749 type(mct_list) :: blist
00750 type(mct_string) :: tattr
00751
00752
00753 character(*),parameter :: subName = '(mct_aVect_mult) '
00754
00755
00756
00757
00758
00759 nptsx = mct_aVect_lsize(av1)
00760 npts = mct_aVect_lsize(av)
00761 if (nptsx /= npts .and. s_loglev > 0) write(s_logunit,*) subName,' ERROR: npts error1 ',npts,nptsx
00762
00763 kfld = mct_aVect_indexRA(av1,fld1,perrWith=subName)
00764
00765 if (present(avlist)) then
00766
00767 call mct_list_init(blist,avlist)
00768
00769 nfld=mct_list_nitem(blist)
00770
00771 allocate(kfldin(nfld))
00772 do m=1,nfld
00773 call mct_list_get(tattr,m,blist)
00774 kfldin(m) = mct_aVect_indexRA(av,mct_string_toChar(tattr))
00775 call mct_string_clean(tattr)
00776 enddo
00777 call mct_list_clean(blist)
00778
00779 #ifdef CPP_VECTOR
00780 do m=1,nfld
00781
00782
00783 do n=1,npts
00784 #else
00785 do n=1,npts
00786 do m=1,nfld
00787 #endif
00788 av%rAttr(kfldin(m),n) = av%rAttr(kfldin(m),n)*av1%rAttr(kfld,n)
00789 enddo
00790 enddo
00791
00792 deallocate(kfldin)
00793
00794 else
00795
00796 nfld = mct_aVect_nRAttr(av)
00797
00798 #ifdef CPP_VECTOR
00799 do m=1,nfld
00800
00801
00802 do n=1,npts
00803 #else
00804 do n=1,npts
00805 do m=1,nfld
00806 #endif
00807 av%rAttr(m,n) = av%rAttr(m,n)*av1%rAttr(kfld,n)
00808 enddo
00809 enddo
00810
00811 endif
00812
00813 end subroutine mct_aVect_mult
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838 subroutine mct_avect_vecmult(av,vec,avlist)
00839
00840
00841
00842
00843
00844 type(mct_aVect) ,intent(inout) :: av
00845 real(R8) ,intent(in) :: vec(:)
00846 character(*),optional,intent(in) :: avlist
00847
00848
00849
00850
00851 integer(IN) :: n,m
00852 integer(IN) :: npts
00853 integer(IN) :: nfld
00854 integer(IN) :: nfldi
00855 integer(IN) :: nptsx
00856 integer(IN) :: nptsi
00857 integer(IN),dimension(:),allocatable :: kfldin
00858 type(mct_list) :: blist
00859 type(mct_string) :: tattr
00860
00861
00862 character(*),parameter :: subName = '(mct_aVect_vecmult) '
00863
00864
00865
00866
00867
00868 nptsx = size(vec,1)
00869 npts = mct_aVect_lsize(av)
00870 if (nptsx /= npts .and. s_loglev > 0) write(s_logunit,*) subName,' ERROR: npts error1 ',npts,nptsx
00871
00872
00873 if (present(avlist)) then
00874
00875 call mct_list_init(blist,avlist)
00876
00877 nfld=mct_list_nitem(blist)
00878
00879 allocate(kfldin(nfld))
00880 do m=1,nfld
00881 call mct_list_get(tattr,m,blist)
00882 kfldin(m) = mct_aVect_indexRA(av,mct_string_toChar(tattr))
00883 call mct_string_clean(tattr)
00884 enddo
00885 call mct_list_clean(blist)
00886
00887 #ifdef CPP_VECTOR
00888 do m=1,nfld
00889
00890
00891 do n=1,npts
00892 #else
00893 do n=1,npts
00894 do m=1,nfld
00895 #endif
00896 av%rAttr(kfldin(m),n) = av%rAttr(kfldin(m),n)*vec(n)
00897 enddo
00898 enddo
00899
00900 deallocate(kfldin)
00901
00902 else
00903
00904 nfld = mct_aVect_nRAttr(av)
00905
00906 #ifdef CPP_VECTOR
00907 do m=1,nfld
00908
00909
00910 do n=1,npts
00911 #else
00912 do n=1,npts
00913 do m=1,nfld
00914 #endif
00915 av%rAttr(m,n) = av%rAttr(m,n)*vec(n)
00916 enddo
00917 enddo
00918
00919 endif
00920
00921 end subroutine mct_aVect_vecmult
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937 subroutine mct_aVect_avg(aVect, counter)
00938
00939
00940
00941
00942
00943 type(mct_aVect),intent(inout) :: aVect
00944 integer ,intent(in) :: counter
00945
00946
00947
00948
00949 integer(IN) :: i,j
00950 integer(IN) :: npts
00951 integer(IN) :: nflds
00952 real(R8) :: ravg
00953
00954
00955 character(*),parameter :: subName = '(mct_aVect_avg) '
00956
00957
00958
00959
00960
00961 if (counter == 0) return
00962
00963 ravg = 1.0_R8/real(counter,R8)
00964
00965 nflds = mct_aVect_nRAttr(aVect)
00966 npts = mct_aVect_lsize (aVect)
00967
00968
00969 do i=1,npts
00970 do j=1,nflds
00971 aVect%rattr(j,i) = aVect%rattr(j,i)*ravg
00972 enddo
00973 enddo
00974
00975 end subroutine mct_aVect_avg
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991 subroutine mct_rearr_rearrange_fldlist(avi, avo, Rearr, vector, alltoall, fldlist)
00992
00993
00994
00995
00996
00997 type(mct_aVect) , intent(in) :: avi
00998 type(mct_aVect) , intent(out) :: avo
00999 type(mct_rearr) , intent(in) :: Rearr
01000 logical , intent(in) :: vector
01001 logical , intent(in) :: alltoall
01002 character(len=*), intent(in) :: fldlist
01003
01004
01005
01006 type(mct_aVect) :: avi_fl
01007 type(mct_aVect) :: avo_fl
01008 integer(IN) :: lsize
01009
01010
01011 character(*),parameter :: subName = '(mct_rearr_rearrange_fldlist) '
01012
01013
01014
01015
01016
01017 lsize = mct_aVect_lsize(avi)
01018 call mct_aVect_init (avi_fl, rlist=fldlist, lsize=lsize)
01019 call mct_aVect_zero (avi_fl)
01020
01021 lsize = mct_aVect_lsize(avo)
01022 call mct_aVect_init (avo_fl, rlist=fldlist, lsize=lsize)
01023 call mct_aVect_zero (avo_fl)
01024
01025 call mct_aVect_copy (aVin=avi, aVout=avi_fl)
01026 call mct_rearr_rearrange(avi_fl, avo_fl, Rearr, VECTOR=vector, ALLTOALL=alltoall)
01027 call mct_aVect_copy (aVin=avo_fl, aVout=avo, vector=vector)
01028
01029 call mct_aVect_clean(avi_fl)
01030 call mct_aVect_clean(avo_fl)
01031
01032 end subroutine mct_rearr_rearrange_fldlist
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051 logical function mct_myindex(index,starti,counti)
01052
01053
01054
01055
01056
01057 integer(IN) :: index
01058 integer(IN) :: starti(:)
01059 integer(IN) :: counti(:)
01060
01061
01062
01063
01064 integer(IN) :: nl,nc,nr,ncprev
01065 integer(IN) :: lsize
01066 logical :: stopnow
01067
01068
01069 character(*),parameter :: subName = '(mct_myindex) '
01070
01071
01072
01073
01074
01075 mct_myindex = .false.
01076
01077 lsize = size(starti)
01078 if (lsize < 1) return
01079
01080 nl = 0
01081 nr = lsize + 1
01082 nc = (nl+nr)/2
01083 stopnow = .false.
01084 do while (.not.stopnow)
01085 if (index < starti(nc)) then
01086 nr = nc
01087 elseif (index > (starti(nc) + counti(nc) - 1)) then
01088 nl = nc
01089 else
01090 mct_myindex = .true.
01091 return
01092 endif
01093 ncprev = nc
01094 nc = (nl + nr)/2
01095 if (nc == ncprev .or. nc < 1 .or. nc > lsize) stopnow = .true.
01096 enddo
01097
01098 mct_myindex = .false.
01099 return
01100
01101 end function mct_myindex
01102
01103
01104 end module mct_mod
01105