m_Navigator.F90 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. ! Math and Computer Science Division, Argonne National Laboratory !
  3. !-----------------------------------------------------------------------
  4. ! CVS m_Navigator.F90,v 1.9 2004-04-21 22:47:09 jacob Exp
  5. ! CVS MCT_2_8_0
  6. !BOP -------------------------------------------------------------------
  7. !
  8. ! !MODULE: m_Navigator - An Object for Indexing Segments of a Vector
  9. !
  10. ! !DESCRIPTION:
  11. ! A {\em Navigator} is a table used to {\em index} or {\em Navigate}
  12. ! segments of a vector, or segments of a dimension of a
  13. ! higher-dimensional array. In MCT, this concept is embodied in
  14. ! the {\tt Navigator} datatype, which contains
  15. ! the following components:
  16. ! \begin{itemize}
  17. ! \item The {\em number} of segments;
  18. ! \item The {\em displacement} of the starting index of each segment
  19. ! from the vector's first element (i.e. the starting index minus 1);
  20. ! \item The {\em length} of each segment; and
  21. ! \item The {\em total length} of the vector or array dimension for which
  22. ! segments are defined. This last item is optional, but if defined
  23. ! provides the ability for the {\tt Navigator} to check for erroneous
  24. ! segment entries (i.e., segments that are out-of-bounds).
  25. ! \end{itemize}
  26. !
  27. ! This module defines the {\tt Navigator} datatype, creation and
  28. ! destruction methods, a variety of query methods, and a method for
  29. ! resizing the {\tt Navigator}.
  30. !
  31. ! !INTERFACE:
  32. module m_Navigator
  33. ! !USES:
  34. ! No external modules are used in the declaration section of this module.
  35. implicit none
  36. private ! except
  37. ! !PUBLIC TYPES:
  38. public :: Navigator ! The class data structure
  39. Type Navigator
  40. integer :: NumSegments ! Number of defined Segments
  41. integer :: VectorLength ! Length of the Vector being indexed
  42. integer,pointer,dimension(:) :: displs ! Segment start displacements
  43. integer,pointer,dimension(:) :: counts ! Segment lengths
  44. End Type Navigator
  45. ! !PUBLIC MEMBER FUNCTIONS:
  46. public :: Navigator_init,init ! initialize an object
  47. public :: clean ! clean an object
  48. public :: NumSegments ! number of vector segments
  49. public :: VectorLength ! indexed vector's total length
  50. public :: msize ! the maximum size
  51. public :: resize ! adjust the true size
  52. public :: get ! get an entry
  53. public :: ptr_displs ! referencing %displs(:)
  54. public :: ptr_counts ! referencing %counts(:)
  55. interface Navigator_init; module procedure &
  56. init_
  57. end interface
  58. interface init ; module procedure init_ ; end interface
  59. interface clean ; module procedure clean_ ; end interface
  60. interface NumSegments ; module procedure &
  61. NumSegments_
  62. end interface
  63. interface VectorLength ; module procedure &
  64. VectorLength_
  65. end interface
  66. interface msize ; module procedure msize_ ; end interface
  67. interface resize; module procedure resize_; end interface
  68. interface get ; module procedure get_ ; end interface
  69. interface ptr_displs; module procedure &
  70. ptr_displs_
  71. end interface
  72. interface ptr_counts; module procedure &
  73. ptr_counts_
  74. end interface
  75. ! !REVISION HISTORY:
  76. ! 22May00 - Jing Guo <guo@dao.gsfc.nasa.gov> - initial prototype/prolog/code
  77. ! 26Aug02 - J. Larson <larson@mcs.anl.gov> - expanded datatype to inlcude
  78. ! VectorLength component.
  79. !EOP ___________________________________________________________________
  80. character(len=*),parameter :: myname='MCT::m_Navigator'
  81. contains
  82. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  83. ! Math and Computer Science Division, Argonne National Laboratory !
  84. !BOP -------------------------------------------------------------------
  85. !
  86. ! !IROUTINE: init_ - Create a Navigator
  87. !
  88. ! !DESCRIPTION:
  89. ! This routine creates a {\tt Navigator} {\tt Nav} capable of storing
  90. ! information about {\tt NumSegments} segments. The user can supply the
  91. ! length of the vector (or array subspace) being indexed by supplying the
  92. ! optional input {\tt INTEGER} argument {\tt VectorLength} (if it is not
  93. ! supplied, this component of {\tt Nav} will be set to zero, signifying
  94. ! to other {\tt Navigator} routines that vector length information is
  95. ! unavailable). The success (failure) of this operation is signified by
  96. ! the zero (non-zero) value of the optional output {\tt INTEGER} argument
  97. ! {\tt stat}.
  98. !
  99. ! !INTERFACE:
  100. subroutine init_(Nav, NumSegments, VectorLength, stat)
  101. ! !USES:
  102. use m_mall,only : mall_ison,mall_mci
  103. use m_die ,only : die,perr
  104. use m_stdio, only : stderr
  105. implicit none
  106. ! !INPUT PARAMETERS:
  107. integer, intent(in) :: NumSegments
  108. integer, optional, intent(in) :: VectorLength
  109. ! !OUTPUT PARAMETERS:
  110. type(Navigator), intent(out) :: Nav
  111. integer, optional, intent(out) :: stat
  112. ! !REVISION HISTORY:
  113. ! 22May00 - Jing Guo <guo@dao.gsfc.nasa.gov> - initial prototype/prolog/code
  114. !EOP ___________________________________________________________________
  115. character(len=*),parameter :: myname_=myname//'::init_'
  116. integer :: ier
  117. ! If the argument VectorLength is present, use this value to set
  118. ! Nav%VectorLength. Otherwise, set Nav%VectorLength to zero.
  119. if(present(VectorLength)) then
  120. if(VectorLength < 0) then
  121. write(stderr,'(2a,i8)') myname_, &
  122. ':: FATAL -- illegal value of VectorLength=',VectorLength
  123. call die(myname_)
  124. endif
  125. Nav%VectorLength = VectorLength
  126. else
  127. Nav%VectorLength = 0
  128. endif
  129. ! Allocate segment attribute table arrays:
  130. allocate(Nav%displs(NumSegments),Nav%counts(NumSegments),stat=ier)
  131. if(ier/=0) then
  132. call perr(myname_,'allocate()',ier)
  133. if(.not.present(stat)) call die(myname_)
  134. stat=ier
  135. return
  136. endif
  137. if(mall_ison()) then
  138. call mall_mci(Nav%displs,myname)
  139. call mall_mci(Nav%counts,myname)
  140. endif
  141. Nav%NumSegments=NumSegments
  142. end subroutine init_
  143. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144. ! Math and Computer Science Division, Argonne National Laboratory !
  145. !BOP -------------------------------------------------------------------
  146. !
  147. ! !IROUTINE: clean_ - Destroy a Navigator
  148. !
  149. ! !DESCRIPTION:
  150. ! This routine deallocates allocated memory associated with the
  151. ! input/output {\tt Navigator} argument {\tt Nav}, and clears the
  152. ! vector length and number of segments components The success (failure)
  153. ! of this operation is signified by the zero (non-zero) value of the
  154. ! optional output {\tt INTEGER} argument {\tt stat}.
  155. !
  156. ! !INTERFACE:
  157. subroutine clean_(Nav, stat)
  158. ! !USES:
  159. use m_mall, only : mall_ison,mall_mco
  160. use m_die, only : warn
  161. implicit none
  162. ! !INPUT/OUTPUT PARAMETERS:
  163. type(Navigator),intent(inout) :: Nav
  164. ! !OUTPUT PARAMETERS:
  165. integer,optional,intent(out) :: stat
  166. ! !REVISION HISTORY:
  167. ! 22May00 - Jing Guo <guo@dao.gsfc.nasa.gov> initial prototype/prolog/code
  168. !EOP ___________________________________________________________________
  169. character(len=*),parameter :: myname_=myname//'::clean_'
  170. integer :: ier
  171. if(mall_ison()) then
  172. if(associated(Nav%displs)) call mall_mco(Nav%displs,myname_)
  173. if(associated(Nav%counts)) call mall_mco(Nav%counts,myname_)
  174. endif
  175. deallocate(Nav%displs,Nav%counts,stat=ier)
  176. if(present(stat)) then
  177. stat=ier
  178. else
  179. if(ier /= 0) call warn(myname_,'deallocate(Nav%...)',ier)
  180. endif
  181. Nav%NumSegments = 0
  182. Nav%VectorLength = 0
  183. end subroutine clean_
  184. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  185. ! Math and Computer Science Division, Argonne National Laboratory !
  186. !BOP -------------------------------------------------------------------
  187. !
  188. ! !IROUTINE: NumSegments_ - Return the Number of Segments
  189. !
  190. ! !DESCRIPTION:
  191. ! This {\tt INTEGER} query function returns the number of segments
  192. ! in the input {\tt Navigator} argument {\tt Nav} for which segment
  193. ! start and length information are defined .
  194. !
  195. ! !INTERFACE:
  196. integer function NumSegments_(Nav)
  197. ! !USES:
  198. implicit none
  199. ! !INPUT PARAMETERS:
  200. type(Navigator), intent(in) :: Nav
  201. ! !REVISION HISTORY:
  202. ! 22May00 - Jing Guo <guo@dao.gsfc.nasa.gov> initial prototype/prolog/code
  203. ! 1Mar02 - E.T. Ong <eong@mcs.anl.gov> - removed die to prevent crashes.
  204. !EOP ___________________________________________________________________
  205. character(len=*),parameter :: myname_=myname//'::NumSegments_'
  206. NumSegments_=Nav%NumSegments
  207. end function NumSegments_
  208. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209. ! Math and Computer Science Division, Argonne National Laboratory !
  210. !BOP -------------------------------------------------------------------
  211. !
  212. ! !IROUTINE: msize_ - Return the Maximum Capacity for Segment Storage
  213. !
  214. ! !DESCRIPTION:
  215. ! This {\tt INTEGER} query function returns the maximum number of
  216. ! segments for which start and length information can be stored in the
  217. ! input {\tt Navigator} argument {\tt Nav}.
  218. !
  219. ! !INTERFACE:
  220. integer function msize_(Nav)
  221. ! !USES:
  222. implicit none
  223. ! !INPUT PARAMETERS:
  224. type(Navigator),intent(in) :: Nav
  225. ! !REVISION HISTORY:
  226. ! 22May00 - Jing Guo <guo@dao.gsfc.nasa.gov> initial prototype/prolog/code
  227. !EOP ___________________________________________________________________
  228. character(len=*),parameter :: myname_=myname//'::msize_'
  229. msize_=size(Nav%displs)
  230. end function msize_
  231. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  232. ! Math and Computer Science Division, Argonne National Laboratory !
  233. !BOP -------------------------------------------------------------------
  234. !
  235. ! !IROUTINE: VectorLength_ - Return the Navigated Vector's Length
  236. !
  237. ! !DESCRIPTION:
  238. ! This {\tt INTEGER} query function returns the total length of the
  239. ! vector navigated by the input {\tt Navigator} argument {\tt Nav}.
  240. ! Note that the vector length is a quantity the user must have set
  241. ! when {\tt Nav} was initialized. If it has not been set, the return
  242. ! value will be zero.
  243. !
  244. ! !INTERFACE:
  245. integer function VectorLength_(Nav)
  246. ! !USES:
  247. implicit none
  248. ! !INPUT PARAMETERS:
  249. type(Navigator), intent(in) :: Nav
  250. ! !REVISION HISTORY:
  251. ! 26Aug02 - J. Larson <larson@mcs.anl.gov> - initial implementation
  252. !EOP ___________________________________________________________________
  253. character(len=*),parameter :: myname_=myname//'::VectorLength_'
  254. VectorLength_=Nav%VectorLength
  255. end function VectorLength_
  256. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  257. ! Math and Computer Science Division, Argonne National Laboratory !
  258. !BOP -------------------------------------------------------------------
  259. !
  260. ! !IROUTINE: resize_ - Reset the Number of Segments
  261. !
  262. ! !DESCRIPTION:
  263. ! This routine resets the number of segments stored in the input/output
  264. ! {\tt Navigator} argument {\tt Nav}. It behaves in one of two modes:
  265. ! If the optional {\tt INTEGER} input argument {\tt NumSegments} is
  266. ! provided, then this value is taken to be the new number of segments.
  267. ! If this routine is invoked without {\tt NumSegments} provided, then
  268. ! the new number of segments is set as per the result of the Fortran
  269. ! {\tt size()} function applied to the segment table arrays.
  270. !
  271. ! !INTERFACE:
  272. subroutine resize_(Nav, NumSegments)
  273. ! !USES:
  274. use m_stdio, only : stderr
  275. use m_die, only : die
  276. implicit none
  277. ! !INPUT PARAMETERS:
  278. integer,optional,intent(in) :: NumSegments
  279. ! !INPUT/OUTPUT PARAMETERS:
  280. type(Navigator),intent(inout) :: Nav
  281. ! !REVISION HISTORY:
  282. ! 22May00 - Jing Guo <guo@dao.gsfc.nasa.gov> initial prototype/prolog/code
  283. !EOP ___________________________________________________________________
  284. character(len=*),parameter :: myname_=myname//'::resize_'
  285. integer :: m
  286. m=msize_(Nav)
  287. if(present(NumSegments)) then
  288. if(NumSegments > m) then
  289. write(stderr,'(3a,2(i8,a))') myname_, &
  290. ':: FATAL value of argument NumSegments exceeds maximum ', &
  291. ' storage for this Navigator. NumSegments = ',NumSegments, &
  292. ' Maximum storage capacity = ',m,' segments.'
  293. call die(myname_)
  294. endif
  295. Nav%NumSegments=NumSegments
  296. else
  297. Nav%NumSegments=m
  298. endif
  299. end subroutine resize_
  300. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  301. ! Math and Computer Science Division, Argonne National Laboratory !
  302. !BOP -------------------------------------------------------------------
  303. !
  304. ! !IROUTINE: get_ - Retrieve Characteristics of a Segment
  305. !
  306. ! !DESCRIPTION:
  307. ! This multi-purpose query routine can be used to retrieve various
  308. ! characteristics of a given segment (identified by the input
  309. ! {\tt INTEGER} argument {\tt iSeg}) stored in the input {\tt Navigator}
  310. ! argument {\tt Nav}:
  311. ! \begin{enumerate}
  312. ! \item The {\em displacement} of the first element in this segment from
  313. ! the first element of the vector. This quantity is returned in the
  314. ! optional output {\tt INTEGER} argument {\tt displ}
  315. ! \item The {\em number of elements} in this segment. This quantity
  316. ! is returned in the optional output {\tt INTEGER} argument {\tt displ}
  317. ! \item The {\em index} of the first element in this segment This
  318. ! quantity is returned in the optional output {\tt INTEGER} argument
  319. ! {\tt lc}.
  320. ! \item The {\em index} of the final element in this segment This
  321. ! quantity is returned in the optional output {\tt INTEGER} argument
  322. ! {\tt le}.
  323. ! \end{enumerate}
  324. ! Any combination of the above characteristics may be obtained by
  325. ! invoking this routine with the corresponding optional arguments.
  326. !
  327. ! !INTERFACE:
  328. subroutine get_(Nav, iSeg, displ, count, lc, le)
  329. ! !USES:
  330. use m_stdio, only : stderr
  331. use m_die, only : die
  332. implicit none
  333. ! !INPUT PARAMETERS:
  334. type(Navigator), intent(in) :: Nav
  335. integer, intent(in) :: iSeg
  336. ! !OUTPUT PARAMETERS:
  337. integer, optional, intent(out) :: displ
  338. integer, optional, intent(out) :: count
  339. integer, optional, intent(out) :: lc
  340. integer, optional, intent(out) :: le
  341. ! !REVISION HISTORY:
  342. ! 22May00 - Jing Guo <guo@dao.gsfc.nasa.gov> initial prototype/prolog/code
  343. !EOP ___________________________________________________________________
  344. character(len=*),parameter :: myname_=myname//'::get_'
  345. ! Argument sanity check:
  346. if(iSeg > msize_(Nav)) then
  347. write(stderr,'(2a,2(a,i8))') myname_, &
  348. ':: FATAL -- Segment index out of Navigator table bounds, ', &
  349. 'Size of Navigator table = ',msize_(Nav),' iSeg = ',iSeg
  350. call die(myname_)
  351. endif
  352. if(present(displ)) displ=Nav%displs(iSeg)
  353. if(present(count)) count=Nav%counts(iSeg)
  354. if(present(lc)) lc=Nav%displs(iSeg)+1
  355. if(present(le)) le=Nav%displs(iSeg)+Nav%counts(iSeg)
  356. end subroutine get_
  357. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  358. ! Math and Computer Science Division, Argonne National Laboratory !
  359. !BOP -------------------------------------------------------------------
  360. !
  361. ! !IROUTINE: ptr_displs_ - Returns Pointer to the displs(:) Component
  362. !
  363. ! !DESCRIPTION:
  364. ! This pointer-valued query function returns a pointer to the
  365. ! {\em displacements} information (the displacement of the first element
  366. ! of each segment from the beginning of the vector) contained in the
  367. ! input {\tt Navigator} argument {\tt Nav}. It has four basic modes
  368. ! of behavior, depending on which (if any) of the optional input
  369. ! {\tt INTEGER} arguments {\tt lbnd} and {\tt ubnd} are supplied.
  370. ! \begin{enumerate}
  371. ! \item If neither {\tt lbnd} nor {\tt ubnd} is supplied, then
  372. ! {\tt ptr\_displs\_} returns a pointer to {\em all} the elements in
  373. ! the array {\tt Nav\%displs(:)}.
  374. ! \item If both {\tt lbnd} and {\tt ubnd} are supplied, then
  375. ! {\tt ptr\_displs\_} returns a pointer to the segment of the
  376. ! array {\tt Nav\%displs(lbnd:ubnd)}.
  377. ! \item If {\tt lbnd} is supplied but {\tt ubnd} is not, then
  378. ! {\tt ptr\_displs\_} returns a pointer to the segment of the
  379. ! array {\tt Nav\%displs(lbnd:msize)}, where {\tt msize} is the
  380. ! length of the array {\tt Nav\%displs(:)}.
  381. ! \item If {\tt lbnd} is not supplied but {\tt ubnd} is, then
  382. ! {\tt ptr\_displs\_} returns a pointer to the segment of the
  383. ! array {\tt Nav\%displs(1:ubnd)}.
  384. ! \end{enumerate}
  385. !
  386. ! !INTERFACE:
  387. function ptr_displs_(Nav, lbnd, ubnd)
  388. ! !USES:
  389. use m_stdio, only : stderr
  390. use m_die, only : die
  391. implicit none
  392. ! !INPUT PARAMETERS:
  393. type(Navigator), intent(in) :: Nav
  394. integer, optional, intent(in) :: lbnd
  395. integer, optional, intent(in) :: ubnd
  396. ! !OUTPUT PARAMETERS:
  397. integer, dimension(:), pointer :: ptr_displs_
  398. ! !REVISION HISTORY:
  399. ! 22May00 - Jing Guo <guo@dao.gsfc.nasa.gov> - initial prototype/prolog/code
  400. !EOP ___________________________________________________________________
  401. character(len=*),parameter :: myname_=myname//'::ptr_displs_'
  402. integer :: lc,le
  403. ! Argument sanity checks
  404. if(present(lbnd)) then
  405. if(lbnd <= 0) then
  406. write(stderr,'(3a,i8)') myname_, &
  407. ':: FATAL -- illegal lower bound, which must be >= 1.', &
  408. 'lbnd = ',lbnd
  409. call die(myname_)
  410. endif
  411. endif
  412. if(present(ubnd)) then
  413. if(ubnd > msize_(Nav)) then
  414. write(stderr,'(2a,2(a,i8))') myname_, &
  415. ':: FATAL -- illegal upper bound, which must be <= msize(Nav).', &
  416. 'msize(Nav) = ',msize_(Nav),' ubnd = ',ubnd
  417. call die(myname_)
  418. endif
  419. endif
  420. if(present(lbnd) .and. present(ubnd)) then
  421. if(lbnd > ubnd) then
  422. write(stderr,'(2a,2(a,i8))') myname_, &
  423. ':: FATAL -- upper bound, must be >= lower bound.', &
  424. 'Lower bound lbnd = ',lbnd,' Upper bound ubnd = ',ubnd
  425. call die(myname_)
  426. endif
  427. endif
  428. ! End argument sanity checks
  429. if(present(lbnd).or.present(ubnd)) then
  430. lc=lbound(Nav%displs,1)
  431. if(present(lbnd)) lc=lbnd
  432. le=ubound(Nav%displs,1)
  433. if(present(ubnd)) le=ubnd
  434. ptr_displs_ => Nav%displs(lc:le)
  435. else
  436. le=Nav%NumSegments
  437. ptr_displs_ => Nav%displs(1:le)
  438. endif
  439. end function ptr_displs_
  440. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  441. ! Math and Computer Science Division, Argonne National Laboratory !
  442. !BOP -------------------------------------------------------------------
  443. !
  444. ! !IROUTINE: ptr_counts_ - Returns Pointer to counts(:) Component
  445. !
  446. ! !DESCRIPTION:
  447. ! This pointer-valued query function returns a pointer to the
  448. ! {\em counts} information (that is, the number of elements in each
  449. ! of each segment the vector being navigated) contained in the
  450. ! input {\tt Navigator} argument {\tt Nav}. It has four basic modes
  451. ! of behavior, depending on which (if any) of the optional input
  452. ! {\tt INTEGER} arguments {\tt lbnd} and {\tt ubnd} are supplied.
  453. ! \begin{enumerate}
  454. ! \item If neither {\tt lbnd} nor {\tt ubnd} is supplied, then
  455. ! {\tt ptr\_counts\_} returns a pointer to {\em all} the elements in
  456. ! the array {\tt Nav\%counts(:)}.
  457. ! \item If both {\tt lbnd} and {\tt ubnd} are supplied, then
  458. ! {\tt ptr\_counts\_} returns a pointer to the segment of the
  459. ! array {\tt Nav\%counts(lbnd:ubnd)}.
  460. ! \item If {\tt lbnd} is supplied but {\tt ubnd} is not, then
  461. ! {\tt ptr\_counts\_} returns a pointer to the segment of the
  462. ! array {\tt Nav\%counts(lbnd:msize)}, where {\tt msize} is the
  463. ! length of the array {\tt Nav\%counts(:)}.
  464. ! \item If {\tt lbnd} is not supplied but {\tt ubnd} is, then
  465. ! {\tt ptr\_counts\_} returns a pointer to the segment of the
  466. ! array {\tt Nav\%counts(1:ubnd)}.
  467. ! \end{enumerate}
  468. !
  469. ! !INTERFACE:
  470. function ptr_counts_(Nav, lbnd, ubnd)
  471. ! !USES:
  472. use m_stdio, only : stderr
  473. use m_die, only : die
  474. implicit none
  475. ! !INPUT PARAMETERS:
  476. type(Navigator), intent(in) :: Nav
  477. integer, optional, intent(in) :: lbnd
  478. integer, optional, intent(in) :: ubnd
  479. ! !OUTPUT PARAMETERS:
  480. integer, dimension(:), pointer :: ptr_counts_
  481. ! !REVISION HISTORY:
  482. ! 22May00 - Jing Guo <guo@dao.gsfc.nasa.gov>- initial prototype/prolog/code
  483. !EOP ___________________________________________________________________
  484. character(len=*),parameter :: myname_=myname//'::ptr_counts_'
  485. integer :: lc,le
  486. ! Argument sanity checks
  487. if(present(lbnd)) then
  488. if(lbnd <= 0) then
  489. write(stderr,'(3a,i8)') myname_, &
  490. ':: FATAL -- illegal lower bound, which must be >= 1.', &
  491. 'lbnd = ',lbnd
  492. call die(myname_)
  493. endif
  494. endif
  495. if(present(ubnd)) then
  496. if(ubnd > msize_(Nav)) then
  497. write(stderr,'(2a,2(a,i8))') myname_, &
  498. ':: FATAL -- illegal upper bound, which must be <= msize(Nav).', &
  499. 'msize(Nav) = ',msize_(Nav),' ubnd = ',ubnd
  500. call die(myname_)
  501. endif
  502. endif
  503. if(present(lbnd) .and. present(ubnd)) then
  504. if(lbnd > ubnd) then
  505. write(stderr,'(2a,2(a,i8))') myname_, &
  506. ':: FATAL -- upper bound, must be >= lower bound.', &
  507. 'Lower bound lbnd = ',lbnd,' Upper bound ubnd = ',ubnd
  508. call die(myname_)
  509. endif
  510. endif
  511. ! End argument sanity checks
  512. if(present(lbnd).or.present(ubnd)) then
  513. lc=lbound(Nav%counts,1)
  514. if(present(lbnd)) lc=lbnd
  515. le=ubound(Nav%counts,1)
  516. if(present(ubnd)) le=ubnd
  517. ptr_counts_ => Nav%counts(lc:le)
  518. else
  519. le=Nav%NumSegments
  520. ptr_counts_ => Nav%counts(1:le)
  521. endif
  522. end function ptr_counts_
  523. end module m_Navigator