SUBROUTINE chkomg
  !
  ! $Author: CPTEC $
  ! $Date: 2000/02/24 13:15:43 $
  ! $Revision: 1.0 $
  ! 
  ! Code converted using TO_F90 by Alan Miller
  ! Date: 2000-02-17  Time: 13:09:10
  ! 
  !     ******************************************************************
  !     *                                                                *
  !     *       ROUTINE FOR WRITING TEMPORARY FILE FOR ETA POST.         *
  !     *                                                                *
  !     ******************************************************************
  IMPLICIT NONE
  REAL,PARAMETER	:: d00=.0,d01=.01,h2=2.0
  INTEGER,PARAMETER	:: nstat=1000
  REAL,PARAMETER	:: cp=1004.6,dtr=1.74532925E-2
  INCLUDE "parmeta.f90"
  INTEGER,PARAMETER	:: lda=lm+9,la=13
  !   warning -->  IF LM.GT.16 THEN SET LDA=LM+9
  INTEGER,PARAMETER	:: jam=6+2*(jm-10),imjm=im*jm-jm/2,lm1=lm-1,lp1=lm+1
  INTEGER	:: i,j,lmhk,l,ier,n
  REAL	:: tll1,times 
  INCLUDE "outfil.f90"
  INCLUDE "ctlblk.f90"
  INCLUDE "loops.f90"
  INCLUDE "masks.f90"
  INCLUDE "mapot.f90"
  INCLUDE "vrbls.f90"
  INCLUDE "contin.f90"
  INCLUDE "prfhld.f90"
  CHARACTER (LEN=32) :: label
  CHARACTER (LEN=4) :: resthr
  !
  !  ON FIRST ENTRY INITIALIZE THE OUTPUT FILE TAG TO ZERO
  !  AND READ IN STATION LIST
  !
  IF(ntsd == 1)THEN
     itag=0
     !
     !  READ PROFILE STATION INFORMATION.
     !
     CALL stalst(nstat,idstn,stnlat,stnlon,  &
          numsta,ihindx,jhindx,ivindx,jvindx,kclass)
     WRITE(list,20)numsta
20   FORMAT('CHKOMG:  NUMBER OF PROFILE STATIONS ',i5)
     WRITE(list,30)(idstn(n),stnlat(n)/dtr,stnlon(n)/dtr  &
          ,                ihindx(n),jhindx(n),ivindx(n),jvindx(n)  &
          ,                kclass(n),n=1,numsta)
30   FORMAT(2X,i5,2F8.2,4I8,i4)
     DO n=1,numsta
        i=ihindx(n)
        j=jhindx(n)
        lmhk=lmh(i,j)
        tll1=t(i,j,lmhk)
        tlmin(n)=tll1
        tlmax(n)=tll1
     END DO
  END IF
  !
  !  CHECK IF WE ARE GOING TO DO THE HOURLY PROFILES
  !
  times=(ntsd-1)*dt
  IF((ntsd == nshde).OR. (MOD(times,3600.) == 0.).OR.  &
       (MOD(times,3600.) > 3600.-dt)) THEN
     !
     !  PUT OMEGA AT STATION LOCATIONS INTO HOLD ARRAY FOR FUTURE USE
     !
     DO n=1,numsta
        DO l=1,lm
           i=ihindx(n)
           j=jhindx(n)
           IF(rtop(i,j,l) > 1.e-12) omghld(n,l)=omgalf(i,j,l)*cp/(rtop(i,j,l)*dt)
        END DO
     END DO
     !
     !  IF FORECAST TIME IS NOT OUTPUT TIME, EXIT ROUTINE.
     !
     IF(ntsd /= nshde)RETURN
     !
     !  CREATE NAME FOR RESTART FILE.
     !
     itag=ntsd/tsph+0.5
     CALL getenv("tmmark",resthr)
     IF(resthr == '    ')THEN
     print*,' tmmark empty:', resthr
        WRITE(rstfil,100)itag
100     FORMAT('restrt',i2.2)
     ELSE
     print*,' tmmark :', resthr
        WRITE(rstfil,105)itag,resthr
105     FORMAT('restrt',i2.2,'.',a4)
     END IF
     !
     !  OPEN UNIT TO RESTART FILE.
     !
     lrstrt=8
     CLOSE(lrstrt)
     !      CALL ASNUNIT(LRSTRT,'-F cos -C ascii -N ibm',IER)
     ier=0
     IF(ier /= 0) WRITE(list,*)'CHKOMG:  ASNUNIT ERROR IER=',ier
     OPEN(lrstrt,FILE=rstfil,FORM='UNFORMATTED')
     !
     !  WRITE DATE AND TIMESTEP INFORMATION TO RESTART FILE.
     !
     label='OMEGA-ALPHA*DT/CP'
     WRITE(lrstrt)run,idat,ihrst,ntsd,label
     !
     !  WRITE ARRAYS NEEDED TO COMPUTE PRESSURE VERTICAL VELOCITY.
     !
     WRITE(lrstrt)pd,res
     DO  l=1,lm
        WRITE(lrstrt)((omgalf(i,j,l),i=1,im),j=1,jm)
     END DO
     RETURN
  END IF
END SUBROUTINE chkomg
