m_Accumulator.F90 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471
  1. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. ! Math and Computer Science Division, Argonne National Laboratory !
  3. !-----------------------------------------------------------------------
  4. ! CVS m_Accumulator.F90,v 1.37 2008-05-15 13:20:10 larson Exp
  5. ! CVS MCT_2_8_0
  6. !BOP -------------------------------------------------------------------
  7. !
  8. ! !MODULE: m_Accumulator - Time Averaging/Accumlation Buffer
  9. !
  10. ! !DESCRIPTION:
  11. !
  12. ! An {\em accumulator} is a data class used for computing running sums
  13. ! and/or time averages of {\tt AttrVect} class data.
  14. ! The period of time over which data are accumulated/averaged is the
  15. ! {\em accumulation cycle}, which is defined by the total number
  16. ! of accumulation steps (the component {\tt Accumulator\%num\_steps}). When
  17. ! the accumulation routine {\tt accumulate\_} is invoked, the number
  18. ! of accumulation cycle steps (the component
  19. ! {\tt Accumulator\%steps\_done})is incremented, and compared with
  20. ! the number of steps in the accumulation cycle to determine if the
  21. ! accumulation cycle has been completed. The accumulation buffers
  22. ! of the {\tt Accumulator} are stored in an {\tt AttrVect} (namely
  23. ! the component {\tt Accumulator\%data}), which allows the user to
  24. ! define the number of variables and their names at run-time.
  25. ! Finally, one can define for each field
  26. ! being accumulated the specific accumulation {\em action}. Currently,
  27. ! there are two options: Time Averaging and Time Summation. The
  28. ! user chooses the specific action by setting an integer action
  29. ! flag for each attribute being accumulated. The supported options
  30. ! are defined by the public data member constants {\tt MCT\_SUM} and
  31. ! {\tt MCT\_AVG}.
  32. ! \\
  33. ! This module also supports a simple usage of accumulator where all
  34. ! the actions are SUM ({\tt inits\_} and {\tt initavs\_}) and the user
  35. ! must call {\tt average\_} to calculate the average from the current
  36. ! value of {\tt Accumulator\%steps\_done}. {\tt Accumulator\%num\_steps}
  37. ! is ignored in this case.
  38. !
  39. ! !INTERFACE:
  40. module m_Accumulator
  41. !
  42. ! !USES:
  43. !
  44. use m_List, only : List
  45. use m_AttrVect, only : AttrVect
  46. use m_realkinds,only : SP,DP,FP
  47. implicit none
  48. private ! except
  49. ! !PUBLIC TYPES:
  50. public :: Accumulator ! The class data structure
  51. Type Accumulator
  52. #ifdef SEQUENCE
  53. sequence
  54. #endif
  55. integer :: num_steps ! total number of accumulation steps
  56. integer :: steps_done ! number of accumulation steps performed
  57. integer, pointer, dimension(:) :: iAction ! index of integer actions
  58. integer, pointer, dimension(:) :: rAction ! index of real actions
  59. type(AttrVect) :: data ! accumulated sum field storage
  60. End Type Accumulator
  61. ! !PUBLIC MEMBER FUNCTIONS:
  62. !
  63. public :: init ! creation method
  64. public :: initp ! partial creation method (MCT USE ONLY)
  65. public :: clean ! destruction method
  66. public :: initialized ! check if initialized
  67. public :: lsize ! local length of the data arrays
  68. public :: NumSteps ! number of steps in a cycle
  69. public :: StepsDone ! number of steps completed in the
  70. ! current cycle
  71. public :: nIAttr ! number of integer fields
  72. public :: nRAttr ! number of real fields
  73. public :: indexIA ! index the integer fields
  74. public :: indexRA ! index the real fields
  75. public :: getIList ! Return tag from INTEGER
  76. ! attribute list
  77. public :: getRList ! Return tag from REAL attribute
  78. ! list
  79. public :: exportIAttr ! Return INTEGER attribute as a vector
  80. public :: exportRAttr ! Return REAL attribute as a vector
  81. public :: importIAttr ! Insert INTEGER vector as attribute
  82. public :: importRAttr ! Insert REAL vector as attribute
  83. public :: zero ! Clear an accumulator
  84. public :: SharedAttrIndexList ! Returns the number of shared
  85. ! attributes, and lists of the
  86. ! respective locations of these
  87. ! shared attributes
  88. public :: accumulate ! Add AttrVect data into an Accumulator
  89. public :: average ! Calculate an average in an Accumulator
  90. ! Definition of interfaces for the methods for the Accumulator:
  91. interface init ; module procedure &
  92. init_, &
  93. inits_, &
  94. initv_, &
  95. initavs_
  96. end interface
  97. interface initp ; module procedure initp_ ; end interface
  98. interface clean ; module procedure clean_ ; end interface
  99. interface initialized; module procedure initialized_ ; end interface
  100. interface lsize ; module procedure lsize_ ; end interface
  101. interface NumSteps ; module procedure NumSteps_ ; end interface
  102. interface StepsDone ; module procedure StepsDone_ ; end interface
  103. interface nIAttr ; module procedure nIAttr_ ; end interface
  104. interface nRAttr ; module procedure nRAttr_ ; end interface
  105. interface indexIA; module procedure indexIA_; end interface
  106. interface indexRA; module procedure indexRA_; end interface
  107. interface getIList; module procedure getIList_; end interface
  108. interface getRList; module procedure getRList_; end interface
  109. interface exportIAttr ; module procedure exportIAttr_ ; end interface
  110. interface exportRAttr ; module procedure &
  111. exportRAttrSP_, &
  112. exportRAttrDP_
  113. end interface
  114. interface importIAttr ; module procedure importIAttr_ ; end interface
  115. interface importRAttr ; module procedure &
  116. importRAttrSP_, &
  117. importRAttrDP_
  118. end interface
  119. interface zero ; module procedure zero_ ; end interface
  120. interface SharedAttrIndexList ; module procedure &
  121. aCaCSharedAttrIndexList_, &
  122. aVaCSharedAttrIndexList_
  123. end interface
  124. interface accumulate ; module procedure accumulate_ ; end interface
  125. interface average ; module procedure average_ ; end interface
  126. ! !PUBLIC DATA MEMBERS:
  127. !
  128. public :: MCT_SUM
  129. public :: MCT_AVG
  130. integer, parameter :: MCT_SUM = 1
  131. integer, parameter :: MCT_AVG = 2
  132. ! !REVISION HISTORY:
  133. ! 7Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  134. ! 7Feb01 - Jay Larson <larson@mcs.anl.gov> - Public interfaces
  135. ! to getIList() and getRList().
  136. ! 9Aug01 - E.T. Ong <eong@mcs.anl.gov> - added initialized and
  137. ! initp_ routines. Added 'action' in Accumulator type.
  138. ! 6May02 - Jay Larson <larson@mcs.anl.gov> - added import/export
  139. ! routines.
  140. ! 26Aug02 - E.T. Ong <eong@mcs.anl.gov> - thourough code revision;
  141. ! no added routines
  142. ! 10Jan08 - R. Jacob <jacob@mcs.anl.gov> - add simple accumulator
  143. ! use support and check documentation.
  144. !EOP ___________________________________________________________________
  145. character(len=*),parameter :: myname='MCT::m_Accumulator'
  146. contains
  147. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  148. ! Math and Computer Science Division, Argonne National Laboratory !
  149. !BOP -------------------------------------------------------------------
  150. !
  151. ! !IROUTINE: init_ - Initialize an Accumulator and its Registers
  152. !
  153. ! !DESCRIPTION:
  154. ! This routine allocates space for the output {\tt Accumulator} argument
  155. ! {\tt aC}, and at a minimum sets the number of time steps in an
  156. ! accumulation cycle (defined by the input {\tt INTEGER} argument
  157. ! {\tt num\_steps}), and the {\em length} of the {\tt Accumulator}
  158. ! register buffer (defined by the input {\tt INTEGER} argument {\tt
  159. ! lsize}). If one wishes to accumulate integer fields, the list of
  160. ! these fields is defined by the input {\tt CHARACTER} argument
  161. ! {\tt iList}, which is specified as a colon-delimited set of
  162. ! substrings (further information regarding this is available in the
  163. ! routine {\tt init\_()} of the module {\tt m\_AttrVect}). If no
  164. ! value of {\tt iList} is supplied, no integer attribute accumulation
  165. ! buffers will be allocated. The accumulation action on each of the
  166. ! integer attributes can be defined by supplying the input {\tt INTEGER}
  167. ! array argument {\tt iAction(:)} (whose length must correspond to the
  168. ! number of items in {\tt iList}). The values of the elements of
  169. ! {\tt iAction(:)} must be one of the values among the public data
  170. ! members defined in the declaration section of this module. If the
  171. ! integer attributes are to be accumulated (i.e. one supplies {\tt iList}),
  172. ! but {\tt iAction(:)} is not specified, the default action for all
  173. ! integer accumulation operations will be summation. The input arguments
  174. ! {\tt rList} and {\tt rAction(:)} define the names of the real variables
  175. ! to be accumulated and the accumulation action for each. The arguments
  176. ! {\tt rList} and {\tt rAction(:)} are related to each other the same
  177. ! way as {\tt iList} and {\tt iAction(:)}. Finally, the user can
  178. ! manually set the number of completed steps in an accumulation cycle
  179. ! (e.g. for restart purposes) by supplying a value for the optional
  180. ! input {\tt INTEGER} argument {\tt steps\_done}.
  181. !
  182. ! !INTERFACE:
  183. subroutine init_(aC, iList, iAction, rList, rAction, lsize, &
  184. num_steps,steps_done)
  185. !
  186. ! !USES:
  187. !
  188. use m_AttrVect, only : AttrVect_init => init
  189. use m_AttrVect, only : AttrVect_zero => zero
  190. use m_List, only: List
  191. use m_List, only: List_nullify => nullify
  192. use m_List, only: List_init => init
  193. use m_List, only: List_nitem => nitem
  194. use m_List, only: List_clean => clean
  195. use m_stdio
  196. use m_die
  197. implicit none
  198. ! !INPUT PARAMETERS:
  199. !
  200. character(len=*), optional, intent(in) :: iList
  201. integer, dimension(:), optional, intent(in) :: iAction
  202. character(len=*), optional, intent(in) :: rList
  203. integer, dimension(:), optional, intent(in) :: rAction
  204. integer, intent(in) :: lsize
  205. integer, intent(in) :: num_steps
  206. integer, optional, intent(in) :: steps_done
  207. ! !OUTPUT PARAMETERS:
  208. !
  209. type(Accumulator), intent(out) :: aC
  210. ! !REVISION HISTORY:
  211. ! 11Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  212. ! 27JUL01 - E.T. Ong <eong@mcs.anl.gov> - added iAction, rAction,
  213. ! niAction, and nrAction to accumulator type. Also defined
  214. ! MCT_SUM and MCT_AVG for accumulator module.
  215. !EOP ___________________________________________________________________
  216. !
  217. character(len=*),parameter :: myname_=myname//'::init_'
  218. integer :: my_steps_done, nIAttr, nRAttr, ierr
  219. integer, dimension(:), pointer :: my_iAction, my_rAction
  220. logical :: status
  221. type(List) :: temp_iList, temp_rList
  222. nullify(my_iAction)
  223. nullify(my_rAction)
  224. call List_nullify(temp_iList)
  225. call List_nullify(temp_rList)
  226. ! Argument consistency checks:
  227. ! 1) Terminate with error message if optional argument iAction (rAction)
  228. ! is supplied but optional argument iList (rList) is not.
  229. if(present(iAction) .and. (.not. present(iList))) then
  230. write(stderr,'(2a)') myname_,'::FATAL--Argument iAction supplied but action iList absent!'
  231. call die(myname_)
  232. endif
  233. if(present(rAction) .and. (.not. present(rList))) then
  234. write(stderr,'(2a)') myname_,'::FATAL--Argument rAction supplied but action rList absent!'
  235. call die(myname_)
  236. endif
  237. ! 2) For iList and rList, generate temporary List data structures to facilitate
  238. ! attribute counting.
  239. if(present(iList)) then ! create temp_iList
  240. call List_init(temp_iList, iList)
  241. nIAttr = List_nitem(temp_iList)
  242. endif
  243. if(present(rList)) then ! create temp_iList
  244. call List_init(temp_rList, rList)
  245. nRAttr = List_nitem(temp_rList)
  246. endif
  247. ! 3) Terminate with error message if optional arguments iAction (rAction)
  248. ! and iList (rList) are supplied but the size of iAction (rAction) does not
  249. ! match the number of items in iList (rList).
  250. if(present(iAction) .and. present(iList)) then
  251. if(size(iAction) /= nIAttr) then
  252. write(stderr,'(2a,2(a,i8))') myname_, &
  253. '::FATAL--Size mismatch between iAction and iList! ', &
  254. 'size(iAction)=',size(iAction),', ','No. items in iList=',nIAttr
  255. call die(myname_)
  256. endif
  257. endif
  258. if(present(rAction) .and. present(rList)) then
  259. if(size(rAction) /= nRAttr) then
  260. write(stderr,'(2a,2(a,i8))') myname_, &
  261. '::FATAL--Size mismatch between rAction and rList! ', &
  262. 'size(rAction)=',size(rAction),', ','No items in rList=',nRAttr
  263. call die(myname_)
  264. endif
  265. endif
  266. ! Initialize the Accumulator components.
  267. ! steps_done:
  268. if(present(steps_done)) then
  269. my_steps_done = steps_done
  270. else
  271. my_steps_done = 0
  272. endif
  273. ! my_iAction (if iList is present)
  274. if(present(iList)) then ! set up my_iAction
  275. allocate(my_iAction(nIAttr), stat=ierr)
  276. if(ierr /= 0) then
  277. write(stderr,'(2a,i8)') myname_, &
  278. '::FATAL: allocate(my_iAction) failed with ierr=',ierr
  279. call die(myname_)
  280. endif
  281. if(present(iAction)) then ! use its values
  282. my_iAction = iAction
  283. else ! go with default summation by assigning value MCT_SUM
  284. my_iAction = MCT_SUM
  285. endif
  286. endif
  287. ! my_rAction (if rList is present)
  288. if(present(rList)) then ! set up my_rAction
  289. allocate(my_rAction(nRAttr), stat=ierr)
  290. if(ierr /= 0) then
  291. write(stderr,'(2a,i8)') myname_, &
  292. '::FATAL: allocate(my_rAction) failed with ierr=',ierr
  293. call die(myname_)
  294. endif
  295. if(present(rAction)) then ! use its values
  296. my_rAction = rAction
  297. else ! go with default summation by assigning value MCT_SUM
  298. my_rAction = MCT_SUM
  299. endif
  300. endif
  301. ! Build the Accumulator aC minus its data component:
  302. if(present(iList) .and. present(rList)) then ! Both REAL and INTEGER registers
  303. call initp_(aC,my_iAction,my_rAction,num_steps,my_steps_done)
  304. deallocate(my_iAction, my_rAction, stat=ierr)
  305. if(ierr /= 0) then
  306. write(stderr,'(2a,i8)') myname_, &
  307. '::FATAL: deallocate(my_iAction, my_rAction) failed with ierr=',ierr
  308. call die(myname_)
  309. endif
  310. else ! Either only REAL or only INTEGER registers in aC
  311. if(present(iList)) then ! Only INTEGER REGISTERS
  312. call initp_(aC=aC, iAction=my_iAction, num_steps=num_steps, &
  313. steps_done=my_steps_done)
  314. deallocate(my_iAction, stat=ierr)
  315. if(ierr /= 0) then
  316. write(stderr,'(2a,i8)') myname_, &
  317. '::FATAL: deallocate(my_iAction) failed with ierr=',ierr
  318. call die(myname_)
  319. endif
  320. endif
  321. if(present(rList)) then ! Only REAL REGISTERS
  322. call initp_(aC=aC, rAction=my_rAction, num_steps=num_steps, &
  323. steps_done=my_steps_done)
  324. deallocate(my_rAction, stat=ierr)
  325. if(ierr /= 0) then
  326. write(stderr,'(2a,i8)') myname_, &
  327. '::FATAL: deallocate(my_rAction) failed with ierr=',ierr
  328. call die(myname_)
  329. endif
  330. endif
  331. endif
  332. ! Initialize the AttrVect data component for aC:
  333. if(present(iList) .and. present(rList)) then
  334. call AttrVect_init(aC%data,iList,rList,lsize)
  335. else
  336. if(present(iList)) then
  337. call AttrVect_init(aV=aC%data,iList=iList,lsize=lsize)
  338. endif
  339. if(present(rList)) then
  340. call AttrVect_init(aV=aC%data,rList=rList,lsize=lsize)
  341. endif
  342. endif
  343. call AttrVect_zero(aC%data)
  344. ! Clean up
  345. if(present(iList)) call List_clean(temp_iList)
  346. if(present(rList)) call List_clean(temp_rList)
  347. ! Check that aC has been properly initialized
  348. status = initialized_(aC=aC,die_flag=.true.,source_name=myname_)
  349. end subroutine init_
  350. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  351. ! Math and Computer Science Division, Argonne National Laboratory !
  352. !BOP -------------------------------------------------------------------
  353. !
  354. ! !IROUTINE: inits_ - Initialize a simple Accumulator and its Registers
  355. !
  356. ! !DESCRIPTION:
  357. ! This routine allocates space for the output simple {\tt Accumulator} argument
  358. ! {\tt aC}, and sets the {\em length} of the {\tt Accumulator}
  359. ! register buffer (defined by the input {\tt INTEGER} argument {\tt
  360. ! lsize}). If one wishes to accumulate integer fields, the list of
  361. ! these fields is defined by the input {\tt CHARACTER} argument
  362. ! {\tt iList}, which is specified as a colon-delimited set of
  363. ! substrings (further information regarding this is available in the
  364. ! routine {\tt init\_()} of the module {\tt m\_AttrVect}). If no
  365. ! value of {\tt iList} is supplied, no integer attribute accumulation
  366. ! buffers will be allocated. The input argument {\tt rList} define
  367. ! the names of the real variables to be accumulated. Finally, the user can
  368. ! manually set the number of completed steps in an accumulation cycle
  369. ! (e.g. for restart purposes) by supplying a value for the optional
  370. ! input {\tt INTEGER} argument {\tt steps\_done}.
  371. ! Its default value is zero.
  372. !
  373. ! In a simple accumulator, the action is always SUM.
  374. !
  375. !
  376. ! !INTERFACE:
  377. subroutine inits_(aC, iList, rList, lsize,steps_done)
  378. !
  379. ! !USES:
  380. !
  381. use m_List, only : List_init => init
  382. use m_List, only : List_clean => clean
  383. use m_List, only : List_nitem => nitem
  384. use m_AttrVect, only : AttrVect_init => init
  385. use m_AttrVect, only : AttrVect_zero => zero
  386. use m_die
  387. implicit none
  388. ! !INPUT PARAMETERS:
  389. !
  390. character(len=*), optional, intent(in) :: iList
  391. character(len=*), optional, intent(in) :: rList
  392. integer, intent(in) :: lsize
  393. integer, optional, intent(in) :: steps_done
  394. ! !OUTPUT PARAMETERS:
  395. !
  396. type(Accumulator), intent(out) :: aC
  397. ! !REVISION HISTORY:
  398. ! 10Jan08 - R. Jacob <jacob@mcs.anlgov> - initial version based on init_
  399. !
  400. !EOP ___________________________________________________________________
  401. !
  402. character(len=*),parameter :: myname_=myname//'::inits_'
  403. type(List) :: tmplist
  404. integer :: my_steps_done,ier,i,actsize
  405. logical :: status
  406. ! Initialize the Accumulator components.
  407. if(present(steps_done)) then
  408. my_steps_done = steps_done
  409. else
  410. my_steps_done = 0
  411. endif
  412. aC%num_steps = -1 ! special value for simple aC
  413. aC%steps_done = my_steps_done
  414. nullify(aC%iAction,aC%rAction)
  415. if(present(iList)) then
  416. call List_init(tmplist,iList)
  417. actsize=List_nitem(tmplist)
  418. allocate(aC%iAction(actsize),stat=ier)
  419. if(ier /= 0) call die(myname_,"iAction allocate",ier)
  420. do i=1,lsize
  421. aC%iAction=MCT_SUM
  422. enddo
  423. call List_clean(tmplist)
  424. endif
  425. if(present(rList)) then
  426. call List_init(tmplist,rList)
  427. actsize=List_nitem(tmpList)
  428. allocate(aC%rAction(actsize),stat=ier)
  429. if(ier /= 0) call die(myname_,"rAction allocate",ier)
  430. do i=1,lsize
  431. aC%rAction=MCT_SUM
  432. enddo
  433. call List_clean(tmplist)
  434. endif
  435. ! Initialize the AttrVect component aC:
  436. if(present(iList) .and. present(rList)) then
  437. call AttrVect_init(aC%data,iList,rList,lsize)
  438. else
  439. if(present(iList)) then
  440. call AttrVect_init(aV=aC%data,iList=iList,lsize=lsize)
  441. endif
  442. if(present(rList)) then
  443. call AttrVect_init(aV=aC%data,rList=rList,lsize=lsize)
  444. endif
  445. endif
  446. call AttrVect_zero(aC%data)
  447. ! Check that aC has been properly initialized
  448. status = initialized_(aC=aC,die_flag=.true.,source_name=myname_)
  449. end subroutine inits_
  450. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  451. ! Math and Computer Science Division, Argonne National Laboratory !
  452. !BOP -------------------------------------------------------------------
  453. !
  454. ! !IROUTINE: initp_ - Initialize an Accumulator but not its Registers
  455. !
  456. ! !DESCRIPTION:
  457. ! This routine is an internal service routine for use by the other
  458. ! initialization routines in this module. It sets up some---but not
  459. ! all---of the components of the output {\tt Accumulator} argument
  460. ! {\tt aC}. This routine can set up the following components of
  461. ! {\tt aC}:
  462. ! \begin{enumerate}
  463. ! \item {\tt aC\%iAction}, the array of accumlation actions for the
  464. ! integer attributes of {\tt aC} (if the input {\tt INTEGER} array
  465. ! argument {\tt iAction(:)} is supplied);
  466. ! \item {\tt aC\%rAction}, the array of accumlation actions for the
  467. ! real attributes of {\tt aC} (if the input {\tt INTEGER} array
  468. ! argument {\tt rAction(:)} is supplied);
  469. ! \item {\tt aC\%num\_steps}, the number of steps in an accumulation
  470. ! cycle (if the input {\tt INTEGER} argument {\tt num\_steps} is
  471. ! supplied); and
  472. ! \item {\tt aC\%steps\_done}, the number of steps completed so far
  473. ! in an accumulation cycle (if the input {\tt INTEGER} argument
  474. ! {\tt steps\_done} is supplied).
  475. ! \end{enumerate}
  476. !
  477. ! !INTERFACE:
  478. subroutine initp_(aC, iAction, rAction, num_steps, steps_done)
  479. !
  480. ! !USES:
  481. !
  482. use m_die
  483. implicit none
  484. ! !INPUT PARAMETERS:
  485. !
  486. integer, dimension(:), optional, intent(in) :: iAction
  487. integer, dimension(:), optional, intent(in) :: rAction
  488. integer, intent(in) :: num_steps
  489. integer, optional, intent(in) :: steps_done
  490. ! !OUTPUT PARAMETERS:
  491. !
  492. type(Accumulator), intent(out) :: aC
  493. ! !REVISION HISTORY:
  494. ! 11Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  495. ! 27JUL01 - E.T. Ong <eong@mcs.anl.gov> - added iAction, rAction,
  496. ! niAction, and nrAction to accumulator type. Also defined
  497. ! MCT_SUM and MCT_AVG for accumulator module.
  498. !EOP ___________________________________________________________________
  499. !
  500. character(len=*),parameter :: myname_=myname//'::initp_'
  501. integer :: i,ier
  502. integer :: steps_completed
  503. ! if the argument steps_done is not present, assume
  504. ! the accumulator is starting at step zero, that is,
  505. ! set steps_completed to zero
  506. steps_completed = 0
  507. if(present(steps_done)) steps_completed = steps_done
  508. ! Set the stepping info:
  509. aC%num_steps = num_steps
  510. aC%steps_done = steps_completed
  511. ! Assign iAction and niAction components
  512. nullify(aC%iAction,aC%rAction)
  513. if(present(iAction)) then
  514. if(size(iAction)>0) then
  515. allocate(aC%iAction(size(iAction)),stat=ier)
  516. if(ier /= 0) call die(myname_,"iAction allocate",ier)
  517. do i=1,size(iAction)
  518. aC%iAction(i) = iAction(i)
  519. enddo
  520. endif
  521. endif
  522. if(present(rAction)) then
  523. if(size(rAction)>0) then
  524. allocate(aC%rAction(size(rAction)),stat=ier)
  525. if(ier /= 0) call die(myname_,"iAction allocate",ier)
  526. do i=1,size(rAction)
  527. aC%rAction(i) = rAction(i)
  528. enddo
  529. endif
  530. endif
  531. end subroutine initp_
  532. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  533. ! Math and Computer Science Division, Argonne National Laboratory !
  534. !BOP -------------------------------------------------------------------
  535. !
  536. ! !IROUTINE: initv_ - Initialize One Accumulator using Another
  537. !
  538. ! !DESCRIPTION:
  539. ! This routine takes the integer and real attribute information (including
  540. ! accumulation action settings for each attribute) from a previously
  541. ! initialized {\tt Accumulator} (the input argument {\tt bC}), and uses
  542. ! it to create another {\tt Accumulator} (the output argument {\tt aC}).
  543. ! In the absence of the {\tt INTEGER} input arguments {\tt lsize},
  544. ! {\tt num\_steps}, and {\tt steps\_done}, {\tt aC} will inherit from
  545. ! {\tt bC} its length, the number of steps in its accumulation cycle, and
  546. ! the number of steps completed in its present accumulation cycle,
  547. ! respectively.
  548. !
  549. ! !INTERFACE:
  550. subroutine initv_(aC, bC, lsize, num_steps, steps_done)
  551. !
  552. ! !USES:
  553. !
  554. use m_List, only : List
  555. use m_List, only : ListExportToChar => exportToChar
  556. use m_List, only : List_copy => copy
  557. use m_List, only : List_allocated => allocated
  558. use m_List, only : List_clean => clean
  559. use m_die
  560. implicit none
  561. ! !INPUT PARAMETERS:
  562. !
  563. type(Accumulator), intent(in) :: bC
  564. integer, optional, intent(in) :: lsize
  565. integer, optional, intent(in) :: num_steps
  566. integer, optional, intent(in) :: steps_done
  567. ! !OUTPUT PARAMETERS:
  568. !
  569. type(Accumulator), intent(out) :: aC
  570. ! !REVISION HISTORY:
  571. ! 11Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  572. ! 17May01 - R. Jacob <jacob@mcs.anl.gov> - change string_get to
  573. ! list_get
  574. ! 27JUL01 - E.T. Ong <eong@mcs.anl.gov> - added iaction,raction
  575. ! compatibility
  576. ! 2Aug02 - J. Larson <larson@mcs.anl.gov> made argument num_steps
  577. ! optional
  578. !EOP ___________________________________________________________________
  579. character(len=*),parameter :: myname_=myname//'::initv_'
  580. type(List) :: temp_iList, temp_rList
  581. integer :: myNumSteps, myStepsDone
  582. integer :: aC_lsize
  583. integer :: niActions, nrActions
  584. integer, dimension(:), allocatable :: iActionArray, rActionArray
  585. integer :: i,ier
  586. logical :: status
  587. ! Check that bC has been initialized
  588. status = initialized(aC=bC,die_flag=.true.,source_name=myname_)
  589. ! If the argument steps_done is present, set myStepsDone
  590. ! to this value; otherwise, set it to zero
  591. if(present(num_steps)) then ! set it manually
  592. myNumSteps = num_steps
  593. else ! inherit it from bC
  594. myNumSteps = bC%num_steps
  595. endif
  596. ! If the argument steps_done is present, set myStepsDone
  597. ! to this value; otherwise, set it to zero
  598. if(present(steps_done)) then ! set it manually
  599. myStepsDone= steps_done
  600. else ! inherit it from bC
  601. myStepsDone = bC%steps_done
  602. endif
  603. ! If the argument lsize is present,
  604. ! set aC_lsize to this value; otherwise, set it to the lsize of bC
  605. if(present(lsize)) then ! set it manually
  606. aC_lsize = lsize
  607. else ! inherit it from bC
  608. aC_lsize = lsize_(bC)
  609. endif
  610. ! Convert the two Lists to two Strings
  611. niActions = 0
  612. nrActions = 0
  613. if(List_allocated(bC%data%iList)) then
  614. call List_copy(temp_iList,bC%data%iList)
  615. niActions = nIAttr_(bC)
  616. endif
  617. if(List_allocated(bC%data%rList)) then
  618. call List_copy(temp_rList,bC%data%rList)
  619. nrActions = nRAttr_(bC)
  620. endif
  621. ! Convert the pointers to arrays
  622. allocate(iActionArray(niActions),rActionArray(nrActions),stat=ier)
  623. if(ier /= 0) call die(myname_,"iActionArray/rActionArray allocate",ier)
  624. if( niActions>0 ) then
  625. do i=1,niActions
  626. iActionArray(i)=bC%iAction(i)
  627. enddo
  628. endif
  629. if( nrActions>0 ) then
  630. do i=1,nrActions
  631. rActionArray(i)=bC%rAction(i)
  632. enddo
  633. endif
  634. ! Call init with present arguments
  635. if( (niActions>0) .and. (nrActions>0) ) then
  636. call init_(aC, iList=ListExportToChar(temp_iList), &
  637. iAction=iActionArray, &
  638. rList=ListExportToChar(temp_rList), &
  639. rAction=rActionArray, &
  640. lsize=aC_lsize, &
  641. num_steps=myNumSteps, &
  642. steps_done=myStepsDone)
  643. else
  644. if( niActions>0 ) then
  645. call init_(aC, iList=ListExportToChar(temp_iList), &
  646. iAction=iActionArray, &
  647. lsize=aC_lsize, &
  648. num_steps=myNumSteps, &
  649. steps_done=myStepsDone)
  650. endif
  651. if( nrActions>0 ) then
  652. call init_(aC, rList=ListExportToChar(temp_rList), &
  653. rAction=rActionArray, &
  654. lsize=aC_lsize, &
  655. num_steps=myNumSteps, &
  656. steps_done=myStepsDone)
  657. endif
  658. endif
  659. if(List_allocated(bC%data%iList)) call List_clean(temp_iList)
  660. if(List_allocated(bC%data%rList)) call List_clean(temp_rList)
  661. deallocate(iActionArray,rActionArray,stat=ier)
  662. if(ier /= 0) call die(myname_,"iActionArray/rActionArray deallocate",ier)
  663. ! Check that aC as been properly initialized
  664. status = initialized(aC=aC,die_flag=.true.,source_name=myname_)
  665. end subroutine initv_
  666. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  667. ! Math and Computer Science Division, Argonne National Laboratory !
  668. !BOP -------------------------------------------------------------------
  669. !
  670. ! !IROUTINE: initavs_ - Initialize a simple Accumulator from an AttributeVector
  671. !
  672. ! !DESCRIPTION:
  673. ! This routine takes the integer and real attribute information (including
  674. ! from a previously initialized {\tt AttributeVector} (the input argument {\tt aV}), and uses
  675. ! it to create a simple (sum only) {\tt Accumulator} (the output argument {\tt aC}).
  676. ! In the absence of the {\tt INTEGER} input argument {\tt lsize},
  677. ! {\tt aC} will inherit from {\tt Av} its length. In the absence of the
  678. ! optional INTEGER argument, {\tt steps\_done} will be set to zero.
  679. !
  680. ! !INTERFACE:
  681. subroutine initavs_(aC, aV, acsize, steps_done)
  682. !
  683. ! !USES:
  684. !
  685. use m_AttrVect, only: AttrVect_lsize => lsize
  686. use m_AttrVect, only: AttrVect_nIAttr => nIAttr
  687. use m_AttrVect, only: AttrVect_nRAttr => nRAttr
  688. use m_AttrVect, only: AttrVect_exIL2c => exportIListToChar
  689. use m_AttrVect, only: AttrVect_exRL2c => exportRListToChar
  690. use m_die
  691. implicit none
  692. ! !INPUT PARAMETERS:
  693. !
  694. type(AttrVect), intent(in) :: aV
  695. integer, optional, intent(in) :: acsize
  696. integer, optional, intent(in) :: steps_done
  697. ! !OUTPUT PARAMETERS:
  698. !
  699. type(Accumulator), intent(out) :: aC
  700. ! !REVISION HISTORY:
  701. ! 10Jan08 - R. Jacob <jacob@mcs.anl.gov> - initial version based on initv_
  702. !EOP ___________________________________________________________________
  703. character(len=*),parameter :: myname_=myname//'::initavs_'
  704. integer :: myNumSteps, myStepsDone
  705. integer :: aC_lsize
  706. integer :: i,ier
  707. integer :: nIatt,nRatt
  708. logical :: status
  709. ! If the argument steps_done is present, set myStepsDone
  710. ! to this value; otherwise, set it to zero
  711. if(present(steps_done)) then ! set it manually
  712. myStepsDone= steps_done
  713. else ! set it to zero
  714. myStepsDone = 0
  715. endif
  716. ! If the argument acsize is present,
  717. ! set aC_lsize to this value; otherwise, set it to the lsize of bC
  718. if(present(acsize)) then ! set it manually
  719. aC_lsize = acsize
  720. else ! inherit it from bC
  721. aC_lsize = AttrVect_lsize(aV)
  722. endif
  723. nIatt=AttrVect_nIAttr(aV)
  724. nRatt=AttrVect_nRAttr(aV)
  725. if((nIAtt>0) .and. (nRatt>0)) then
  726. call inits_(aC,AttrVect_exIL2c(aV),AttrVect_exRL2c(aV), &
  727. aC_lsize,myStepsDone)
  728. else
  729. if(nIatt>0) then
  730. call inits_(aC,iList=AttrVect_exIL2c(aV),lsize=aC_lsize, &
  731. steps_done=myStepsDone)
  732. endif
  733. if(nRatt>0) then
  734. call inits_(aC,rList=AttrVect_exRL2c(aV),lsize=aC_lsize, &
  735. steps_done=myStepsDone)
  736. endif
  737. endif
  738. ! Check that aC as been properly initialized
  739. status = initialized(aC=aC,die_flag=.true.,source_name=myname_)
  740. end subroutine initavs_
  741. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  742. ! Math and Computer Science Division, Argonne National Laboratory !
  743. !BOP -------------------------------------------------------------------
  744. !
  745. ! !IROUTINE: clean_ - Destroy an Accumulator
  746. !
  747. ! !DESCRIPTION:
  748. ! This routine deallocates all allocated memory structures associated
  749. ! with the input/output {\tt Accumulator} argument {\tt aC}. The
  750. ! success (failure) of this operation is signified by the zero (non-zero)
  751. ! value of the optional {\tt INTEGER} output argument {\tt stat}. If
  752. ! {\tt clean\_()} is invoked with {\tt stat} present, it is the user's
  753. ! obligation to check this return code and act accordingly. If {\tt stat}
  754. ! is not supplied and any of the deallocation operations fail, this
  755. ! routine will terminate execution with an error statement.
  756. !
  757. ! !INTERFACE:
  758. subroutine clean_(aC, stat)
  759. !
  760. ! !USES:
  761. !
  762. use m_mall
  763. use m_stdio
  764. use m_die
  765. use m_AttrVect, only : AttrVect_clean => clean
  766. implicit none
  767. ! !INPUT/OUTPUT PARAMETERS:
  768. !
  769. type(Accumulator), intent(inout) :: aC
  770. ! !OUTPUT PARAMETERS:
  771. !
  772. integer, optional, intent(out) :: stat
  773. ! !REVISION HISTORY:
  774. ! 11Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  775. ! 27JUL01 - E.T. Ong <eong@mcs.anl.gov> - deallocate pointers iAction
  776. ! and rAction.
  777. ! 1Mar02 - E.T. Ong <eong@mcs.anl.gov> removed the die to prevent
  778. ! crashes and added stat argument.
  779. !EOP ___________________________________________________________________
  780. character(len=*),parameter :: myname_=myname//'::clean_'
  781. integer :: ier
  782. if(present(stat)) then
  783. stat=0
  784. call AttrVect_clean(aC%data,stat)
  785. else
  786. call AttrVect_clean(aC%data)
  787. endif
  788. if( associated(aC%iAction) ) then
  789. deallocate(aC%iAction,stat=ier)
  790. if(ier /= 0) then
  791. if(present(stat)) then
  792. stat=ier
  793. else
  794. call warn(myname_,'deallocate(aC%iAction)',ier)
  795. endif
  796. endif
  797. endif
  798. if( associated(aC%rAction) ) then
  799. deallocate(aC%rAction,stat=ier)
  800. if(ier /= 0) then
  801. if(present(stat)) then
  802. stat=ier
  803. else
  804. call warn(myname_,'deallocate(aC%rAction)',ier)
  805. endif
  806. endif
  807. endif
  808. end subroutine clean_
  809. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  810. ! Math and Computer Science Division, Argonne National Laboratory !
  811. !BOP -------------------------------------------------------------------
  812. !
  813. ! !IROUTINE: initialized_ - Check if an Accumulator is Initialized
  814. !
  815. ! !DESCRIPTION:
  816. ! This logical function returns a value of {\tt .TRUE.} if the input
  817. ! {\tt Accumulator} argument {\tt aC} is initialized correctly. The
  818. ! term "correctly initialized" means there is internal consistency
  819. ! between the number of integer and real attributes in {\tt aC}, and
  820. ! their respective data structures for accumulation registers, and
  821. ! accumulation action flags. The optional {\tt LOGICAL} input argument
  822. ! {\tt die\_flag} if present, can result in messages written to
  823. ! {\tt stderr}:
  824. ! \begin {itemize}
  825. ! \item if {\tt die\_flag} is true and {\tt aC} is correctly initialized,
  826. ! and
  827. ! \item if {\tt die\_flag} is false and {\tt aC} is incorrectly
  828. ! initialized.
  829. ! \end{itemize}
  830. ! Otherwise, inconsistencies in how {\tt aC} is set up will result in
  831. ! termination with an error message.
  832. ! The optional {\tt CHARACTER} input argument {\tt source\_name} allows
  833. ! the user to, in the event of error, generate traceback information
  834. ! (e.g., the name of the routine that invoked this one).
  835. !
  836. ! !INTERFACE:
  837. logical function initialized_(aC, die_flag, source_name)
  838. !
  839. ! !USES:
  840. !
  841. use m_stdio
  842. use m_die
  843. use m_List, only : List
  844. use m_List, only : List_allocated => allocated
  845. use m_AttrVect, only : AttrVect
  846. use m_AttrVect, only : Attr_nIAttr => nIAttr
  847. use m_AttrVect, only : Attr_nRAttr => nRAttr
  848. implicit none
  849. ! !INPUT PARAMETERS:
  850. !
  851. type(Accumulator), intent(in) :: aC
  852. logical, optional, intent(in) :: die_flag
  853. character(len=*), optional, intent(in) :: source_name
  854. ! !REVISION HISTORY:
  855. ! 7AUG01 - E.T. Ong <eong@mcs.anl.gov> - initital prototype
  856. !
  857. !EOP ___________________________________________________________________
  858. character(len=*),parameter :: myname_=myname//'::initialized_'
  859. integer :: i
  860. logical :: kill
  861. logical :: aC_associated
  862. if(present(die_flag)) then
  863. kill = .true.
  864. else
  865. kill = .false.
  866. endif
  867. ! Initial value
  868. initialized_ = .true.
  869. aC_associated = .true.
  870. ! Check the association status of pointers in aC
  871. if( associated(aC%iAction) .or. associated(aC%rAction) ) then
  872. aC_associated = .true.
  873. else
  874. initialized_ = .false.
  875. aC_associated = .false.
  876. if(kill) then
  877. if(present(source_name)) write(stderr,*) source_name, myname_, &
  878. ":: ERROR, Neither aC%iAction nor aC%rAction are associated"
  879. call die(myname_,"Neither aC%iAction nor aC%rAction are associated")
  880. endif
  881. endif
  882. if( List_allocated(aC%data%iList) .or. List_allocated(aC%data%rList) ) then
  883. aC_associated = .true.
  884. else
  885. initialized_ = .false.
  886. aC_associated = .false.
  887. if(kill) then
  888. if(present(source_name)) write(stderr,*) source_name, myname_, &
  889. ":: ERROR, Neither aC%data%iList nor aC%data%rList are allocated"
  890. call die(myname_,"Neither aC%data%iList nor aC%data%rList are allocated")
  891. endif
  892. endif
  893. ! Make sure iAction and rAction sizes are greater than zero
  894. if(associated(aC%iAction)) then
  895. if(size(aC%iAction)<=0) then
  896. initialized_ = .false.
  897. aC_associated = .false.
  898. if(kill) then
  899. if(present(source_name)) write(stderr,*) source_name, myname_, &
  900. ":: ERROR, size(aC%iAction<=0), size = ", size(aC%iAction)
  901. call die(myname_,"size(aC%iAction<=0), size = ", size(aC%iAction))
  902. endif
  903. endif
  904. endif
  905. if(associated(aC%rAction)) then
  906. if(size(aC%rAction)<=0) then
  907. initialized_ = .false.
  908. aC_associated = .false.
  909. if(kill) then
  910. if(present(source_name)) write(stderr,*) source_name, myname_, &
  911. ":: ERROR, size(aC%rAction<=0), size = ", size(aC%rAction)
  912. call die(myname_,"size(aC%rAction<=0), size = ", size(aC%rAction))
  913. endif
  914. endif
  915. endif
  916. ! More sanity checking...
  917. if( aC_associated ) then
  918. if( (Attr_nIAttr(aC%data) == 0) .and. (Attr_nRAttr(aC%data) == 0) ) then
  919. initialized_ = .false.
  920. if(kill) then
  921. if(present(source_name)) write(stderr,*) source_name, myname_, &
  922. ":: ERROR, No attributes found in aC%data"
  923. call die(myname_,"No attributes found in aC%data")
  924. endif
  925. endif
  926. if(Attr_nIAttr(aC%data) > 0) then
  927. if( size(aC%iAction) /= Attr_nIAttr(aC%data) ) then
  928. initialized_ = .false.
  929. if(kill) then
  930. if(present(source_name)) write(stderr,*) source_name, myname_, &
  931. ":: ERROR, size(aC%iAction) /= nIAttr(aC%data)"
  932. call die(myname_,"size(aC%iAction) /= nIAttr(aC%data)")
  933. endif
  934. endif
  935. do i=1,Attr_nIAttr(aC%data)
  936. if( (aC%iAction(i) /= MCT_SUM) .and. &
  937. (aC%iAction(i) /= MCT_AVG) ) then
  938. initialized_ = .false.
  939. if(kill) then
  940. if(present(source_name)) write(stderr,*) source_name, &
  941. myname_, ":: ERROR, Invalid value found in aC%iAction"
  942. call die(myname_,"Invalid value found in aC%iAction", &
  943. aC%iAction(i))
  944. endif
  945. endif
  946. enddo
  947. endif ! if(Attr_nIAttr(aC%data) > 0)
  948. if(Attr_nRAttr(aC%data) > 0) then
  949. if( size(aC%rAction) /= Attr_nRAttr(aC%data) ) then
  950. initialized_ = .false.
  951. if(kill) then
  952. if(present(source_name)) write(stderr,*) source_name, &
  953. myname_, ":: ERROR, size(aC%rAction) /= nRAttr(aC%data)"
  954. call die(myname_,"size(aC%rAction) /= nRAttr(aC%data)")
  955. endif
  956. endif
  957. do i=1,Attr_nRAttr(aC%data)
  958. if( (aC%rAction(i) /= MCT_SUM) .and. &
  959. (aC%rAction(i) /= MCT_AVG) ) then
  960. initialized_ = .false.
  961. if(kill) then
  962. if(present(source_name)) write(stderr,*) source_name, &
  963. myname_, ":: ERROR, Invalid value found in aC%rAction", &
  964. aC%rAction(i)
  965. call die(myname_,"Invalid value found in aC%rAction", &
  966. aC%iAction(i))
  967. endif
  968. endif
  969. enddo
  970. endif ! if(Attr_nRAttr(aC%data) > 0)
  971. endif ! if (aC_associated)
  972. end function initialized_
  973. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  974. ! Math and Computer Science Division, Argonne National Laboratory !
  975. !BOP -------------------------------------------------------------------
  976. !
  977. ! !IROUTINE: lsize_ - Length of an Accumulator
  978. !
  979. ! !DESCRIPTION:
  980. ! This {\tt INTEGER} query function returns the number of data points
  981. ! for which the input {\tt Accumulator} argument {\tt aC} is performing
  982. ! accumulation. This value corresponds to the length of the {\tt AttrVect}
  983. ! component {\tt aC\%data} that stores the accumulation registers.
  984. !
  985. ! !INTERFACE:
  986. integer function lsize_(aC)
  987. !
  988. ! !USES:
  989. !
  990. use m_AttrVect, only : AttrVect_lsize => lsize
  991. implicit none
  992. ! !INPUT PARAMETERS:
  993. !
  994. type(Accumulator), intent(in) :: aC
  995. ! !REVISION HISTORY:
  996. ! 12Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  997. !EOP ___________________________________________________________________
  998. character(len=*),parameter :: myname_=myname//'::lsize_'
  999. ! The function AttrVect_lsize is called to return
  1000. ! its local size data
  1001. lsize_=AttrVect_lsize(aC%data)
  1002. end function lsize_
  1003. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1004. ! Math and Computer Science Division, Argonne National Laboratory !
  1005. !BOP -------------------------------------------------------------------
  1006. !
  1007. ! !IROUTINE: NumSteps_ - Number of Accumulation Cycle Time Steps
  1008. !
  1009. ! !DESCRIPTION:
  1010. ! This {\tt INTEGER} query function returns the number of time steps in an
  1011. ! accumulation cycle for the input {\tt Accumulator} argument {\tt aC}.
  1012. !
  1013. ! !INTERFACE:
  1014. integer function NumSteps_(aC)
  1015. !
  1016. ! !USES:
  1017. !
  1018. use m_die, only : die
  1019. use m_stdio, only : stderr
  1020. implicit none
  1021. ! !INPUT PARAMETERS:
  1022. !
  1023. type(Accumulator), intent(in) :: aC
  1024. ! !REVISION HISTORY:
  1025. ! 7Aug02 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  1026. !EOP ___________________________________________________________________
  1027. character(len=*),parameter :: myname_=myname//'::NumSteps_'
  1028. integer :: myNumSteps
  1029. ! Retrieve the number of cycle steps from aC:
  1030. myNumSteps = aC%num_steps
  1031. if(myNumSteps <= 0) then
  1032. write(stderr,'(2a,i8)') myname_, &
  1033. ':: FATAL--illegal number of steps in an accumulation cycle = ',&
  1034. myNumSteps
  1035. call die(myname_)
  1036. endif
  1037. NumSteps_ = myNumSteps
  1038. end function NumSteps_
  1039. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1040. ! Math and Computer Science Division, Argonne National Laboratory !
  1041. !BOP -------------------------------------------------------------------
  1042. !
  1043. ! !IROUTINE: StepsDone_ - Number of Completed Steps in the Current Cycle
  1044. !
  1045. ! !DESCRIPTION:
  1046. ! This {\tt INTEGER} query function returns the of time steps that have
  1047. ! been completed in the current accumulation cycle for the input
  1048. ! {\tt Accumulator} argument {\tt aC}.
  1049. !
  1050. ! !INTERFACE:
  1051. integer function StepsDone_(aC)
  1052. !
  1053. ! !USES:
  1054. !
  1055. use m_die, only : die
  1056. use m_stdio, only : stderr
  1057. implicit none
  1058. ! !INPUT PARAMETERS:
  1059. !
  1060. type(Accumulator), intent(in) :: aC
  1061. ! !REVISION HISTORY:
  1062. ! 7Aug02 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  1063. !EOP ___________________________________________________________________
  1064. character(len=*),parameter :: myname_=myname//'::StepsDone_'
  1065. integer :: myStepsDone
  1066. ! Retrieve the number of completed steps from aC:
  1067. myStepsDone = aC%steps_done
  1068. if(myStepsDone < 0) then
  1069. write(stderr,'(2a,i8)') myname_, &
  1070. ':: FATAL--illegal number of completed steps = ',&
  1071. myStepsDone
  1072. call die(myname_)
  1073. endif
  1074. StepsDone_ = myStepsDone
  1075. end function StepsDone_
  1076. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1077. ! Math and Computer Science Division, Argonne National Laboratory !
  1078. !BOP -------------------------------------------------------------------
  1079. !
  1080. ! !IROUTINE: nIAttr_ - Return the Number of INTEGER Attributes
  1081. !
  1082. ! !DESCRIPTION:
  1083. ! This {\tt INTEGER} query function returns the number of integer
  1084. ! attributes that are stored in the input {\tt Accumulator} argument
  1085. ! {\tt aC}. This value is equal to the number of integer attributes
  1086. ! in the {\tt AttrVect} component {\tt aC\%data} that stores the
  1087. ! accumulation registers.
  1088. !
  1089. ! !INTERFACE:
  1090. integer function nIAttr_(aC)
  1091. !
  1092. ! !USES:
  1093. !
  1094. use m_AttrVect, only : AttrVect_nIAttr => nIAttr
  1095. implicit none
  1096. ! !INPUT PARAMETERS:
  1097. !
  1098. type(Accumulator),intent(in) :: aC
  1099. ! !REVISION HISTORY:
  1100. ! 12Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  1101. !EOP ___________________________________________________________________
  1102. character(len=*),parameter :: myname_=myname//'::nIAttr_'
  1103. ! The function AttrVect_nIAttr is called to return the
  1104. ! number of integer fields
  1105. nIAttr_=AttrVect_nIAttr(aC%data)
  1106. end function nIAttr_
  1107. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1108. ! Math and Computer Science Division, Argonne National Laboratory !
  1109. !BOP -------------------------------------------------------------------
  1110. !
  1111. ! !IROUTINE: nRAttr_ - number of REAL fields stored in the Accumulator.
  1112. !
  1113. ! !DESCRIPTION:
  1114. ! This {\tt INTEGER} query function returns the number of real
  1115. ! attributes that are stored in the input {\tt Accumulator} argument
  1116. ! {\tt aC}. This value is equal to the number of real attributes
  1117. ! in the {\tt AttrVect} component {\tt aC\%data} that stores the
  1118. ! accumulation registers.
  1119. !
  1120. ! !INTERFACE:
  1121. integer function nRAttr_(aC)
  1122. !
  1123. ! !USES:
  1124. !
  1125. use m_AttrVect, only : AttrVect_nRAttr => nRAttr
  1126. implicit none
  1127. ! !INPUT PARAMETERS:
  1128. !
  1129. type(Accumulator),intent(in) :: aC
  1130. ! !REVISION HISTORY:
  1131. ! 12Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  1132. !EOP ___________________________________________________________________
  1133. character(len=*),parameter :: myname_=myname//'::nRAttr_'
  1134. ! The function AttrVect_nRAttr is called to return the
  1135. ! number of real fields
  1136. nRAttr_=AttrVect_nRAttr(aC%data)
  1137. end function nRAttr_
  1138. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1139. ! Math and Computer Science Division, Argonne National Laboratory !
  1140. !BOP -------------------------------------------------------------------
  1141. !
  1142. ! !IROUTINE: getIList_ - Retrieve a Numbered INTEGER Attribute Name
  1143. !
  1144. ! !DESCRIPTION:
  1145. ! This routine returns as a {\tt String} (see the mpeu module
  1146. ! {\tt m\_String} for information) the name of the {\tt ith} item in
  1147. ! the integer registers of the {\tt Accumulator} argument {\tt aC}.
  1148. !
  1149. ! !INTERFACE:
  1150. subroutine getIList_(item, ith, aC)
  1151. !
  1152. ! !USES:
  1153. !
  1154. use m_AttrVect, only : AttrVect_getIList => getIList
  1155. use m_String, only : String
  1156. implicit none
  1157. ! !INPUT PARAMETERS:
  1158. !
  1159. integer, intent(in) :: ith
  1160. type(Accumulator), intent(in) :: aC
  1161. ! !OUTPUT PARAMETERS:
  1162. !
  1163. type(String), intent(out) :: item
  1164. ! !REVISION HISTORY:
  1165. ! 12Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  1166. !EOP ___________________________________________________________________
  1167. character(len=*),parameter :: myname_=myname//'::getIList_'
  1168. call AttrVect_getIList(item,ith,aC%data)
  1169. end subroutine getIList_
  1170. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1171. ! Math and Computer Science Division, Argonne National Laboratory !
  1172. !BOP -------------------------------------------------------------------
  1173. !
  1174. ! !IROUTINE: getRList_ - Retrieve a Numbered REAL Attribute Name
  1175. !
  1176. ! !DESCRIPTION:
  1177. ! This routine returns as a {\tt String} (see the mpeu module
  1178. ! {\tt m\_String} for information) the name of the {\tt ith} item in
  1179. ! the real registers of the {\tt Accumulator} argument {\tt aC}.
  1180. !
  1181. ! !INTERFACE:
  1182. subroutine getRList_(item, ith, aC)
  1183. !
  1184. ! !USES:
  1185. !
  1186. use m_AttrVect, only : AttrVect_getRList => getRList
  1187. use m_String, only : String
  1188. implicit none
  1189. ! !INPUT PARAMETERS:
  1190. !
  1191. integer, intent(in) :: ith
  1192. type(Accumulator),intent(in) :: aC
  1193. ! !OUTPUT PARAMETERS:
  1194. !
  1195. type(String), intent(out) :: item
  1196. ! !REVISION HISTORY:
  1197. ! 12Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  1198. !EOP ___________________________________________________________________
  1199. character(len=*),parameter :: myname_=myname//'::getRList_'
  1200. call AttrVect_getRList(item,ith,aC%data)
  1201. end subroutine getRList_
  1202. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1203. ! Math and Computer Science Division, Argonne National Laboratory !
  1204. !BOP -------------------------------------------------------------------
  1205. !
  1206. ! !IROUTINE: indexIA_ - Index an INTEGER Attribute
  1207. !
  1208. ! !DESCRIPTION:
  1209. ! This {\tt INTEGER} query function returns the index in the integer
  1210. ! accumulation register buffer of the {\tt Accumulator} argument {\tt aC}
  1211. ! the attribute named by the {\tt CHARACTER} argument {\tt item}. That
  1212. ! is, all the accumulator running tallies for the attribute named
  1213. ! {\tt item} reside in
  1214. !\begin{verbatim}
  1215. ! aC%data%iAttr(indexIA_(aC,item),:).
  1216. !\end{verbatim}
  1217. ! The user may request traceback information (e.g., the name of the
  1218. ! routine from which this one is called) by providing values for either
  1219. ! of the optional {\tt CHARACTER} arguments {\tt perrWith} or {\tt dieWith}
  1220. ! In the event {\tt indexIA\_()} can not find {\tt item} in {\tt aC},
  1221. ! the routine behaves as follows:
  1222. ! \begin{enumerate}
  1223. ! \item if neither {\tt perrWith} nor {\tt dieWith} are present,
  1224. ! {\tt indexIA\_()} returns a value of zero;
  1225. ! \item if {\tt perrWith} is present, but {\tt dieWith} is not, an error
  1226. ! message is written to {\tt stderr} incorporating user-supplied traceback
  1227. ! information stored in the argument {\tt perrWith};
  1228. ! \item if {\tt dieWith} is present, execution terminates with an error
  1229. ! message written to {\tt stderr} that incorporates user-supplied traceback
  1230. ! information stored in the argument {\tt dieWith}.
  1231. ! \end{enumerate}
  1232. ! !INTERFACE:
  1233. integer function indexIA_(aC, item, perrWith, dieWith)
  1234. !
  1235. ! !USES:
  1236. !
  1237. use m_AttrVect, only : AttrVect_indexIA => indexIA
  1238. use m_die, only : die
  1239. use m_stdio,only : stderr
  1240. implicit none
  1241. ! !INPUT PARAMETERS:
  1242. !
  1243. type(Accumulator), intent(in) :: aC
  1244. character(len=*), intent(in) :: item
  1245. character(len=*), optional, intent(in) :: perrWith
  1246. character(len=*), optional, intent(in) :: dieWith
  1247. ! !REVISION HISTORY:
  1248. ! 14Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  1249. !EOP ___________________________________________________________________
  1250. character(len=*),parameter :: myname_=myname//'::indexIA_'
  1251. indexIA_=AttrVect_indexIA(aC%data,item)
  1252. if(indexIA_==0) then
  1253. if(.not.present(dieWith)) then
  1254. if(present(perrWith)) write(stderr,'(4a)') perrWith, &
  1255. '" indexIA_() error, not found "',trim(item),'"'
  1256. else
  1257. write(stderr,'(4a)') dieWith, &
  1258. '" indexIA_() error, not found "',trim(item),'"'
  1259. call die(dieWith)
  1260. endif
  1261. endif
  1262. end function indexIA_
  1263. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1264. ! Math and Computer Science Division, Argonne National Laboratory !
  1265. !BOP -------------------------------------------------------------------
  1266. !
  1267. ! !IROUTINE: indexRA_ - index the Accumulator real attribute list.
  1268. !
  1269. ! !DESCRIPTION:
  1270. ! This {\tt INTEGER} query function returns the index in the real
  1271. ! accumulation register buffer of the {\tt Accumulator} argument {\tt aC}
  1272. ! the attribute named by the {\tt CHARACTER} argument {\tt item}. That
  1273. ! is, all the accumulator running tallies for the attribute named
  1274. ! {\tt item} reside in
  1275. !\begin{verbatim}
  1276. ! aC%data%rAttr(indexRA_(aC,item),:).
  1277. !\end{verbatim}
  1278. ! The user may request traceback information (e.g., the name of the
  1279. ! routine from which this one is called) by providing values for either
  1280. ! of the optional {\tt CHARACTER} arguments {\tt perrWith} or {\tt dieWith}
  1281. ! In the event {\tt indexRA\_()} can not find {\tt item} in {\tt aC},
  1282. ! the routine behaves as follows:
  1283. ! \begin{enumerate}
  1284. ! \item if neither {\tt perrWith} nor {\tt dieWith} are present,
  1285. ! {\tt indexRA\_()} returns a value of zero;
  1286. ! \item if {\tt perrWith} is present, but {\tt dieWith} is not, an error
  1287. ! message is written to {\tt stderr} incorporating user-supplied traceback
  1288. ! information stored in the argument {\tt perrWith};
  1289. ! \item if {\tt dieWith} is present, execution terminates with an error
  1290. ! message written to {\tt stderr} that incorporates user-supplied traceback
  1291. ! information stored in the argument {\tt dieWith}.
  1292. ! \end{enumerate}
  1293. !
  1294. ! !INTERFACE:
  1295. integer function indexRA_(aC, item, perrWith, dieWith)
  1296. !
  1297. ! !USES:
  1298. !
  1299. use m_AttrVect, only : AttrVect_indexRA => indexRA
  1300. use m_die, only : die
  1301. use m_stdio,only : stderr
  1302. implicit none
  1303. ! !INPUT PARAMETERS:
  1304. !
  1305. type(Accumulator), intent(in) :: aC
  1306. character(len=*), intent(in) :: item
  1307. character(len=*), optional, intent(in) :: perrWith
  1308. character(len=*), optional, intent(in) :: dieWith
  1309. ! !REVISION HISTORY:
  1310. ! 14Sep00 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  1311. !EOP ___________________________________________________________________
  1312. character(len=*),parameter :: myname_=myname//'::indexRA_'
  1313. indexRA_=AttrVect_indexRA(aC%data,item)
  1314. if(indexRA_==0) then
  1315. if(.not.present(dieWith)) then
  1316. if(present(perrWith)) write(stderr,'(4a)') perrWith, &
  1317. '" indexRA_() error, not found "',trim(item),'"'
  1318. else
  1319. write(stderr,'(4a)') dieWith, &
  1320. '" indexRA_() error, not found "',trim(item),'"'
  1321. call die(dieWith)
  1322. endif
  1323. endif
  1324. end function indexRA_
  1325. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1326. ! Math and Computer Science Division, Argonne National Laboratory !
  1327. !BOP -------------------------------------------------------------------
  1328. !
  1329. ! !IROUTINE: exportIAttr_ - Export INTEGER Attribute to a Vector
  1330. !
  1331. ! !DESCRIPTION:
  1332. ! This routine extracts from the input {\tt Accumulator} argument
  1333. ! {\tt aC} the integer attribute corresponding to the tag defined in
  1334. ! the input {\tt CHARACTER} argument {\tt AttrTag}, and returns it in
  1335. ! the {\tt INTEGER} output array {\tt outVect}, and its length in the
  1336. ! output {\tt INTEGER} argument {\tt lsize}.
  1337. !
  1338. ! {\bf N.B.:} This routine will fail if the {\tt AttrTag} is not in
  1339. ! the {\tt Accumulator} {\tt List} component {\tt aC\%data\%iList}.
  1340. !
  1341. ! {\bf N.B.:} The flexibility of this routine regarding the pointer
  1342. ! association status of the output argument {\tt outVect} means the
  1343. ! user must invoke this routine with care. If the user wishes this
  1344. ! routine to fill a pre-allocated array, then obviously this array
  1345. ! must be allocated prior to calling this routine. If the user wishes
  1346. ! that the routine {\em create} the output argument array {\tt outVect},
  1347. ! then the user must ensure this pointer is not allocated (i.e. the user
  1348. ! must nullify this pointer) at the time this routine is invoked.
  1349. !
  1350. ! {\bf N.B.:} If the user has relied on this routine to allocate memory
  1351. ! associated with the pointer {\tt outVect}, then the user is responsible
  1352. ! for deallocating this array once it is no longer needed. Failure to
  1353. ! do so will result in a memory leak.
  1354. !
  1355. ! !INTERFACE:
  1356. subroutine exportIAttr_(aC, AttrTag, outVect, lsize)
  1357. !
  1358. ! !USES:
  1359. !
  1360. use m_die
  1361. use m_stdio
  1362. use m_AttrVect, only : AttrVect_exportIAttr => exportIAttr
  1363. implicit none
  1364. ! !INPUT PARAMETERS:
  1365. type(Accumulator), intent(in) :: aC
  1366. character(len=*), intent(in) :: AttrTag
  1367. ! !OUTPUT PARAMETERS:
  1368. integer, dimension(:), pointer :: outVect
  1369. integer, optional, intent(out) :: lsize
  1370. ! !REVISION HISTORY:
  1371. ! 6May02 - J.W. Larson <larson@mcs.anl.gov> - initial prototype.
  1372. !
  1373. !EOP ___________________________________________________________________
  1374. character(len=*),parameter :: myname_=myname//'::exportIAttr_'
  1375. ! Export the data (inheritance from AttrVect)
  1376. if(present(lsize)) then
  1377. call AttrVect_exportIAttr(aC%data, AttrTag, outVect, lsize)
  1378. else
  1379. call AttrVect_exportIAttr(aC%data, AttrTag, outVect)
  1380. endif
  1381. end subroutine exportIAttr_
  1382. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1383. ! Math and Computer Science Division, Argonne National Laboratory !
  1384. !BOP -------------------------------------------------------------------
  1385. !
  1386. ! !IROUTINE: exportRAttrSP_ - Export REAL Attribute to a Vector
  1387. !
  1388. ! !DESCRIPTION:
  1389. ! This routine extracts from the input {\tt Accumulator} argument
  1390. ! {\tt aC} the real attribute corresponding to the tag defined in
  1391. ! the input {\tt CHARACTER} argument {\tt AttrTag}, and returns it in
  1392. ! the {\tt REAL} output array {\tt outVect}, and its length in the
  1393. ! output {\tt INTEGER} argument {\tt lsize}.
  1394. !
  1395. ! {\bf N.B.:} This routine will fail if the {\tt AttrTag} is not in
  1396. ! the {\tt Accumulator} {\tt List} component {\tt aC\%data\%iList}.
  1397. !
  1398. ! {\bf N.B.:} The flexibility of this routine regarding the pointer
  1399. ! association status of the output argument {\tt outVect} means the
  1400. ! user must invoke this routine with care. If the user wishes this
  1401. ! routine to fill a pre-allocated array, then obviously this array
  1402. ! must be allocated prior to calling this routine. If the user wishes
  1403. ! that the routine {\em create} the output argument array {\tt outVect},
  1404. ! then the user must ensure this pointer is not allocated (i.e. the user
  1405. ! must nullify this pointer) at the time this routine is invoked.
  1406. !
  1407. ! {\bf N.B.:} If the user has relied on this routine to allocate memory
  1408. ! associated with the pointer {\tt outVect}, then the user is responsible
  1409. ! for deallocating this array once it is no longer needed. Failure to
  1410. ! do so will result in a memory leak.
  1411. !
  1412. ! !INTERFACE:
  1413. subroutine exportRAttrSP_(aC, AttrTag, outVect, lsize)
  1414. !
  1415. ! !USES:
  1416. !
  1417. use m_die
  1418. use m_stdio
  1419. use m_AttrVect, only : AttrVect_exportRAttr => exportRAttr
  1420. implicit none
  1421. ! !INPUT PARAMETERS:
  1422. type(Accumulator), intent(in) :: aC
  1423. character(len=*), intent(in) :: AttrTag
  1424. ! !OUTPUT PARAMETERS:
  1425. real(SP), dimension(:), pointer :: outVect
  1426. integer, optional, intent(out) :: lsize
  1427. ! !REVISION HISTORY:
  1428. ! 6May02 - J.W. Larson <larson@mcs.anl.gov> - initial prototype.
  1429. !
  1430. !EOP ___________________________________________________________________
  1431. character(len=*),parameter :: myname_=myname//'::exportRAttrSP_'
  1432. ! Export the data (inheritance from AttrVect)
  1433. if(present(lsize)) then
  1434. call AttrVect_exportRAttr(aC%data, AttrTag, outVect, lsize)
  1435. else
  1436. call AttrVect_exportRAttr(aC%data, AttrTag, outVect)
  1437. endif
  1438. end subroutine exportRAttrSP_
  1439. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1440. ! Math and Computer Science Division, Argonne National Laboratory !
  1441. ! ----------------------------------------------------------------------
  1442. !
  1443. ! !IROUTINE: exportRAttrDP_ - Export REAL Attribute to a Vector
  1444. !
  1445. ! !DESCRIPTION:
  1446. ! Double precision version of exportRAttrSP_
  1447. !
  1448. ! !INTERFACE:
  1449. subroutine exportRAttrDP_(aC, AttrTag, outVect, lsize)
  1450. !
  1451. ! !USES:
  1452. !
  1453. use m_die
  1454. use m_stdio
  1455. use m_AttrVect, only : AttrVect_exportRAttr => exportRAttr
  1456. implicit none
  1457. ! !INPUT PARAMETERS:
  1458. type(Accumulator), intent(in) :: aC
  1459. character(len=*), intent(in) :: AttrTag
  1460. ! !OUTPUT PARAMETERS:
  1461. real(DP), dimension(:), pointer :: outVect
  1462. integer, optional, intent(out) :: lsize
  1463. ! !REVISION HISTORY:
  1464. ! 6May02 - J.W. Larson <larson@mcs.anl.gov> - initial prototype.
  1465. !
  1466. ! ______________________________________________________________________
  1467. character(len=*),parameter :: myname_=myname//'::exportRAttrDP_'
  1468. ! Export the data (inheritance from AttrVect)
  1469. if(present(lsize)) then
  1470. call AttrVect_exportRAttr(aC%data, AttrTag, outVect, lsize)
  1471. else
  1472. call AttrVect_exportRAttr(aC%data, AttrTag, outVect)
  1473. endif
  1474. end subroutine exportRAttrDP_
  1475. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1476. ! Math and Computer Science Division, Argonne National Laboratory !
  1477. !BOP -------------------------------------------------------------------
  1478. !
  1479. ! !IROUTINE: importIAttr_ - Import INTEGER Attribute from a Vector
  1480. !
  1481. ! !DESCRIPTION:
  1482. ! This routine imports data provided in the input {\tt INTEGER} vector
  1483. ! {\tt inVect} into the {\tt Accumulator} argument {\tt aC}, storing
  1484. ! it as the integer attribute corresponding to the tag defined in
  1485. ! the input {\tt CHARACTER} argument {\tt AttrTag}. The input
  1486. ! {\tt INTEGER} argument {\tt lsize} is used to ensure there is
  1487. ! sufficient space in the {\tt Accumulator} to store the data.
  1488. !
  1489. ! {\bf N.B.:} This routine will fail if the {\tt AttrTag} is not in
  1490. ! the {\tt Accumulator} {\tt List} component {\tt aC\%data\%rList}.
  1491. !
  1492. ! !INTERFACE:
  1493. subroutine importIAttr_(aC, AttrTag, inVect, lsize)
  1494. !
  1495. ! !USES:
  1496. !
  1497. use m_die
  1498. use m_stdio , only : stderr
  1499. use m_AttrVect, only : AttrVect_importIAttr => importIAttr
  1500. implicit none
  1501. ! !INPUT PARAMETERS:
  1502. character(len=*), intent(in) :: AttrTag
  1503. integer, dimension(:), pointer :: inVect
  1504. integer, intent(in) :: lsize
  1505. ! !INPUT/OUTPUT PARAMETERS:
  1506. type(Accumulator), intent(inout) :: aC
  1507. ! !REVISION HISTORY:
  1508. ! 6May02 - J.W. Larson <larson@mcs.anl.gov> - initial prototype.
  1509. !EOP ___________________________________________________________________
  1510. character(len=*),parameter :: myname_=myname//'::importIAttr_'
  1511. ! Argument Check:
  1512. if(lsize > lsize_(aC)) then
  1513. write(stderr,*) myname_,':: ERROR, lsize > lsize_(aC).', &
  1514. 'lsize = ',lsize,'lsize_(aC) = ',lsize_(ac)
  1515. call die(myname_)
  1516. endif
  1517. ! Import the data (inheritance from AttrVect)
  1518. call AttrVect_importIAttr(aC%data, AttrTag, inVect, lsize)
  1519. end subroutine importIAttr_
  1520. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1521. ! Math and Computer Science Division, Argonne National Laboratory !
  1522. !BOP -------------------------------------------------------------------
  1523. !
  1524. ! !IROUTINE: importRAttrSP_ - Import REAL Attribute from a Vector
  1525. !
  1526. ! !DESCRIPTION:
  1527. ! This routine imports data provided in the input {\tt REAL} vector
  1528. ! {\tt inVect} into the {\tt Accumulator} argument {\tt aC}, storing
  1529. ! it as the real attribute corresponding to the tag defined in
  1530. ! the input {\tt CHARACTER} argument {\tt AttrTag}. The input
  1531. ! {\tt INTEGER} argument {\tt lsize} is used to ensure there is
  1532. ! sufficient space in the {\tt Accumulator} to store the data.
  1533. !
  1534. ! {\bf N.B.:} This routine will fail if the {\tt AttrTag} is not in
  1535. ! the {\tt Accumulator} {\tt List} component {\tt aC\%data\%rList}.
  1536. !
  1537. ! !INTERFACE:
  1538. subroutine importRAttrSP_(aC, AttrTag, inVect, lsize)
  1539. !
  1540. ! !USES:
  1541. !
  1542. use m_die
  1543. use m_stdio , only : stderr
  1544. use m_AttrVect, only : AttrVect_importRAttr => importRAttr
  1545. implicit none
  1546. ! !INPUT PARAMETERS:
  1547. character(len=*), intent(in) :: AttrTag
  1548. real(SP), dimension(:), pointer :: inVect
  1549. integer, intent(in) :: lsize
  1550. ! !INPUT/OUTPUT PARAMETERS:
  1551. type(Accumulator), intent(inout) :: aC
  1552. ! !REVISION HISTORY:
  1553. ! 6May02 - J.W. Larson <larson@mcs.anl.gov> - initial prototype.
  1554. !EOP ___________________________________________________________________
  1555. character(len=*),parameter :: myname_=myname//'::importRAttrSP_'
  1556. ! Argument Check:
  1557. if(lsize > lsize_(aC)) then
  1558. write(stderr,*) myname_,':: ERROR, lsize > lsize_(aC).', &
  1559. 'lsize = ',lsize,'lsize_(aC) = ',lsize_(ac)
  1560. call die(myname_)
  1561. endif
  1562. ! Import the data (inheritance from AttrVect)
  1563. call AttrVect_importRAttr(aC%data, AttrTag, inVect, lsize)
  1564. end subroutine importRAttrSP_
  1565. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1566. ! Math and Computer Science Division, Argonne National Laboratory !
  1567. ! ----------------------------------------------------------------------
  1568. !
  1569. ! !IROUTINE: importRAttrDP_ - Import REAL Attribute from a Vector
  1570. !
  1571. ! !DESCRIPTION:
  1572. ! Double precision version of importRAttrSP_
  1573. !
  1574. ! !INTERFACE:
  1575. subroutine importRAttrDP_(aC, AttrTag, inVect, lsize)
  1576. !
  1577. ! !USES:
  1578. !
  1579. use m_die
  1580. use m_stdio , only : stderr
  1581. use m_AttrVect, only : AttrVect_importRAttr => importRAttr
  1582. implicit none
  1583. ! !INPUT PARAMETERS:
  1584. character(len=*), intent(in) :: AttrTag
  1585. real(DP), dimension(:), pointer :: inVect
  1586. integer, intent(in) :: lsize
  1587. ! !INPUT/OUTPUT PARAMETERS:
  1588. type(Accumulator), intent(inout) :: aC
  1589. ! !REVISION HISTORY:
  1590. ! 6May02 - J.W. Larson <larson@mcs.anl.gov> - initial prototype.
  1591. ! ______________________________________________________________________
  1592. character(len=*),parameter :: myname_=myname//'::importRAttrDP_'
  1593. ! Argument Check:
  1594. if(lsize > lsize_(aC)) then
  1595. write(stderr,*) myname_,':: ERROR, lsize > lsize_(aC).', &
  1596. 'lsize = ',lsize,'lsize_(aC) = ',lsize_(ac)
  1597. call die(myname_)
  1598. endif
  1599. ! Import the data (inheritance from AttrVect)
  1600. call AttrVect_importRAttr(aC%data, AttrTag, inVect, lsize)
  1601. end subroutine importRAttrDP_
  1602. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1603. ! Math and Computer Science Division, Argonne National Laboratory !
  1604. !BOP -------------------------------------------------------------------
  1605. !
  1606. ! !IROUTINE: zero_ - Zero an Accumulator
  1607. !
  1608. ! !DESCRIPTION:
  1609. ! This subroutine clears the the {\tt Accumulator} argument {\tt aC}.
  1610. ! This is accomplished by setting the number of completed steps in the
  1611. ! accumulation cycle to zero, and zeroing out all of the accumlation
  1612. ! registers.
  1613. !
  1614. ! !INTERFACE:
  1615. subroutine zero_(aC)
  1616. !
  1617. ! !USES:
  1618. !
  1619. use m_AttrVect, only : AttrVect_zero => zero
  1620. implicit none
  1621. ! !INPUT/OUTPUT PARAMETERS:
  1622. !
  1623. type(Accumulator), intent(inout) :: aC
  1624. ! !REVISION HISTORY:
  1625. ! 7Aug02 - Jay Larson <larson@mcs.anl.gov> - initial prototype
  1626. !EOP ___________________________________________________________________
  1627. character(len=*),parameter :: myname_=myname//'::zero_'
  1628. ! Set number of completed cycle steps to zero:
  1629. aC%steps_done = 0
  1630. ! Zero out the accumulation registers:
  1631. call AttrVect_zero(aC%data)
  1632. end subroutine zero_
  1633. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1634. ! Math and Computer Science Division, Argonne National Laboratory !
  1635. !BOP -------------------------------------------------------------------
  1636. !
  1637. ! !IROUTINE: aCaCSharedAttrIndexList_ - Cross-index Two Accumulators
  1638. !
  1639. ! !DESCRIPTION: {\tt aCaCSharedAttrIndexList\_()} takes a pair of
  1640. ! user-supplied {\tt Accumulator} variables {\tt aC1} and {\tt aC2},
  1641. ! and for choice of either {\tt REAL} or {\tt INTEGER} attributes (as
  1642. ! specified literally in the input {\tt CHARACTER} argument {\tt attrib})
  1643. ! returns the number of shared attributes {\tt NumShared}, and arrays of
  1644. ! indices {\tt Indices1} and {\tt Indices2} to their storage locations
  1645. ! in {\tt aC1} and {\tt aC2}, respectively.
  1646. !
  1647. ! {\bf N.B.:} This routine returns two allocated arrays---{\tt Indices1(:)}
  1648. ! and {\tt Indices2(:)}---which must be deallocated once the user no longer
  1649. ! needs them. Failure to do this will create a memory leak.
  1650. !
  1651. ! !INTERFACE:
  1652. subroutine aCaCSharedAttrIndexList_(aC1, aC2, attrib, NumShared, &
  1653. Indices1, Indices2)
  1654. !
  1655. ! !USES:
  1656. !
  1657. use m_stdio
  1658. use m_die, only : MP_perr_die, die, warn
  1659. use m_List, only : GetSharedListIndices
  1660. implicit none
  1661. ! !INPUT PARAMETERS:
  1662. !
  1663. type(Accumulator), intent(in) :: aC1
  1664. type(Accumulator), intent(in) :: aC2
  1665. character*7, intent(in) :: attrib
  1666. ! !OUTPUT PARAMETERS:
  1667. !
  1668. integer, intent(out) :: NumShared
  1669. integer,dimension(:), pointer :: Indices1
  1670. integer,dimension(:), pointer :: Indices2
  1671. ! !REVISION HISTORY:
  1672. ! 7Feb01 - J.W. Larson <larson@mcs.anl.gov> - initial version
  1673. !EOP ___________________________________________________________________
  1674. character(len=*),parameter :: myname_=myname//'::aCaCSharedAttrIndexList_'
  1675. integer :: ierr
  1676. ! Based on the value of the argument attrib, pass the
  1677. ! appropriate pair of Lists for comparison...
  1678. select case(trim(attrib))
  1679. case('REAL','real')
  1680. call GetSharedListIndices(aC1%data%rList, aC2%data%rList, NumShared, &
  1681. Indices1, Indices2)
  1682. case('INTEGER','integer')
  1683. call GetSharedListIndices(aC1%data%iList, aC2%data%iList, NumShared, &
  1684. Indices1, Indices2)
  1685. case default
  1686. write(stderr,'(4a)') myname_,":: value of argument attrib=",attrib, &
  1687. " not recognized. Allowed values: REAL, real, INTEGER, integer"
  1688. ierr = 1
  1689. call die(myname_, 'invalid value for attrib', ierr)
  1690. end select
  1691. end subroutine aCaCSharedAttrIndexList_
  1692. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1693. ! Math and Computer Science Division, Argonne National Laboratory !
  1694. !BOP -------------------------------------------------------------------
  1695. !
  1696. ! !IROUTINE: aVaCSharedAttrIndexList_ - Cross-index with an AttrVect
  1697. !
  1698. ! !DESCRIPTION: {\tt aVaCSharedAttrIndexList\_()} a user-supplied
  1699. ! {\tt AttrVect} variable {\tt aV} and an {\tt Accumulator} variable
  1700. ! {\tt aC}, and for choice of either {\tt REAL} or {\tt INTEGER}
  1701. ! attributes (as ! specified literally in the input {\tt CHARACTER}
  1702. ! argument {\tt attrib}) returns the number of shared attributes
  1703. ! {\tt NumShared}, and arrays of indices {\tt Indices1} and {\tt Indices2}
  1704. ! to their storage locations in {\tt aV} and {\tt aC}, respectively.
  1705. !
  1706. ! {\bf N.B.:} This routine returns two allocated arrays---{\tt Indices1(:)}
  1707. ! and {\tt Indices2(:)}---which must be deallocated once the user no longer
  1708. ! needs them. Failure to do this will create a memory leak.
  1709. !
  1710. ! !INTERFACE:
  1711. subroutine aVaCSharedAttrIndexList_(aV, aC, attrib, NumShared, &
  1712. Indices1, Indices2)
  1713. !
  1714. ! !USES:
  1715. !
  1716. use m_stdio
  1717. use m_die, only : MP_perr_die, die, warn
  1718. use m_AttrVect, only : AttrVect
  1719. use m_List, only : GetSharedListIndices
  1720. implicit none
  1721. ! !INPUT PARAMETERS:
  1722. !
  1723. type(AttrVect), intent(in) :: aV
  1724. type(Accumulator), intent(in) :: aC
  1725. character(len=*), intent(in) :: attrib
  1726. ! !OUTPUT PARAMETERS:
  1727. !
  1728. integer, intent(out) :: NumShared
  1729. integer,dimension(:), pointer :: Indices1
  1730. integer,dimension(:), pointer :: Indices2
  1731. ! !REVISION HISTORY:
  1732. ! 7Feb01 - J.W. Larson <larson@mcs.anl.gov> - initial version
  1733. !EOP ___________________________________________________________________
  1734. character(len=*),parameter :: myname_=myname//'::aVaCSharedAttrIndexList_'
  1735. integer :: ierr
  1736. ! Based on the value of the argument attrib, pass the
  1737. ! appropriate pair of Lists for comparison...
  1738. select case(trim(attrib))
  1739. case('REAL','real')
  1740. call GetSharedListIndices(aV%rList, aC%data%rList, NumShared, &
  1741. Indices1, Indices2)
  1742. case('INTEGER','integer')
  1743. call GetSharedListIndices(aV%iList, aC%data%iList, NumShared, &
  1744. Indices1, Indices2)
  1745. case default
  1746. write(stderr,'(4a)') myname_,":: value of argument attrib=",attrib, &
  1747. " not recognized. Allowed values: REAL, real, INTEGER, integer"
  1748. ierr = 1
  1749. call die(myname_, 'invalid value for attrib', ierr)
  1750. end select
  1751. end subroutine aVaCSharedAttrIndexList_
  1752. !BOP -------------------------------------------------------------------
  1753. !
  1754. ! !IROUTINE: accumulate_--Acumulate from an AttrVect to an Accumulator.
  1755. !
  1756. ! !DESCRIPTION:
  1757. ! This routine performs time {\em accumlation} of data present in an
  1758. ! MCT field data {\tt AttrVect} variable {\tt aV} and combines it with
  1759. ! the running tallies stored in the MCT {\tt Accumulator} variable {\tt aC}.
  1760. ! This routine automatically identifies which
  1761. ! fields are held in common by {\tt aV} and {\tt aC} and uses the
  1762. ! accumulation action information stored in {\tt aC} to decide how
  1763. ! each field in {\tt aV} is to be combined into its corresponding
  1764. ! running tally in {\tt aC}. The accumulation operations currently
  1765. ! supported are:
  1766. ! \begin {itemize}
  1767. ! \item {\tt MCT\_SUM}: Add the current values in the {\tt Av} to the current values in {\tt Ac}.
  1768. ! \item {\tt MCT\_AVG}: Same as {\tt MCT\_SUM} except when {\tt steps\_done} is equal
  1769. ! to {\tt num\_steps} then perform one more sum and replaced with average.
  1770. ! \end {itemize}
  1771. !
  1772. ! This routine also automatically increments the counter in {\tt aC}
  1773. ! signifying the number of steps completed in the accumulation cycle.
  1774. !
  1775. ! NOTE: The user must reset (zero) the {\tt Accumulator} after the average
  1776. ! has been formed or the next call to {\tt accumulate} will add to the average.
  1777. !
  1778. ! !INTERFACE:
  1779. subroutine accumulate_(aV, aC)
  1780. !
  1781. ! !USES:
  1782. !
  1783. use m_stdio, only : stdout,stderr
  1784. use m_die, only : die
  1785. use m_AttrVect, only : AttrVect
  1786. use m_AttrVect, only : AttrVect_lsize => lsize
  1787. use m_AttrVect, only : AttrVect_nIAttr => nIAttr
  1788. use m_AttrVect, only : AttrVect_nRAttr => nRAttr
  1789. use m_AttrVect, only : AttrVect_indexRA => indexRA
  1790. use m_AttrVect, only : AttrVect_indexIA => indexIA
  1791. implicit none
  1792. ! !INPUT PARAMETERS:
  1793. !
  1794. type(AttrVect), intent(in) :: aV ! Input AttrVect
  1795. ! !INPUT/OUTPUT PARAMETERS:
  1796. !
  1797. type(Accumulator), intent(inout) :: aC ! Output Accumulator
  1798. ! !REVISION HISTORY:
  1799. ! 18Sep00 - J.W. Larson <larson@mcs.anl.gov> -- initial version.
  1800. ! 7Feb01 - J.W. Larson <larson@mcs.anl.gov> -- General version.
  1801. ! 10Jun01 - E.T. Ong -- fixed divide-by-zero problem in integer
  1802. ! attribute accumulation.
  1803. ! 27Jul01 - E.T. Ong <eong@mcs.anl.gov> -- removed action argument.
  1804. ! Make compatible with new Accumulator type.
  1805. !EOP ___________________________________________________________________
  1806. character(len=*),parameter :: myname_=myname//'::accumulate_'
  1807. ! Overlapping attribute index number
  1808. integer :: num_indices
  1809. ! Overlapping attribute index storage arrays:
  1810. integer, dimension(:), pointer :: aCindices, aVindices
  1811. integer :: aCindex, aVindex
  1812. ! Error flag and loop indices
  1813. integer :: ierr, l, n
  1814. ! Averaging time-weighting factor:
  1815. real(FP) :: step_weight
  1816. integer :: num_steps
  1817. ! Character variable used as a data type flag:
  1818. character*7 :: data_flag
  1819. ! Sanity check of arguments:
  1820. if(lsize_(aC) /= AttrVect_lsize(aV)) then
  1821. write(stderr,'(2a,i8,a,i8)') myname_, &
  1822. ':: Mismatched Accumulator/AttrVect lengths. AttrVect_lsize(aV) = ',&
  1823. AttrVect_lsize(aV), 'lsize_(aC) = ',lsize_(aC)
  1824. call die(myname_)
  1825. endif
  1826. if(aC%num_steps == 0) then
  1827. write(stderr,'(2a)') myname,':: FATAL--Zero steps in accumulation cycle.'
  1828. call die(myname_)
  1829. endif
  1830. ! Set num_steps from aC:
  1831. num_steps = aC%num_steps
  1832. ! Accumulation of REAL attribute data:
  1833. if( associated(aC%rAction) ) then ! if summing or avergaging reals...
  1834. ! Accumulate only if fields are present
  1835. data_flag = 'REAL'
  1836. call aVaCSharedAttrIndexList_(aV, aC, data_flag, num_indices, &
  1837. aVindices, aCindices)
  1838. if(num_indices > 0) then
  1839. do n=1,num_indices
  1840. aVindex = aVindices(n)
  1841. aCindex = aCindices(n)
  1842. ! Accumulate if the action is MCT_SUM or MCT_AVG
  1843. if( (aC%rAction(aCindex) == MCT_SUM).or. &
  1844. (aC%rAction(aCindex) == MCT_AVG) ) then
  1845. do l=1,AttrVect_lsize(aV)
  1846. aC%data%rAttr(aCindex,l) = aC%data%rAttr(aCindex,l) + &
  1847. aV%rAttr(aVindex,l)
  1848. end do
  1849. endif
  1850. end do
  1851. deallocate(aVindices, aCindices, stat=ierr)
  1852. if(ierr /= 0) then
  1853. write(stderr,'(2a,i8)') myname_, &
  1854. ':: Error in first deallocate(aVindices...), ierr = ',ierr
  1855. call die(myname_)
  1856. endif
  1857. endif ! if(num_indices > 0)
  1858. endif ! if( associated(aC%rAction) )
  1859. ! Accumulation of INTEGER attribute data:
  1860. if( associated(aC%iAction) ) then ! if summing or avergaging ints...
  1861. ! Accumulate only if fields are present
  1862. data_flag = 'INTEGER'
  1863. call aVaCSharedAttrIndexList_(aV, aC, data_flag, num_indices, &
  1864. aVindices, aCindices)
  1865. if(num_indices > 0) then
  1866. do n=1,num_indices
  1867. aVindex = aVindices(n)
  1868. aCindex = aCindices(n)
  1869. ! Accumulate if the action is MCT_SUM or MCT_AVG
  1870. if( (aC%iAction(aCindex) == MCT_SUM) .or. &
  1871. (aC%iAction(aCindex) == MCT_AVG) ) then
  1872. do l=1,AttrVect_lsize(aV)
  1873. aC%data%iAttr(aCindex,l) = aC%data%iAttr(aCindex,l) + &
  1874. aV%iAttr(aVindex,l)
  1875. end do
  1876. endif
  1877. end do
  1878. deallocate(aVindices, aCindices, stat=ierr)
  1879. if(ierr /= 0) then
  1880. write(stderr,'(2a,i8)') myname_, &
  1881. ':: Error in second deallocate(aVindices...), ierr = ',ierr
  1882. call die(myname_)
  1883. endif
  1884. endif ! if(num_indices > 0)
  1885. endif ! if( associated(aC%iAction) )
  1886. ! Increment aC%steps_done:
  1887. aC%steps_done = aC%steps_done + 1
  1888. ! If we are at the end of an averaging period, compute the
  1889. ! average (if desired).
  1890. if(aC%steps_done == num_steps) then
  1891. step_weight = 1.0_FP / REAL(num_steps,FP)
  1892. do n=1,nRAttr_(aC)
  1893. if( aC%rAction(n) == MCT_AVG ) then
  1894. do l=1,lsize_(aC)
  1895. aC%data%rAttr(n,l) = step_weight * aC%data%rAttr(n,l)
  1896. enddo
  1897. endif
  1898. enddo
  1899. do n=1,nIAttr_(aC)
  1900. if( aC%iAction(n) == MCT_AVG ) then
  1901. do l=1,lsize_(aC)
  1902. aC%data%iAttr(n,l) = aC%data%iAttr(n,l) / num_steps
  1903. enddo
  1904. endif
  1905. enddo
  1906. endif
  1907. end subroutine accumulate_
  1908. !BOP -------------------------------------------------------------------
  1909. !
  1910. ! !IROUTINE: average_ -- Force an average to be taken on an Accumulator
  1911. !
  1912. ! !DESCRIPTION:
  1913. ! This routine will compute the average of the current values in an
  1914. ! {\tt Accumulator} using the current value of {\tt steps\_done}
  1915. ! in the {\tt Accumulator}
  1916. !
  1917. ! !INTERFACE:
  1918. subroutine average_(aC)
  1919. !
  1920. ! !USES:
  1921. !
  1922. use m_stdio, only : stdout,stderr
  1923. use m_die, only : die
  1924. use m_AttrVect, only : AttrVect
  1925. use m_AttrVect, only : AttrVect_lsize => lsize
  1926. use m_AttrVect, only : AttrVect_nIAttr => nIAttr
  1927. use m_AttrVect, only : AttrVect_nRAttr => nRAttr
  1928. use m_AttrVect, only : AttrVect_indexRA => indexRA
  1929. use m_AttrVect, only : AttrVect_indexIA => indexIA
  1930. implicit none
  1931. ! !INPUT/OUTPUT PARAMETERS:
  1932. !
  1933. type(Accumulator), intent(inout) :: aC ! Output Accumulator
  1934. ! !REVISION HISTORY:
  1935. ! 11Jan08 - R.Jacob <jacob@mcs.anl.gov> -- initial version based on accumulate_
  1936. !EOP ___________________________________________________________________
  1937. character(len=*),parameter :: myname_=myname//'::average_'
  1938. ! Overlapping attribute index number
  1939. integer :: num_indices
  1940. ! Overlapping attribute index storage arrays:
  1941. integer, dimension(:), pointer :: aCindices, aVindices
  1942. integer :: aCindex, aVindex
  1943. ! Error flag and loop indices
  1944. integer :: ierr, l, n
  1945. ! Averaging time-weighting factor:
  1946. real(FP) :: step_weight
  1947. integer :: steps_done
  1948. if(aC%num_steps == 0) then
  1949. write(stderr,'(2a)') myname_,':: FATAL--Zero steps in accumulation cycle.'
  1950. call die(myname_)
  1951. endif
  1952. if(aC%steps_done == 0) then
  1953. write(stderr,'(2a)') myname_,':: FATAL--Zero steps completed in accumulation cycle.'
  1954. call die(myname_)
  1955. endif
  1956. ! Set num_steps from aC:
  1957. steps_done = aC%steps_done
  1958. step_weight = 1.0_FP / REAL(steps_done,FP)
  1959. do n=1,nRAttr_(aC)
  1960. do l=1,lsize_(aC)
  1961. aC%data%rAttr(n,l) = step_weight * aC%data%rAttr(n,l)
  1962. enddo
  1963. enddo
  1964. do n=1,nIAttr_(aC)
  1965. do l=1,lsize_(aC)
  1966. aC%data%iAttr(n,l) = aC%data%iAttr(n,l) / steps_done
  1967. enddo
  1968. enddo
  1969. end subroutine average_
  1970. end module m_Accumulator