#!/bin/csh

set prod1 = "$1"
set prod2 = "$2"

set n1 = `echo $1 | wc -w`
set n2 = `echo $2 | wc -w`

if ($n1 >= $n2) then
    set prodlist = "$prod1"
else
    set prodlist = "$prod2"
endif

set prods = ""

foreach p ($prodlist) 

    set found = 0

    # if both prodlists contain the same exact prod, record pair and go to next
    echo $prod1 | grep $p >> /dev/null
    if ($status == 0) then
        echo $prod2 | grep $p >> /dev/null
        if ($status == 0) then 
            set p1 = $p
            set p2 = $p
            set prods = "$prods $p1,$p2"             
            continue
        endif
    endif

    # else, we have to mix and match

    set opts = "Lt_410 Lt_411 Lt_412 Lt_413 Lt_414 Lt_415 Lt_416"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "Lt_746 Lt_748 Lt_765"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "Lt_869 Lt_868 Lt_865"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "Lr_746 Lr_748 Lr_765"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "Lr_869 Lr_868 Lr_865"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "nLw_410 nLw_411 nLw_412 nLw_413 nLw_414 nLw_415 nLw_416"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "nLw_440 nLw_442 nLw_443 nLw_445"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "nLw_469"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "nLw_486 nLw_488 nLw_489 nLw_490"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "nLw_510 nLw_531"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "nLw_547"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                set found = 1
                break
            endif
        end
        if ($found == 1) then
            set prods = "$prods $p1,$p2"
            continue
        endif
    endif 

    set opts = "nLw_547 nLw_551 nLw_555 nLw_556 nLw_560"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "nLw_670 nLw_678"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "nLw_670 nLw_667"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "Rrs_410 Rrs_411 Rrs_412 Rrs_413 Rrs_414 Rrs_415 Rrs_416"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "Rrs_440 Rrs_442 Rrs_443 Rrs_445"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "Rrs_486 Rrs_488 Rrs_489 Rrs_490"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "Rrs_510 Rrs_531"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "Rrs_547 Rrs_551 Rrs_555 Rrs_556 Rrs_560"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "Rrs_670 Rrs_667 Rrs_671 Rrs_665 Rrs_660"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "rhos_410 rhos_411 rhos_412 rhos_413 rhos_414 rhos_415 rhos_416"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "rhos_440 rhos_442 rhos_443 rhos_445"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "rhos_469"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                set found = 1
                break
            endif
        end
        if ($found == 1) then
            set prods = "$prods $p1,$p2"
            continue
        endif
    endif 

    set opts = "rhos_488 rhos_489 rhos_490"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "rhos_510 rhos_531"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "rhos_547 rhos_551 rhos_555 rhos_556 rhos_560"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "rhos_670 rhos_667"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "rhos_678"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

   set opts = "rhos_748 rhos_765"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

   set opts = "rhos_859"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

   set opts = "rhos_865 rhos_869 rhos_870"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "epsilon eps_78"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "chl_oc3 chl_oc4"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "chl_ocx chlor_a"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "angstrom_510 angstrom_520 angstrom_531 angstrom"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif 

    set opts = "tau_865 tau_869 taua_865 taua_868 taua_869 aot_865 aot_868 aot_869 aot_862"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then 
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then 
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
        continue
    endif 

    set opts = "Kd_490 K_490"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif

    set opts = "a_443_giop a_442_giop a_445_giop"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif

    set opts = "aph_443_giop aph_442_giop aph_445_giop"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif

    set opts = "aph_555_giop aph_551_giop aph_550_giop aph_547_giop"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif

    set opts = "adg_443_giop adg_442_giop adg_445_giop"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif

    set opts = "bb_443_giop bb_442_giop bb_445_giop"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif

    set opts = "bbp_443_giop bbp_442_giop bbp_445_giop"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif

    set opts = "par par2"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif


    set opts = "npp_vgpm npp_eppley"
    echo $opts | grep $p >> /dev/null
    if ($status == 0) then
        foreach o ($opts)
            echo $prod1 | grep $o >> /dev/null
            if ($status == 0) then
                set p1 = $o
                break
            endif
        end
        foreach o ($opts)
            echo $prod2 | grep $o >> /dev/null
            if ($status == 0) then
                set p2 = $o
                break
            endif
        end
        set prods = "$prods $p1,$p2"
    endif



end


echo $prods




