ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE_old/src/mdtools/libmdCode/vector_class.F90
(Generate patch)

Comparing trunk/OOPSE_old/src/mdtools/libmdCode/vector_class.F90 (file contents):
Revision 317 by gezelter, Tue Mar 11 23:13:06 2003 UTC vs.
Revision 346 by chuckv, Fri Mar 14 19:51:11 2003 UTC

# Line 19 | Line 19
19   !! @author J. Daniel Gezelter
20   !! @author Charles F. Vardeman II
21   !! @author Matthew Meineke
22 < !! @version $Id: vector_class.F90,v 1.6 2003-03-11 23:13:06 gezelter Exp $, $Date: 2003-03-11 23:13:06 $, $Name: not supported by cvs2svn $, $Revision: 1.6 $
22 > !! @version $Id: vector_class.F90,v 1.8 2003-03-14 19:51:11 chuckv Exp $, $Date: 2003-03-14 19:51:11 $, $Name: not supported by cvs2svn $, $Revision: 1.8 $
23  
24   module Vector_class
25    
# Line 445 | Line 445 | contains
445      
446      whichprop = getPropertyIndex(this, PropName)
447      if (whichprop .eq. 0 ) then
448 <       write(*,*) 'unknown property!'
448 >       write(*,*) 'unknown property: ', PropName
449         pv = 0.0
450      else
451         if (this%PropertyDataType(whichprop) .ne. real_data_type) then
452 <          write(*,*) 'wrong data type for this property!'
452 >          write(*,*) 'Property: ', PropName, " is not real data type."
453            pv = 0.0
454         else
455            pv = this%realElementProperties(id, whichprop)
# Line 465 | Line 465 | contains
465      
466      whichprop = getPropertyIndex(this, PropName)
467      if (whichprop .eq. 0 ) then
468 <       write(*,*) 'unknown property!'
468 >       write(*,*) 'unknown property! ', PropName
469         pv = 0
470      else
471         if (this%PropertyDataType(whichprop) .ne. integer_data_type) then
472 <          write(*,*) 'wrong data type for this property!'
472 >          write(*,*) 'Property! ', PropName, " is not integer data type."
473            pv = 0
474         else
475            pv = this%integerElementProperties(id, whichprop)
# Line 485 | Line 485 | contains
485      
486      whichprop = getPropertyIndex(this, PropName)
487      if (whichprop .eq. 0 ) then
488 <       write(*,*) 'unknown property!'
488 >       write(*,*) 'unknown property! ', PropName
489         pv = .false.
490      else
491         if (this%PropertyDataType(whichprop) .ne. logical_data_type) then
492 <          write(*,*) 'wrong data type for this property!'
492 >          write(*,*) 'Property! ', PropName, " is not logical data type."
493            pv = .false.
494         else
495            pv = this%logicalElementProperties(id, whichprop)
# Line 501 | Line 501 | contains
501      type(Vector), pointer :: this
502      integer :: id, i
503      character(len=*) :: PropName
504 <    
504 >
505      do i = 1, this%propertyCount
506         if (this%PropertyDescriptions(i) == PropName) then
507            id = i
# Line 516 | Line 516 | contains
516      integer, intent(in) :: minCapacity, minPropCap
517      integer :: oldCapacity, oldPropCap
518      integer :: newCapacity, newPropCap
519 <    logical :: resizeFlag = .false.
519 >    logical :: resizeFlag
520  
521 <    oldCapacity = size(this%ElementData)
522 <    oldPropCap = size(this%PropertyDescriptions)
521 >    resizeFlag = .false.
522  
523 + !  first time: allocate a new vector with default size
524 +
525 +    if (.not. associated(this)) then
526 +       this => initialize()
527 +    endif
528 +
529 +    oldCapacity = size(this%ElementData)
530 +    oldPropCap  = size(this%PropertyDescriptions)
531 +    
532      if (minCapacity > oldCapacity) then
533         if (this%capacityIncrement .gt. 0) then
534            newCapacity = oldCapacity + this%capacityIncrement
# Line 531 | Line 539 | contains
539            newCapacity = minCapacity
540         endif
541         resizeFlag = .true.
542 +    else
543 +       newCapacity = oldCapacity
544      endif
545 <
545 >    
546 > !!! newCapacity is not set.....
547      if (minPropCap > oldPropCap) then
548         if (this%PropertyIncrement .gt. 0) then
549            newPropCap = oldPropCap + this%PropertyIncrement
# Line 543 | Line 554 | contains
554            newPropCap = minPropCap
555         endif
556         resizeFlag = .true.
557 +    else
558 +       newPropCap = oldPropCap
559      endif
560 <      
560 >    
561      if (resizeFlag) then
562 <       that = initialize(newCapacity, newPropCap, &
562 >       that => initialize(newCapacity, newPropCap, &
563              this%capacityIncrement, this%PropertyIncrement)      
564         call copyAllData(this, that)
565         deallocate(this)
# Line 563 | Line 576 | contains
576         v2%elementData(i) = v1%elementData(i)
577         do j = 1, v1%propertyCount
578  
579 <          if (v1%PropertyDataType(j) .eq. integer_data_type)  &
579 >          if (v1%PropertyDataType(j) .eq. integer_data_type) &
580                 v2%integerElementProperties(i,j) = &
581                 v1%integerElementProperties(i,j)
582  
# Line 590 | Line 603 | contains
603    function addElement(this) result (id)
604      type(Vector), pointer :: this
605      integer :: id
606 <    call ensureCapacityHelper(this, this%elementCount + 1, this%PropertyCount)
607 <    this%elementCount = this%elementCount + 1
608 <    this%elementData = this%elementCount
609 <    id = this%elementCount
606 >    integer :: error
607 >
608 >    if (.not. associated(this)) then
609 >       call ensureCapacityHelper(this,1,0)
610 >    else
611 >       call ensureCapacityHelper(this, this%elementCount + 1, this%PropertyCount)
612 >    end if
613 >
614 >       this%elementCount = this%elementCount + 1
615 >       this%elementData = this%elementCount
616 >       id = this%elementCount
617 >
618 >
619    end function addElement
620  
621    recursive subroutine setElementPropertyReal(this, id, PropName, PropValue)
# Line 601 | Line 623 | contains
623      integer :: id, i
624      character(len=*), intent(in) :: PropName
625      real( kind = 8 ), intent(in) :: PropValue
626 <    logical :: foundit = .false.
626 >    logical :: foundit
627 >    
628 >    foundit = .false.
629 >
630      ! first make sure that the PropName isn't in the list of known properties:
631 +
632      do i = 1, this%propertyCount
633         if (PropName == this%PropertyDescriptions(i)) then
634            foundit = .true.
635            this%realElementProperties(id,i) = PropValue
636         endif
637      enddo
638 <    
638 >
639      if (.not.foundit) then
640 <       call addPropertyToVector(this, PropName, real_data_type)
641 <       call setElementPropertyReal(this, id, PropName, PropValue)
640 >         call addPropertyToVector(this, PropName, real_data_type)
641 >         call setElementPropertyReal(this, id, PropName, PropValue)
642      endif
643    end subroutine setElementPropertyReal
644  
# Line 621 | Line 647 | contains
647      integer :: id, i
648      character(len=*), intent(in) :: PropName
649      integer, intent(in) :: PropValue
650 <    logical :: foundit = .false.
650 >    logical :: foundit
651 >
652 >    foundit = .false.
653      ! first make sure that the PropName isn't in the list of known properties:
654      do i = 1, this%propertyCount
655         if (PropName == this%PropertyDescriptions(i)) then
# Line 641 | Line 669 | contains
669      integer :: id, i
670      character(len=*), intent(in) :: PropName
671      logical, intent(in) :: PropValue
672 <    logical :: foundit = .false.
672 >    logical :: foundit
673 >
674 >    foundit = .false.
675      ! first make sure that the PropName isn't in the list of known properties:
676      do i = 1, this%propertyCount
677         if (PropName == this%PropertyDescriptions(i)) then
# Line 660 | Line 690 | contains
690      type(Vector), pointer :: this
691      character(len=*), intent(in) :: PropName
692      integer data_type
693 <    call ensureCapacityHelper(this, this%elementCount, this%propertyCount + 1)
694 <    this%propertyCount = this%propertyCount + 1
695 <    this%PropertyDescriptions(this%propertyCount) = PropName
696 <    this%PropertyDataType(this%propertyCount) = data_type
697 <  end subroutine addPropertyToVector
693 >    
694 >     call ensureCapacityHelper(this, this%elementCount, this%propertyCount + 1)
695 >     this%propertyCount = this%propertyCount + 1
696 >     this%PropertyDescriptions(this%propertyCount) = PropName
697 >     this%PropertyDataType(this%propertyCount) = data_type
698 >   end subroutine addPropertyToVector
699    
700    function initialize_0i() result(this)
701      type(Vector), pointer :: this
702 <    nullify(this)
672 <    this = initialize_2i(10, 5)
702 >    this => initialize_2i(10, 5)
703    end function initialize_0i
704  
705    function initialize_1i(nprop) result(this)
706      integer, intent(in) :: nprop
707      type(Vector), pointer :: this
708 <    nullify(this)
679 <    this = initialize_2i(10, nprop)
708 >    this => initialize_2i(10, nprop)
709    end function initialize_1i
710  
711    function initialize_2i(cap, nprop) result(this)
712      integer, intent(in) :: cap, nprop
713      type(Vector), pointer :: this
714 <    nullify(this)
686 <    this = initialize_4i(cap, nprop, 0, 0)
714 >    this => initialize_4i(cap, nprop, 0, 0)
715    end function initialize_2i
716  
717    function initialize_3i(cap, nprop, capinc) result(this)
718      integer, intent(in) :: cap, nprop, capinc
719      type(Vector), pointer :: this
720 <    nullify(this)
693 <    this = initialize_4i(cap, nprop, capinc, 0)
720 >    this => initialize_4i(cap, nprop, capinc, 0)
721    end function initialize_3i
722  
723    function initialize_4i(cap, nprop, capinc, propinc) result(this)
724      integer, intent(in) :: cap, nprop, capinc, propinc
725      integer :: error
726      type(Vector), pointer :: this
727 +
728      nullify(this)
729 <    if (cap < 0) then
729 >
730 >     if (cap < 0) then
731         write(*,*) 'Bogus Capacity:', cap
732         return
733      endif
# Line 706 | Line 735 | contains
735         write(*,*) 'Bogus Number of Properties:', nprop
736         return
737      endif
738 +    
739 +    allocate(this,stat=error)
740 +    if ( error /= 0 ) then
741 +       write(*,*) 'Could not allocate Vector!'
742 +       return
743 +    end if
744  
710    allocate(this, stat=error)
711    if(error .ne. 0) write(*,*) 'Could not allocate Vector!'
712
745      this%initialCapacity = cap
746      this%initialProperties = nprop
747      this%capacityIncrement = capinc
748      this%propertyIncrement = propinc
749 <
749 >
750      allocate(this%elementData(this%initialCapacity), stat=error)
751      if(error /= 0) write(*,*) 'Could not allocate elementData!'
752 <    
752 >
753 >
754      allocate(this%PropertyDescriptions(this%initialProperties), &
755           stat=error)
756      if(error /=  0) write(*,*) 'Could not allocate PropertyDescriptions!'
757  
758 +    allocate(this%PropertyDataType(this%initialProperties), &
759 +         stat=error)
760 +    if(error /=  0) write(*,*) 'Could not allocate PropertyDataType!'
761 +    
762      allocate(this%integerElementProperties(this%initialCapacity, &
763           this%initialProperties), stat=error)
764      if(error /= 0) write(*,*) 'Could not allocate integerElementProperties!'
# Line 733 | Line 770 | contains
770      allocate(this%logicalElementProperties(this%initialCapacity, &
771           this%initialProperties), stat=error)
772      if(error .ne. 0) write(*,*) 'Could not allocate logicalElementProperties!'
773 +
774    end function initialize_4i
775      
776 <
777 <    
740 <
741 <
742 <
776 >  
777 >  
778   end module Vector_class

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines