       SUBROUTINE WWEATH(NMONTH,MONTH,NDPRE,NDAYM)
C  PREPARE WORKING TAPE COPY OF COMPRESSED WEATHER
C    NMONTH  NO. OF MONTHS OF DATA IN WORKING COPY(INCL GRND PRECOND)
C    MONTH CONSEC ORDER BY MONTH OF DATA IN WORKING COPY
C    NDPRE  NO. OF PRECONDITIONING DAYS ON TAPE40 (USUALLY 1)
C    NDAYM  NO. OF 24-HR DAYS OF DATA PER MONTH(INCL. PRECOND. DAY)
C
C  TAPE60 WRITE. ECHO OF NAMELIST INPUT
C  TAPE30 READ.  NAMELIST INPUT
C  TAPE40 READ.  ANNUAL COMPRESSED WEATHER FOR A CITY
C                TDB,TWB,WSPD,HORIZ. SOLAR,BAROMETRIC PRESS,MON,DAY,HR
C  TAPE41 WRITE. WORKING COPY OF COMPRESSED WEATHER DATA
C                HAS CONTENTS OF COMMON BLK TYRGND AS 1ST RECORD
C
CMDK TYRGND
CMDK SIMA
C
      DIMENSION X(5),IX(3),MONTH(12),NDAYTOT(12),MNTH(20)
C
C  NMNPRE NO. OF PRECONDITIONING MONTHS
C  IPRINT = 1 TO PRINT WEATHER DATA IN WORKING COPY
C
      DATA IPRINT/0/
      DATA NDAYTOT/31,28,31,30,31,30,31,31,30,31,30,31/
C
      WRITE(60,*) 'SUB.WWEATH COMPRESSED WEATHER PRE-PROCESSING'
      WRITE(60,*) '   NMONTH,MONTH...',NMONTH,(MONTH(I),I=1,NMONTH)
      WRITE(60,*) '   NDAYM,NMNPRE,IPRINT...',NDAYM,NMNPRE,IPRINT
C  NDHRS IS THE NO. OF HOURS IN A MONTH ON THE COMPRESSED WEATHER FILE
C  IT INCLUDES ANY PRECONDITIONING DAY(S). NOTE NDAYM HERE IS NDAYM
C  (IN STRRUN)+NDPRE (IN STRRUN)
C  
      NDHRS=NDAYM*24
      DO 10 I=1,NMNPRE
      MNTH(I)=MONTH(1)-NMNPRE+(I-1)
10    IF(MNTH(I).LT.1)MNTH(I)=MNTH(I)+12
      DO 20 I=1,NMONTH
   20 MNTH(I+NMNPRE)=MONTH(I)
      WRITE(60,*) '  MNTH...',(MNTH(I),I=1,(NMONTH+NMNPRE))
C
C * * * PREPARE WORKING COPY
C
      KMONLST=12
      NTM=0
      DO 100 IMONTH=1,NMONTH+NMNPRE
         KMONTH=MNTH(IMONTH)
         IF(KMONTH.LE.KMONLST)THEN
            KMONLST=0
            REWIND 40
         ENDIF
C * * *    SKIP TO END OF MONTH BEFORE DESIRED MONTH
         IF(KMONTH.GT.1)THEN
C * * *        AVOID HAVING TO REWIND 40 BEFORE EACH SKIP(TO REDUCE READING)
          IF( KMONLST.LT.(KMONTH-1)) THEN
            NHRSI=NDHRS*KMONLST+1
            NHRSE=NDHRS*(KMONTH-1)
            DO 25 J=NHRSI,NHRSE
   25       READ(40,*,END=998)(X(I),I=1,5),(IX(I),I=1,3)
          ENDIF
         ENDIF
C * * *    NOW READ DATA FOR MONTH
         IHR=1
         KMOLS=9999
   30    DO 40 I=1,NDHRS
C  X(1) - TDB -- OUTDOOR DRY BULB TEMP, F
C  X(2) - TWB -- OUTDOOR WET BULB TEMP, F
C  X(3) - WSPED -- WIND SPEED, MILES/HR
C  X(4) - SOLARH -- TOTAL SOLAR RADIATION ON A HORIZONTAL SURFACE,
C         BTU/HR-FT2            
C  X(5) - BARPSI -- BAROMETRIC PRESSURE, PSI
C  IX(1) - MONTH; IX(2) - DAY; IX(3) - HOUR
         READ(40,*,END=997)(X(J),J=1,5),(IX(J),J=1,3)
         IF(NTM.EQ.0)THEN
C * * *  FIND TIME OF YEAR AT MIDMONTH OF FIRST MONTH
C        USED TO INITIALIZE GROUND TEMPS WITH KUSUDA CORRELATION
           KMON=IX(1)
           IF(KMON.EQ.1)THEN
              TIMEYR=14*24.
              MN1=12
           ELSE
              MN1=KMON-1
              NDYRS=0
              DO 32 L=1,MN1
   32         NDYRS=NDYRS+NDAYTOT(L)
              NDYRS=NDYRS+14
              TIMEYR=NDYRS*24.
           ENDIF
C          FIND TIME OF YR(TIMEI) AT FIRST BLDG PRECOND DAY
C          IT FALLS NMNPRE MONTHS AFTER TIMEYR
           TIMEI=TIMEYR
           IF(MN1.EQ.12)THEN
               TIMEI=TIMEI+(NDAYTOT(1)/2+NDAYTOT(2)+NDAYTOT(3)/2)*24.
           ELSE
               TIMEI=TIMEI+(NDAYTOT(KMON)/2)*24.
               MNEXT=KMON+1
               IF(MNEXT.GT.12)MNEXT=1
               TIMEI=TIMEI+NDAYTOT(MNEXT)*24.
               MNEXT=MNEXT+1
               IF(MNEXT.GT.12)MNEXT=1
               TIMEI=TIMEI+(NDAYTOT(MNEXT)/2)*24.
           ENDIF
           WRITE(60,502)TIMEYR,TIMEI
           NTM=1
         ENDIF
         IF(IMONTH.LE.NMNPRE)THEN
           WRITE(41,500)(X(J),J=1,5),(IX(J),J=1,3)
           IF(IPRINT.EQ.1)WRITE(60,500)(X(J),J=1,5),(IX(J),J=1,3)
C              WRITE SOLAR DATA ON TAPE19 IF PAST GRND PRECOND DAYS         
C              NOTE: SKIP 1ST PRECOND DAY EACH MONTH(IT IS SAME AS 2ND )
         ELSE
           IF(NDPRE.GT.0)THEN
             IF(IDY.GE.NDPRE.AND.KMO.EQ.KMOLS)THEN
               WRITE(41,500)(X(J),J=1,5),(IX(J),J=1,3)
             ENDIF
           ELSE
             WRITE(41,500)(X(J),J=1,5),(IX(J),J=1,3)
           ENDIF
           SOLARH(IHR)=X(4)
           IHR = IHR + 1
           IF(IHR.EQ.25)THEN
             IF(KMO.NE.KMOLS)IDY=0
             IDY=IDY+1
             IF(IDY.GT.NDPRE)THEN
               WRITE(19,534)KMO,KDY
               WRITE(19,533)(SOLARH(IHR),IHR=1,24)
             ENDIF
             IHR=1
             KMOLS=KMO
           ENDIF
           KMO=IX(1)
           KDY=IX(2)
         ENDIF
   40   CONTINUE
        KMONLST=KMONTH
  100 CONTINUE
      CLOSE(40)
C     ADD THE FIRST HOUR OF NEXT DAY TO FILE FOR COMPATIBILIBY IN MAIN
      IX(2)=IX(2)+1
      IX(3)=0
      WRITE(41,500)(X(J),J=1,5),(IX(J),J=1,3)
      IF(IPRINT.EQ.1)WRITE(60,500)(X(J),J=1,5),(IX(J),J=1,3)
      REWIND 41
      REWIND 19
      RETURN
C 996 STOP 'WWEATH:EOF ON TAPE30!!'
  997 STOP 'WWEATH:EOF ON TAPE40 BELOW LABEL 30!!'
  998 STOP 'WWEATH:EOF ON TAPE40 ABOVE LABEL 30!!'
  500 FORMAT((1X,3(F5.1,2X),F6.1,2X,F6.2,2X,3(I2,3X)))
  501 FORMAT(' SUB.WWEATH:  KMONTH= ',I5,' NDHRS= ',I5)
  502 FORMAT(1X,'HOUR OF YR AT START OF GROUND PRECOND= ',F12.5/
     +1X,'HOUR OF YR AT FIRST BLDG PRECOND DAY= ',F12.5)
  533 FORMAT(1X,6G13.5/1X,6G13.5/1X,6G13.5/1X,6G13.5)
  534 FORMAT(1X,2I7)
      END
