C++*********************************************************************
C
C RADAV.F 
C
C **********************************************************************
C=*                                                                    *
C=* This file is part of:   SPIDER - Modular Image Processing System.  *
C=* SPIDER System Authors:  Joachim Frank & ArDean Leith               *
C=* Copyright 1985-2010  Health Research Inc.,                         *
C=* Riverview Center, 150 Broadway, Suite 560, Menands, NY 12204.      *
C=* Email: spider@wadsworth.org                                        *
C=*                                                                    *
C=* SPIDER is free software; you can redistribute it and/or            *
C=* modify it under the terms of the GNU General Public License as     *
C=* published by the Free Software Foundation; either version 2 of the *
C=* License, or (at your option) any later version.                    *
C=*                                                                    *
C=* SPIDER is distributed in the hope that it will be useful,          *
C=* but WITHOUT ANY WARRANTY; without even the implied warranty of     *
C=* merchantability or fitness for a particular purpose.  See the GNU  *
C=* General Public License for more details.                           *
C=* You should have received a copy of the GNU General Public License  *
C=* along with this program. If not, see <http://www.gnu.org/licenses> *
C=*                                                                    *
C **********************************************************************
C
C  RADAV(LUN1,LUN2)
C
C  IMAGE_PROCESSING_ROUTINE
C
C23456789012345678901234567890123456789012345678901234567890123456789012
C **********************************************************************

        SUBROUTINE RADAV(LUN1,LUN2)

        INCLUDE 'CMBLOCK.INC'
        INCLUDE 'CMLIMIT.INC'

        CHARACTER(LEN=MAXNAM)   ::  FILNAM

C       OPEN INPUT FILE
        MAXIM1 = 0
	CALL OPFILEC(0,.TRUE.,FILNAM,LUN1,'O',IFORM,NSAM1,NROW1,NSLIC1,
     &               MAXIM1,'INPUT1',.FALSE.,IRTFLG)
	IF (IRTFLG .NE. 0) RETURN

        IRMAX  = NSAM1/2  + MOD(NSAM1,2)
        IRMAX2 = NROW1/2  + MOD(NROW1,2)
        IRMAX3 = NSLIC1/2 + MOD(NSLIC1,2)

	IF (NSLIC1 .EQ. 1)THEN
           NSAM2 = MIN0(IRMAX,IRMAX2)
	ELSE
           NSAM2 = MIN0(IRMAX,IRMAX2,IRMAX3)
	ENDIF
        NROW2  = 1
	NSLIC2 = 1
           
C       OPEN AN OUTPUT FILE
        MAXIM2 = 0 
	IFORM  = 1
        CALL OPFILEC(LUN1,.TRUE.,FILNAM,LUN2,'U',IFORM,
     &               NSAM2,NROW2,NSLIC2,
     &  	     MAXIM2,'OUTPUT',.TRUE.,IRTFLG)
	IF (IRTFLG .NE. 0) RETURN

        IRMAX  =  NSAM2
  
        IF (NSLIC1.EQ.1)THEN
           CALL CRCSE1(LUN1,LUN2,NSAM1,NROW1,IRMAX)
        ELSE
           CALL CRCSE3(LUN1,LUN2,NSAM1,NROW1,NSLIC1,IRMAX)
        ENDIF

        END

