        SUBROUTINE DF_WINDOW(LUS,CLEAR,REPLOT,BUFFER,XLINLOG,YLINLOG,
     .  XWL,XWU,YWL,YWU,XWL1,YWL1)
C
C----------------------------------------------------------------------
C.IDENTIFICATION: Subroutine DF_WINDOW
C.LIBRARY:        XASGRAPH
C.AUTHOR:         L.Chiappetti - IFCTR Milano
C.VERSIONS:       0.0 - 13 Oct 93 - Prototype
C.                0.1 - 11 Aug 94 - bug fix : missing NTIC arg in NICER_LIN_AXES
C.PURPOSE:        set DeFault WINDOW from environment into common
C.SYNTAX:         CALL DF_WINDOW(LUS,CLEAR,.....)
C.PARAMETERS:     INTEGER LUS(2)       : the graphics logical units
C                 LOGICAL CLEAR        : the overwrite flag
C                 LOGICAL REPLOT       : the replot axis flag
C                 CHARACTER*(*) BUFFER : a work buffer provided by main
C                 CHAR*3 X|YLINLOG     : scale flags (LIN|LOG)
C                 REAL XWL,XWU,YWL,YWU : suggested plot extrema (data range)
C                 REAL XWL1,YWL1       : smallest positive lower extrema
C                                        of the data range (for LOG case)
C----------------------------------------------------------------------
C
        INTEGER       LUS(*)
        LOGICAL       CLEAR,REPLOT
        CHARACTER*(*) BUFFER,XLINLOG,YLINLOG
        REAL         XWL,XWU,YWL,YWU,XWL1,YWL1,XL,YL
        INCLUDE      'pencommon.inc'
C
C       handle default X and Y axis setup
C       using "suggested" ranges XWL to XWU and YWL to YWU
C       (XWL1 and YWL1 are the smallest POSITIVE values to be used
C       in case of log scales)
C       alternatively shall use environment XAXIS, YAXIS
C       and also XSCALE YSCALE
C       the used axis ranges will be set in PENCOMMON
C
C       first determine whether log scales are wished       
C
        CALL GET_GLOBAL_DEFAULT('XSCALE','LIN',XLINLOG)
        CALL GET_GLOBAL_DEFAULT('YSCALE','LIN',YLINLOG)
        CALL Y_SCALE(LUS,XLINLOG,YLINLOG)          
        XL=XWL
        YL=YWL
        IF(XLINLOG.EQ.'LOG')XL=XWL1       
        IF(YLINLOG.EQ.'LOG')YL=YWL1       
        PENCOMMON_YCLIP=YLINLOG.EQ.'LOG'
C
C       for a new page, either automatic mode
C       (derive from data file) or use fixed limits (global variables)
C
        IF(CLEAR.OR.REPLOT)THEN
C          these routines set a preliminary default rounding user guesses
C          these will be used if xyAXIS is set to NICE, they are less
C          rounded then the NICER values used if xyAXIS is AUTO
           CALL NICE_AXES(XL ,XWU,PENCOMMON_XWL,PENCOMMON_XWU)    
           CALL NICE_AXES(YL ,YWU,PENCOMMON_YWL,PENCOMMON_YWU)
C
C          but an explicit setting in the environment overrides
           CALL GET_GLOBAL_DEFAULT('XAXIS','AUTO',BUFFER)
           CALL UPCASE(BUFFER)
           IF(BUFFER.EQ.'AUTO')THEN
              IF(XLINLOG.EQ.'LIN')THEN
C                NTIC=10 for consistency with DF_AXES call to LB_AXIS
                 CALL NICER_LIN_AXES
     .           (XL ,XWU,PENCOMMON_XWL,PENCOMMON_XWU,10)    
              ELSE
                 CALL NICER_LOG_AXES
     .           (XL ,XWU,PENCOMMON_XWL,PENCOMMON_XWU)    
              ENDIF
           ELSEIF(BUFFER.NE.'NICE')THEN
              READ(BUFFER,*)PENCOMMON_XWL,PENCOMMON_XWU             
           ENDIF   
           CALL GET_GLOBAL_DEFAULT('YAXIS','AUTO',BUFFER)
           CALL UPCASE(BUFFER)
           IF(BUFFER.EQ.'AUTO')THEN
              IF(YLINLOG.EQ.'LIN')THEN
C                NTIC=10 for consistency with DF_AXES call to LB_AXIS
                 CALL NICER_LIN_AXES
     .           (YL ,YWU,PENCOMMON_YWL,PENCOMMON_YWU,10)    
              ELSE
                 CALL NICER_LOG_AXES
     .           (YL ,YWU,PENCOMMON_YWL,PENCOMMON_YWU)    
              ENDIF
           ELSEIF(BUFFER.NE.'NICE')THEN
              READ(BUFFER,*)PENCOMMON_YWL,PENCOMMON_YWU
           ENDIF   
        ELSE
C
C          for an overwrite plot use saved values
C
           CALL GET_GLOBAL_DEFAULT('XYAXIS',' ',BUFFER)
C-->       should it be BUFFER//'/' ?
           READ(BUFFER,*)PENCOMMON_XWL,PENCOMMON_XWU,
     .                   PENCOMMON_YWL,PENCOMMON_YWU
        ENDIF
C
C       set the window and save it
C-->    beware ! no Y_ calls between Y_SCALE and Y_WINDOW !!!
C
C-->    there is no protection in plotting routines for negative if scale is log
        CALL Y_WINDOW(LUS,PENCOMMON_XWL,PENCOMMON_XWU,
     .                   PENCOMMON_YWL,PENCOMMON_YWU)    
*       write(*,*)' window called'
C       save for future use
        IF(CLEAR)THEN
        WRITE(BUFFER,'(4(G15.7,'',''))')
     .  PENCOMMON_XWL,PENCOMMON_XWU,PENCOMMON_YWL,PENCOMMON_YWU
*       write(*,*)' going to z_set'
        CALL Z_SET_GLOBAL('XYAXIS',BUFFER) 
*       write(*,*) 'done'
        ENDIF
        RETURN
        END
