      SUBROUTINE GET_WACCMFILE(DS_TIME,WACCM_DIR,WACCM_FILE)
      IMPLICIT NONE
      INTEGER DAY,NCHAR,IC,ICC1,ICC2,IYEAR
      CHARACTER*(*) DS_Time,WACCM_DIR,WACCM_FILE
      CHARACTER*25 WACCM_PRE
      CHARACTER*4 YEAR
      CHARACTER*2 MONTH
      CHARACTER*1 BLANK
      CHARACTER*60 DIR
      DATA WACCM_PRE/"wa319_4x5_ref1.cam2.h0zm."/
      DATA BLANK/' '/
      NCHAR = LEN(WACCM_DIR)
      DIR = WACCM_DIR
      DO IC = 1, NCHAR
        ICC1 = IC
        IF(DIR(IC:IC).NE.BLANK) GO TO 1
      ENDDO
 1    DO IC = ICC1, NCHAR
        IF(DIR(IC:IC).EQ.BLANK.OR.DIR(IC:IC).EQ.char(0)) GO TO 2
        ICC2 = IC
      ENDDO
 2    READ(DS_Time,'(A4,I3)') YEAR,DAY
      READ(YEAR,'(I4)') IYEAR
      IF ( (DAY .GE. 1) .AND. (DAY .LE. 31) )THEN
        MONTH='01'
      ELSE IF( (DAY .GT. 31) .AND. (DAY .LE. 59) )THEN
        MONTH='02'
      ELSE IF( (DAY .GT. 59) .AND. (DAY .LE. 90) )THEN  
        MONTH='03'
      ELSE IF( (DAY .GT. 90) .AND. (DAY .LE. 120) )THEN
        MONTH='04'
      ELSE IF( (DAY .GT. 120) .AND. (DAY .LE. 151) )THEN
        MONTH='05'
      ELSE IF( (DAY .GT. 151) .AND. (DAY .LE. 181) )THEN
        MONTH='06'
      ELSE IF( (DAY .GT. 181) .AND. (DAY .LE. 212) )THEN
        MONTH='07'
      ELSE IF( (DAY .GT. 212) .AND. (DAY .LE. 243) )THEN
        MONTH='08'
      ELSE IF( (DAY .GT. 243) .AND. (DAY .LE. 273) )THEN
        MONTH='09'
      ELSE IF( (DAY .GT. 273) .AND. (DAY .LE. 304) )THEN
        MONTH='10'
      ELSE IF( (DAY .GT. 304) .AND. (DAY .LE. 334) )THEN
        MONTH='11'
      ELSE IF( (DAY .GT. 334) .AND. (DAY .LE. 366) )THEN
        MONTH='12'
      ENDIF
      IF(DAY.GT.304.and.IYEAR.GT.2004) THEN
        YEAR='2004'
      ELSEIF(IYEAR.GT.2005) THEN
        YEAR='2005'
      ENDIF
      WACCM_FILE=DIR(ICC1:ICC2)//WACCM_PRE//YEAR//'-'
     $   //MONTH//'.nc'//char(0)
      WRITE(*,'(A)') WACCM_FILE
      RETURN
      END
