        subroutine tempsearch(ifile,name,dirname)
	include 'Online.cmm'
	integer system
	character*40 name
	character*40 dirname
	character*2 mn
	character*19 jaar,maand
	character*40 dirnames(10)
        character*50 fname
	character*80 dname,wname
	character*80 gname
	character*80 string
	character*120 pname
C--
C make possible dirnames
C--
	if (idatum.gt.20010000 .and. idatum.lt.20020000) then
	  jaar='Year2001'
	  imaand=idatum-20010000
	elseif (idatum.gt.20020000 .and. idatum.lt.20030000)
	  jaar='Year2002'
	  imaand=idatum-20020000
	elseif (idatum.gt.20030000 .and. idatum.lt.20040000)
	  jaar='Year2003'
	  imaand=idatum-20030000
	elseif (idatum.gt.20040000 .and. idatum.lt.20050000)
	  jaar='Year2004'
	  imaand=idatum-20040000
	else
	  jaar='Year2005'
	  imaand=idatum-20050000
	endif

	imaand=imaand/100
	write(mn,1234)imaand
 1234	format('I2')
	maand='Mon'//mn
	
	dirnames(1)=jaar//maand
	dirnames(2)=jaar
	print *,'construct dirname 1:',dirname(1)
	print *,'construct dirname 2:',dirname(2)
	do i=1,2
	  pname='cd /projects/MDT/Data/ChamberTemp/'//dirnames(i)
         if (name(1:2).eq.'En') then
	  pname='cd /projects/MDT/Data/Environment/'//dirnames(i)
	 endif
          dname='/project/atlas/BOL/BOLTEMP/'//name
          wname='/project/atlas/BOL/BOLTEMP/'//'tempfile'
          fname='get '//name
          gname=fname//' tempfile'
	  open(29,file='stemp.exe')
	    write(29,*)'open paling.nikhef.nl'
            write(29,*)'user MDToper BOLroom'
            write(29,*)pname
            write(29,*)'lcd /project/atlas/BOL/BOLTEMP'
            write(29,*)gname 
            write(29,*)'bye'
	  close(29)
C if not there ftp file
	  close(ifile)
          istat = system
     +      ('rm /project/atlas/BOL/BOLTEMP/tempfile')
          istat = system ('ftp -n < gettemp.exe')
          istat = system 
     +      ('chmod g+w /project/atlas/BOL/BOLTEMP/tempfile')
          print *, 'ftp ended with status ', istat
	  open(ifile,file=wname)
	  read(ifile,'(a)',ERR=199,END=199)string
          rewind(ifile)
          goto 200
C if not exist give message
 199	print *,' Temp file does not yet  ',iname
	enddo
 200	continue
        end


