SUBROUTINE TMSTO90
!use consts
use global
implicit none  
   
real(DP) :: A2,A1
integer :: iloc,izloc,iz,i
      SAVE

      CALL TSTAV90

      A2=0.
      DO 100 ILOC=1,NLOC
        A1=0.
        IZLOC=MOD(ILOC-1,NZLOC)+1
        IZ=ILAYST(IZLOC)
        
        DO 50 I=2,IMAXR
          A1=A1+TR(ILOC,I)/CINR(I,IZ)
   50   CONTINUE
   
        A1=A1/CRTOT(IZ)
!-------A1: mean TR temperature in subregion ILOC
        A2=A2+A1*VOLOC(ILOC)*CR(IZ)
  100 CONTINUE
      A2=A2/CAPSTO
!-----A2: mean TR temperature in storage volume
      TMSTOR=A2+TSTAVE 
!write(10,*) Tmstor,A2,Tstave,A1,volst
RETURN
END subroutine tmsto90
