      SUBROUTINE UNIQTOORDER1MASK(ifn,jp,mskcode)

C     UNIQTOORDER TAKES ONE MASK FILE AND CONVERTS THE NUMBERS FROM
C     UNIQUE STATION NUMBER TO THE POSITION NUMBER OF THE STATION
C     IN THE FILE AND WRITES THIS NUMBER TO A TEMPORARY MASK

c     ifn - file ID number for mask
c     jp - probe code
c     mskcodes - Code of what type of mask each present mask is
c                1 - (.s,index,.p) sequential mask
c                2 - (.d, .2) two integer mask
c                3 - (.3) three integer
c                4 - (.4) four integer
c                5 - (.c) one string
c                6 - (.c2) two string
c                7 - (2ri) two reals, one integer
c                8 - (2r2i) two reals, two integers
c                9 - (c2i) one string, two integers

      character*17 charu

      itemp=-1
      idone=0
      icount=0

      call tempfile(itemp)

      do 55 nn=1,20000000

       if ( mskcode .eq. 1) then
        call readmask(ju,ifn,idone)
       elseif ( mskcode .eq. 2 ) then
        call readmask2(ju,ifn,idone,isecond)
       elseif ( mskcode .eq. 3 ) then
        call readmask3(ju,ifn,idone,isecond,ithird)
       elseif ( mskcode .eq. 4 ) then
        call readmask4(ju,ifn,idone,isecond,ithird,ifourth)
       elseif ( mskcode .eq. 5 ) then
        call readcmask(ju,charu,ifn,idone)
       endif

       if ( idone .gt. 0 ) then
        call onefilecloseft(ifn)
        ifn=itemp
        idone=0
        call filerewind(itemp)
        goto 4
       endif

       call uniqthere(jj,ju,jp)
       if ( jj .gt. -1 ) then
        if ( mskcode .eq. 1 ) then
         call writetomask(jj,icount,itemp)
        elseif ( mskcode .eq. 2 ) then
         call writetomask2(jj,icount,itemp,isecond)
        elseif ( mskcode .eq. 3 ) then
         call writetomask3(jj,icount,itemp,isecond,ithird)
        elseif ( mskcode .eq. 4 ) then
         call writetomask4(jj,icount,itemp,isecond,ithird,ifourth)
        elseif ( mskcode .eq. 5 ) then
         call writecmask(jj,charu,itemp)
         icount=icount+1
        endif
       endif

55    continue
4     continue

      return
      end
