501
502 class(TimeArraySeriesType), intent(inout) :: this
503 integer(I4B), intent(in) :: nvals
504 real(DP), dimension(nvals), intent(inout) :: values
505 real(DP), intent(in) :: time0
506 real(DP), intent(in) :: time1
507
508 integer(I4B) :: i
509 real(DP) :: area, currTime, nextTime, ratio0, ratio1, t0, &
510 t01, t1, timediff, value, value0, value1, valuediff
511 logical :: ldone
512 type(ListNodeType), pointer :: precNode => null()
513 type(ListNodeType), pointer :: currNode => null(), nextnode => null()
514 type(TimeArrayType), pointer :: currRecord => null(), nextrecord => null()
515 class(*), pointer :: currObj => null(), nextobj => null()
516
51710 format('Error encountered while performing integration', &
518 ' for time-array series "', a, '" for time interval: ', &
519 g12.5, ' to ', g12.5)
520
521 values = dzero
522 value = dzero
523 ldone = .false.
524 t1 = -done
525 call this%get_latest_preceding_node(time0, precnode)
526 if (associated(precnode)) then
527 currnode => precnode
528 do while (.not. ldone)
529 currobj => currnode%GetItem()
530 currrecord => castastimearraytype(currobj)
531 currtime = currrecord%taTime
532 if (currtime < time1) then
533 if (.not. associated(currnode%nextNode)) then
534
535 if (.not. this%read_next_array()) then
536 write (errmsg, 10) trim(this%Name), time0, time1
537 call store_error(errmsg)
538 call store_error_unit(this%inunit)
539 end if
540 end if
541 if (associated(currnode%nextNode)) then
542 nextnode => currnode%nextNode
543 nextobj => nextnode%GetItem()
544 nextrecord => castastimearraytype(nextobj)
545 nexttime = nextrecord%taTime
546
547
548 if (currtime >= time0) then
549 t0 = currtime
550 else
551 t0 = time0
552 end if
553 if (nexttime <= time1) then
554 t1 = nexttime
555 else
556 t1 = time1
557 end if
558
559
560 t01 = t1 - t0
561 select case (this%iMethod)
562 case (stepwise)
563 do i = 1, nvals
564
565 value0 = currrecord%taArray(i)
566 area = value0 * t01
567
568 values(i) = values(i) + area
569 end do
570 case (linear)
571 do i = 1, nvals
572
573 timediff = nexttime - currtime
574 ratio0 = (t0 - currtime) / timediff
575 ratio1 = (t1 - currtime) / timediff
576 valuediff = nextrecord%taArray(i) - currrecord%taArray(i)
577 value0 = currrecord%taArray(i) + ratio0 * valuediff
578 value1 = currrecord%taArray(i) + ratio1 * valuediff
579 area = 0.5d0 * t01 * (value0 + value1)
580
581 values(i) = values(i) + area
582 end do
583 end select
584 else
585 write (errmsg, 10) trim(this%Name), time0, time1
586 call store_error(errmsg)
587 call store_error('(Probable programming error)', terminate=.true.)
588 end if
589 else
590
591 ldone = .true.
592 end if
593
594
595 if (t1 >= time1) then
596 ldone = .true.
597 else
598 if (.not. associated(currnode%nextNode)) then
599
600 if (.not. this%read_next_array()) then
601 write (errmsg, 10) trim(this%Name), time0, time1
602 call store_error(errmsg)
603 call this%parser%StoreErrorUnit()
604 end if
605 end if
606 if (associated(currnode%nextNode)) then
607 currnode => currnode%nextNode
608 else
609 write (errmsg, 10) trim(this%Name), time0, time1
610 call store_error(errmsg)
611 call store_error('(Probable programming error)', terminate=.true.)
612 end if
613 end if
614 end do
615 end if
616
617 if (this%autoDeallocate) then
618 if (associated(precnode)) then
619 if (associated(precnode%prevNode)) then
620 call this%DeallocateBackward(precnode%prevNode)
621 end if
622 end if
623 end if