ccc f77 pixelxy.f -o pixelxy.e find2.f -L/star/lib `sla_link` --no-second-underscore ~nch/recio/librecio.a /star/lib/libcnf.a /star/lib/libstarmem.a

cccc  f77 pixelxy.f -o pixelxy.e -L/star/lib `sla_link` `cio_link` find2.f
cccc f77 pixelxy.f -o pixelxy.e -L/star/lib `sla_link` -lcio -L/home/scosdev/v034/lib `ndf_link` find2.f

        implicit none
        real rarad,decrad,size,sizey
        real*8 raf,decf,dist,distx,disty,dra,ddec,mindist,c,xpl,ypl,
     >sla_dsep,bepoch,r1950,d1950,dr1950,dd1950,radiff,xi,eta,pldist(4),
     >plx(4),ply(4),platelim,pi,adddist,sortdist(4),slop
        integer proc,equinox,lstring,jf,nsrt,field,fieldstore,i,
     >possfield(4),nofields,irank(4),ifail,order,exist(4),iosp(5),j,
     >status,ios,pnum,gif,jj,datafield,dataedge
        character*75 inname,fitsname,errname
        character string*30,mmname*50,fieldfile*60,numstr*20
        character nostring*30,stem*23,hkfile*70
        real*8 datadist,datax,datay,lowdist,drarad,ddecrad
        character datafile*75,datahk*75,wave*1,signd*1,signr*1
        integer datayes,tf,fail,rihmsf(4),dihmsf(4),wavecode
        character*10 iplate,dataplate
        character*64 surDirN,surDirS,dataDir
        call getenv('SURVEY_DIR_N',surDirN)
        call getenv('SURVEY_DIR_S',surDirN)
        call getenv('SSS_DATA_DIR',dataDir)
        fail=0

        read (5,*)proc
        read (5,'(a)')inname
        read (5,'(a)')fitsname
        read (5,'(a)')string
        read (5,*,err=1,iostat=iosp(1)) equinox
  1     continue
        read (5,*,err=2,iostat=iosp(2)) size,sizey
  2     continue
     
        read (5,'(a)') wave    
        read (5,'(a)') errname 
        read (5,*,err=3,iostat=iosp(3)) gif
  3     continue

        open (66,file=errname,status='new')
        if (equinox.ne.1 .and. equinox.ne. 2) then
        fail=99
        write (66,*)'Invalid value entered for equinox.<br>'
        write (66,*)'Please go BACK and use drop down menu.<br>'
        end if

        if (string .eq.' ' .or. string.eq.'  ' .or.
     > string .eq. '                              ') then
        fail=99
        write (66,*)'Null string entered for coordinates.<br>'
        write (66,*)'Please go BACK and try again.<br>'
        end if   

        if (size .gt. 45.) then
        fail=99
        write (66,*) 'Size requested is greater than 30 arcmin. '
        write (66,*) 'Currently this is not possible.<br> '
        write (66,*) 'If you need a larger single area,' 
        write (66,*) 'please email mar@roe.ac.uk<br>'
        end if        

        if (iosp(2).eq.0 .and. size.lt. 0.1) then
        fail=99
        write (66,*) 'Size requested is less than 0.1 arcmin.<br>'
        write (66,*) 'Please go BACK and enter a larger value.<br> '
        end if
        
        if (wave.ne.'J' .and. wave.ne.'R' .and.
     > wave.ne.'I' .and. wave.ne. 'E' .and. wave.ne. 'O' .and.
     > wave.ne.'B' .and. wave.ne. 'F' .and. wave .ne.'P' .and.
     > wave.ne.'N'  .and. wave .ne.'A') then
        fail=99
        write (66,*) 'Invalid waveband requested.<br>'
        write (66,*) 'Please go BACK and use drop-down menu.<br>'
        end if

        if (gif.ne.0 .and. gif.ne.1) then
        fail=99
        write (66,*) 'Invalid choice entered for GIF option.<br>'
        write (66,*) 'Please go BACK and use drop-down menu.<br>'
        end if

        if (iosp(1).ne.0.or.iosp(2).ne.0.or.iosp(3).ne.0) then
        fail=99
        write (66,*) 'Invalid value(s) entered for size, equinox'
        write (66,*) ' or GIF option(s).<br>'
        write (66,*) 'Please go BACK and check.<br>'
        end if

        nsrt=1
        pi=3.141592654
       
        call sla_dafin(string,nsrt,dra,jf)
        call sla_dafin(string,nsrt,ddec,jf)
          dra=dra*15.
        call sla_dr2tf(2,dra,signr,rihmsf)
        call sla_dr2af(1,ddec,signd,dihmsf)   
        drarad=dra
        ddecrad=ddec
        d1950=ddec
        r1950=dra
        if (equinox .eq. 2) 
     >  call sla_FK54z(dra,ddec,1980D0,r1950,d1950,dr1950,dd1950)
ccc     >  call sla_FK54z(dra,ddec,1980D0,drarad,ddecrad,dr1950,dd1950) 
        if (dra.gt.2.*pi .or. dra.lt.0. .or. 
     >ddec.lt. -pi/2. .or. ddec.gt. pi/2.) then
         fail=99
          write (66,*) 
     >'Please check inputted RA (0 to 24hrs) and/or Dec (-90 to +90)'
          write (66,*) '<br>'
          end if
        if (wave.eq.'J') wavecode=1  
        if (wave.eq.'R') wavecode=2
        if (wave.eq.'I') wavecode=3
        if (wave.eq.'E') wavecode=4
        if (wave.eq.'P' .or. wave.eq.'A' ) wavecode=5
        if (wave.eq.'B') wavecode=6
        if (wave.eq.'F') wavecode=7
        if (wave.eq.'N') wavecode=8
         if (wave.eq.'J' .and. d1950.gt. 0.0555) then
         fail=99
       write (66,*) 'The survey/waveband requested only' 
       write (66,*) 'covers -90 < Dec < +3  B1950 <br>'
       write (66,*) 'Please go BACK and select another survey.<br>'
         end if        
         if (wave.eq.'R' .and. d1950 .gt. 0.0555) then
         fail=99
       write (66,*) 'The survey/waveband requested only' 
       write (66,*) 'covers -90 < Dec < +3  B1950 <br>'
       write (66,*) 'Please go BACK and select another survey.<br>'
         end if        
          if (wave.eq.'I' .and. d1950.gt. 0.0555) then
         fail=99
       write (66,*) 'The survey/waveband requested only' 
       write (66,*) 'covers -90 < Dec < +3  B1950 <br>'
       write (66,*) 'Please go BACK and select another survey.<br>'
         end if        
         if (wave.eq.'E' .and. d1950 .gt. -0.2967) then
         fail=99
       write (66,*) 'The survey/waveband requested only' 
       write (66,*) 'covers -90 < Dec < -17  B1950 <br>'
       write (66,*) 'Please go BACK and select another survey.<br>'
         end if        
         if (wave.eq.'P' .and. d1950 .lt. -0.5672) then
         fail=99
       write (66,*) 'The survey/waveband requested only' 
       write (66,*) 'covers -32.5 < Dec < +90  B1950 <br>'
       write (66,*) 'Please go BACK and select another survey.<br>'
         end if        
         if (wave.eq.'O' .and. d1950 .lt. -0.5672) then
         fail=99
       write (66,*) 'The survey/waveband requested only' 
       write (66,*) 'covers -32.5 < Dec < +90  B1950 <br>'
       write (66,*) 'Please go BACK and select another survey.<br>'
         end if        
         if (wave.eq.'B' .and. d1950 .lt. -0.0555) then
         fail=99
       write (66,*) 'The survey/waveband requested only' 
       write (66,*) 'covers -3 < Dec < +90  B1950 <br>'
       write (66,*) 'Please go BACK and select another survey.<br>'
         end if        
         if (wave.eq.'F' .and. d1950.lt. -0.0555) then
         fail=99
       write (66,*) 'The survey/waveband requested only' 
       write (66,*) 'covers -3 < Dec < +90  B1950 <br>'
       write (66,*) 'Please go BACK and select another survey.<br>'
         end if        
         if (wave.eq.'N' .and. d1950.lt. -0.0555) then
         fail=99
       write (66,*) 'The survey/waveband requested only' 
       write (66,*) 'covers -3 < Dec < +90  B1950 <br>'
       write (66,*) 'Please go BACK and select another survey.<br>'
         end if  
         if (fail.eq.99) then
         close(66)
         stop
         end if         



       slop=4.  
       if (abs(ddecrad) .gt. 85*pi/180.0d0) slop=-2.

       call find2(drarad,ddecrad,size,wave,
     >equinox,datayes,datax,datay,datadist,datafile,
     >dataplate,datahk,datafield,dataedge,slop)
        if (datayes.eq.0) then
       slop=-25.
       call find2(drarad,ddecrad,size,wave,
     >equinox,datayes,datax,datay,datadist,datafile,
     >dataplate,datahk,datafield,dataedge,slop)             
       endif
    

        if (datayes.eq.0) then 
      write (66,*)'The plate(s) covering the requested coordinates '
      write (66,*)'in the waveband/survey selected have not yet '
      write (66,*) 'been scanned. <br> <br>'
      write (66,*) 'Charts showing the status of survey scans available'
      write (66,*) ' on-line can be found under'
      write (66,*)'the survey scanning status page.<br><br>' 
 
        close (66)
        stop
         end if

        open (11,status='new',file=inname)
        write (11,493) proc
        write (11,493) proc
 493    format(i5)
         write (11,494) datafile
 494     format(a75)

        write (11,32) rihmsf(1),rihmsf(2),rihmsf(3),'.',rihmsf(4),
     >signd,dihmsf(1),dihmsf(2),dihmsf(3),'.',dihmsf(4)
 32   format(i2.2,1x,i2.2,1x,i2.2,a1,i2.2,1x,a1,i2.2,1x,i2.2,1x,
     >i2.2,a1,i1)
 31     format (a6)
        write (11,*) equinox
        write (11,*) size,sizey
        write (11,*) wavecode
        if (wave.eq.'P' .or. wave.eq. 'O' .or.  wave.eq. 'A') then
        write (11,798) datafield
        else
        write (11,799) datafield
        end if
 798    format(i4.4)
 799    format (i3.3)
        write (11,*) dataplate
        write (11,800) datax
        write (11,800) datay
 800    format(f7.2)
        write (11,*) dataedge
        write (11,493) proc
        end














