       Subroutine sststp(sstupstep)
C       Implicit none									   
       INCLUDE "parmeta"								   
       INCLUDE "parm.tbl"								   
       INTEGER, PARAMETER    :: la=13							   
       INTEGER, PARAMETER    :: imjm=im*jm-jm/2,jam=6+2*(jm-10)  			   
     +      , lp1=lm+1,ltop=1,lbot=lm , lscrch=4*lm+1+la +1  				   
     +      , l1=la+lm+1,l2=la+2*lm+1 , l3=la+3*lm+1,l4=la+4*lm+1			   
       INCLUDE "CTLBLK.comm"								   
       INCLUDE "LOOPS.comm"								   
       INCLUDE "MASKS.comm"								   
       INCLUDE "PHYS.comm"								   
       
       integer,intent(in)	    :: sstupstep					   
       integer  		    :: day						   
       integer  		    :: mon						   
       integer  		    :: yr						   
       integer  		    :: utc						   
       integer  		    :: ma						   
       integer  		    :: mb
       integer                      :: imes
       integer                      :: imes2						   
       real*4			    :: yday						   
       real*4			    :: add						   
       real*4			    :: fa						   
       real*4			    :: fb						   
       integer, dimension(12)	    :: monl
       character(len=10)            :: chardate	
       					   
      iyr=IDAT(3)
      imo=IDAT(1)
      idy=IDAT(2)
      iutc=NTSD*DT/3600     ! chou dt eh 90seg
      CALL getdate(iyr,imo,idy,iutc,yr,mon,day,utc)
       
       data monl /31,28,31,30,31,30,31,31,30,31,30,31/					   
       
       anl=365
       
       If (mod(iyr,4) .eq. 0) then 
       monl(2)=29 
       anl=366
       endif
       
       nmessst=monl(mon)*(86400/DT)
       nanosst=anl*(86400/DT)  ! #  de passos de tempo em um ano							   
C*			   
       yday=day 									   
       ma=mon-1
       If (ma .lt. 1) ma=12
c       print*,"MA",ma,"MON",mon,"DAY",yday 
 
       If ((yday).ge.(float(monl(mon))/2)) ma=mon
       print*, " ma:", ma
       mb=ma+1	 
       
       If (ma .lt. 1) ma=12								   
C       If (mb .gt. 12) mb=1
       
       if(ntsd.eq.1)then
           
CANDRE	   imes=ma
	   imes=initsst
           imes2=imes+1
	   
c	   print*,"IMESSL",imes,"IMESL1",imes2,"DAY",yday

       else
CGAJSST MUDANDO O MES DA LEITURA DA SST NO DIA 15 DE CADA MES PARA CADA dt      
CEsse calculo de imes funciona para uma rodada de no max 2 anos
CANDRE	  imes=int(ntsd/(nanosst+float(nmessst)/2.))*12.+ma          
CANDRE	  imes2=imes+1
	ntsd1=(ntsd+(nmessst/2))
	imes=int(ntsd1/nmessst)+initsst
        imes2=imes+1  
c	print*,"IMESSM",imes,"MON",mon,"NTSD",ntsd,"DAY",yday
CGAJSST FIM 		
       endif									   
       add= int(monl(ma)/2.0)-1    ! correcao para evitar valores negativo e fb
       If (ma.eq.mon) add=-add-2.0							   
       fb=2.0*(yday+add)/float(monl(ma)+monl(mb))					   
       fa=1.0-fb
       If ((ntsd.eq.1).and.(int(yday).eq.16)) Then					   
         sst=sstm(:,:,imes)	
       Else
         sst=fa*sstm(:,:,imes)+fb*sstm(:,:,imes2)
       Endif
       
c       print*,"FFimes  ",imes,"FFimes2",imes2,"NTSD",ntsd
c       print*,"FFMA  ",ma,"FFMB",mb										   
       RETURN										   
      END
