Add new segment after the last OBX

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Add new segment after the last OBX

  • Creator
    Topic
  • #50225
    Femina Jaffer
    Participant

    Hello Everyone,

    I am having great difficulty accomplishing something that should not be too hard – but, I cannot in the life of me figure out what I am doing wrong.

    I need to add a new hard coded OBX segment after the VERY last OBX segment if a condition is met (if $flg is P).  I don’t know where or how I should do this?  I attempted setting a new variable with the new OBX and added an if condition, but it did not work.  So, I have removed it.

    The segment to add is :

    OBX|$OBX_count||CULTSTAT|||||P[format %c 13]

    I have attached the code, and also have a snippet below:

                                     set OBX [lindex $line 3]

                           set OBXSplit [lindex [split $OBX ^] 0]  

                                     set ABFlg [lindex [split [lindex $line 3] ^] 1]

                                     set Flg [lindex [split $ABFlg “*”] 1]

                                     set Flg [string trimright $Flg]

                                   

                                     if {$Flg !=”P”} {

                                            append OBXsegs OBX|$OBX_count||||[lindex $line 3][format %c 13]

                                     } else {

                                           

                                             append OBXsegs OBX|$OBX_count||||$OBXSplit[format %c 13]

                                            }                                          

                                             incr OBX_count +1

                                         

                                                                 

                     }

                    incr DSP_count +1

                  }

           }

     }

    append out OBR|1|$OBR2||$OBR4_1^|||$OBR7|||||||||$physID||||||||$OBR24|$OBR25|[format %c 13]  

    append out $OBXsegs

     return $out

    }

    Thank you for all your help.

Viewing 8 reply threads
  • Author
    Replies
    • #65260
      Tom Rioux
      Participant

      Femina,

      The script you downloaded is 0 bytes.   You may want to try again.

      Thanks…

      Tom Rioux

    • #65261
      Femina Jaffer
      Participant

      Thank you Tom, for pointing this out!  Here it is again.

    • #65262
      Jim Kosloskey
      Participant

      Famina,

      I would do this in an Xlate – if you have one.

      email: jim.kosloskey@jim-kosloskey.com

    • #65263
      Steve Carter
      Participant

      Without reading through your code, you should be able to make something like this work:

      set segIndex -1

      set addOBX 0

      foreach seg $segList {

         incr segIndex

         # Everytime you come across an OBX, set ‘obxIndex’ to $segIndex

         # At the end of the proc, this will give you the index of the last OBX

         # in the message.

         #

         # Determine if you need to add extra OBX.  If so, do the following:

         # set addOBX 1

         # Create the new OBX and place the value in ‘newOBXData’

         # Do whatever you need to do with the other segments in the message

             

      }

      # If you need the extra OBX, insert it into whatever your new segList variable maybe

      if { $addOBX } {

         incr obxIndex

         set newSegList [linsert $newSegList $obxIndex $newOBXData]

      }

      There are many ways to accomplish something like this.  This is just one.

      Hope this helps.

      Steve

    • #65264
      Tom Rioux
      Participant

      Maybe I’m not understanding what you are asking but could you just set your extra OBX to a variable….say “extra_obx”  Then modify your code as:

      append OBXsegs $extra_obx  

      append out $OBXsegs

      Let me know if this is what you are looking for?

      Tom Rioux

    • #65265
      Femina Jaffer
      Participant

      Thanks for all the responses.  I will give them some thought.

      Tom,

      I tried exactly as you suggested before posting, but that didn’t do a thing.  It was actually ignoring the new variable.

      Jim,

      I am not currently using an Xlate.  We are just modifying an existing code in place to address this matter.

      Thanks again.

    • #65266
      Charlie Bursell
      Participant

      I didn’t really look at your code but assuming you have Tcl 8.4 (CL 5.4.1+) this is easy.

      Assume all of your segments are in a lis, segList.  Also assume you have built the extra OBX segment in a variable name OBX

      # First get a list of locations for all OBX segments

      set obxLocs [lsearch -all -regexp $segList {^OBX}]

      # Now get the last location

      set lastLoc [lindex $obxLocs end]

      # Incement this location so you insert after last

      incr lastLoc

      $ Now simply insert in the list

      set segList [linsert $segList $lastLoc $OBX]

      Piece of cake  😀

    • #65267
      Gary Atkinson
      Participant

      If you had a xlate to use you could use the MATH function and add 1 to your variable.

    • #65268
      Femina Jaffer
      Participant

      Thank you all for your replies and for the many helpful suggestions.  I apologize for not responding sooner, as I had been out of the country and just returned.

      I finally did get it to work, and the problem was that a variable I had set was not set in the correct place; it had to be defined globally or out of the loop.  

      Thank you Steve Carter for sending me a script to follow, this was very helpful indeed.

      Again, thank you all for always coming thru for me!

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

Forum Statistics

Registered Users
5,042
Forums
28
Topics
9,200
Replies
34,023
Topic Tags
267