filter based on fields

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf filter based on fields

  • Creator
    Topic
  • #49272
    Rick Pritchett
    Participant

      I am tring to create a proc that will kill a message based on fields PV1 18 and PV1 41.  If PV1 is either “REF” or “RCR” and if PV1 41 is “PRE” the message is killed.  Here is what i have so far:

      proc filterAgiLink { args } {

       global HciConnName

         set mode [keylget args MODE]

         switch -exact — $mode {

      start {

         return “”

      }

      run {

         set mh [keylget args MSGID]

         set dispList

           set msg [msgget $mh]

           set fldSep [string index $msg 3]

           set subSep [string index $msg 4]

           set segList [split $msg r]

           set PV1 [lindex [lregexp $segList {^PV1}] 0]

           set PV1flds [split $PV1 $fldSep]

           set PV1_18 [lindex $PV1flds 18]

        set PV1_41 [lindex $PV1flds 41]

           

        if {{$PV1_41 == “PRE”} || {$PV1_18 == “REF”} || {$PV1_18== “RCR”}} {

           set dispList

        return $dispList

           } else {

               

               return $dispList

           }

        }

        shutdown {

           return “”

        }

           }

        }

    Viewing 9 reply threads
    • Author
      Replies
      • #61323
        Dave Zibble
        Participant

          Here’s an old one that will get you going.  Important thing is the foreach construct for looping through the segments in the message.

          run {

                     keylget args MSGID mh

                     set msg [msgget $mh]

                     set fld_delim [cindex $msg 3]

                     set disp “CONTINUE”

                     # Find PV1 segment, get disch date from it.

                     foreach elem [split $msg “r”] {

               if { [cequal [csubstr $elem 0 3] “PV1”] } {

                                    set pv1_list [split $elem $fld_delim]

                                    set disch_date [lindex $pv1_list 45]

                                         if { $disch_date > 0 } {

                                            set disp “KILL”

                                            break

                                 }

                           }

                     }

        • #61324
          Michael Hertel
          Participant

            Change this line:

            if {{$PV1_41 == “PRE”} || {$PV1_18 == “REF”} || {$PV1_18== “RCR”}} {

            to

            if {[cequal $PV1_41 PRE] && ([cequal $PV1_18 REF] || [cequal $PV1_18 RCR])} {

            Hope this helps,

            -mh

          • #61325
            Rick Pritchett
            Participant

              for some reason i took out the curly brakets around each comparison and it worked.  Anyone now why?

            • #61326
              Greg Eriksen
              Participant

                I think it has to do with variable substitution.  The curly braces would be forcing tcl not to substitute the $ with the actual value of the variable.

                I would pay attention though, to what Michael is recommending above in your use of “ands” (&&) and “ors” (||).

              • #61327
                Steve Carter
                Participant

                  You just need to replace the braces with parentheses:

                  if { ($PV1_41 == “PRE”) || ($PV1_18 == “REF”) || ($PV1_18== “RCR”) } {

                  Steve

                • #61328
                  Anonymous
                  Participant

                    You will need to use the example the Michael gave you.   In the following example:

                    if { ($PV1_41 == “PRE”) || ($PV1_18 == “REF”) || ($PV1_18== “RCR”) }

                    …this will kill the message if ANY of the conditions are met.  So you could have PV1_41 equal to “PRE” and PV1-18 equal to ABC and it would still kill the message.

                    In Michael’s example below:

                    if {[cequal $PV1_41 PRE] && ([cequal $PV1_18 REF] || [cequal $PV1_18 RCR])}

                    …this will kill the message ONLY if PV1_41 ==”PRE”  AND PV1_18 == “REF” or “RCR”

                    Hope this helps….

                  • #61329
                    Charlie Bursell
                    Participant

                      I agree with Michael’s answer with the exception that you should use the string commands now and not the “C” commands.

                      In other words:

                      if {[string equal $PV1_41 PRE] && ([string equal $PV1_18 REF] || [string equal $PV1_18 RCR])}

                      The string commands run several orders of magnitude faster than the old TclX “C” commands

                      You should NEVER use numeric compare in place of string compare (==, !=, etc.).  It is very inefficient and may give an incorrect response.

                      Also, NEVER loop if you can help it!  The lregexp command to get the PV1 segment is MUCH more ergonomic than looping through all of the segments.  FWIW, in place of lregexp which is not a core command you can now use lsearch if you are on Tcl 8.4 (Cloverleaf 5.4.1 or higher)treated as lieteral $PV1_41, not as a variable.

                      As for why the curly braces did not work.  When you quoted with the curly braces the variables were not evaluated.  For example, $PV1_41  was  treated as a literal, not a variable.

                      Just my $0.02 worth

                    • #61330
                      Dave Zibble
                      Participant

                        Just look what you can learn by posting your old Tcl out there!!!

                        (i.e. You’re a rusty old integrator, you don’t read e-mail for comprehension and you better get current on the Tcl shizzle!)

                      • #61331
                        Michael Hertel
                        Participant

                          I had a feeling Charlie was gonna say that. 🙂

                          Somehow I have this mental thing with using “[string equal” when “[cequal” is shorter. (One word instead of two). Too bad we can’t alias commands.

                          As Dave suggests, I too, need to get current (and like it and use it) with the Tcl shizzle.

                        • #61332
                          Rick Pritchett
                          Participant

                            Thanks again for everyones help

                        Viewing 9 reply threads
                        • The forum ‘Cloverleaf’ is closed to new topics and replies.