	SUBROUTINE ND_WLCL (idat, gdattm, iret)
	
C************************************************************************
C* ND_WLCL								*
C*									*
C* This subroutine writes out the local section (Section 2) into a text *
C* file from a grib2 message.						*
C*									*
C* ND_WLCL (IDAT, GDATTM, IRET)						*
C*									*
C* Input Parameters:							*
C* 	IDAT (NIDAT)	INTEGER		Local Section			*
C*	GDATTM (2)	CHAR*		Grib message time		*
C*									*
C* Output Parameters:							*
C*	IRET		INTEGER		Return code			*
C**									*
C* Log:									*
C* C. Bailey		6/04	creation into subroutine		*
C************************************************************************
	INTEGER idat (*), numlines, numchars, iret
	CHARACTER line(1000)*300, gdattm(2)*(*), lclfile*128
C------------------------------------------------------------------------
	iret = 0

	numlines = 1
	numchars = 1
	
C Intialize strings

	do x = 1, 1000, 1
	    do y = 1, 300, 1
	        line(x)(y:y) = ' '	
	    end do
	end do
                
C DECODE EACH INTEGER VALUE INTO A CHARACTER AND ADD TO STRING
		 
	do 100 i = 3, idat(1)+2, 1
	    if( idat(i) .eq. 0) then 
C                NEW LINE	    
	         numlines = numlines + 1
	         numchars = 1
            else
	         line(numlines)(numchars:numchars) = CHAR(idat(i))
	         numchars = numchars + 1
	    endif
 100  	continue
 
        lclfile="local_"//gdattm(1)(1:6)//gdattm(1)(8:15)//".txt"   
            
        OPEN (1, file=lclfile)
        
	DO i=0, numlines-1, 1	 
            write(1,40) i, " = ", line(i+1)
 40         format(i3, a3, a300)
 	END DO
 	
        CLOSE (1)      
       
        RETURN
        
        END
