HPF 80 Characters per line to LCR 76 Characters per line

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf HPF 80 Characters per line to LCR 76 Characters per line

  • Creator
    Topic
  • #53269
    Mary Kobis
    Participant

      Before I start inventing a new text editor, is anyone willing to share a tcl that will reformat a transcribed report from HPF to LCR. The new twist is that I need to keep the paragraphing. Today we have a tcl in place that will place a tilde before the overage word if the line is over 76 characters.

      When displayed in Siemens LCR the overage word is on a line by its self. It may occur in a middle of a sentence. When this happens it makes the entire document look very unprofessional.

      My first pass on the document would be to identify the paragraphs by a few rules we found (I know more will show up) and then a second pass to take the paragraph and realign to 76 characters. This may create a new obx or extend an existing obx.  Should be fun!… Any help is appreciated. Thanks, Mary.

    Viewing 3 reply threads
    • Author
      Replies
      • #77106
        James Cobane
        Participant

          Mary,

          Not sure what platform you are running, but in AIX there is the “fmt” command that allows you to reformat text to a specified width per line; i.e.

          echo “This is a line of text that I am specifying to be only 20 characters per line” | fmt -20

          This is a line of

          text that I am

          specifying to be

          only 20 characters

          per line

          You could potientially run your text through this command via an exec statement within a proc.  There may be a native tcl command to do this, but I’m not aware of it.

          Hope this helps.

          Jim Cobane

          Henry Ford Health

          Jim Cobane

        • #77107
          Mary Kobis
          Participant

            Thanks Jim! I think it will be very useful. We are on AIX 6 and CL 5.8. Mary

          • #77108
            Robert Kersemakers
            Participant

              Hi Mary,

              I have had a similar situation: we have medical results in a Word-document (a letter from the specialist to the family doctor), that needs to be transformed into EDIFact messages, which is a flat-file format where all the text lines are limited to 72 characters. As in your case, new paragraphs and tabs did not show well. I did a lot of ‘parsing’ to get a reasonable result, but it will never be perfect.

              One of the first things I made was a proc to reformat the text to a specified number of characters per line, without breaking words:

              Code:

              proc orbis_split_tekst { tekst {lengte 80}} {

               # This procedure checks whether (a part of) an additional LAB-text is longer than $lengte characters
               # If so, this text is split into separate parts; the list of parts is returned.

              set returnlist {};

               if {[string length $tekst] > $lengte} {

                 # String is te lang: opsplitsen in woorden.
                 set woordlist [split $tekst ” “];

                 # Tevens wordt er een lege ‘nieuwe tekst’ aangelegd
                 set newtekst “”;

                 # Alle woorden worden nu doorlopen
                 foreach woord $woordlist {

                   if { [clength $newtekst] == 0} {
                     # Eerste woord: gewoon toevoegen (zonder spatie) aan ‘newtekst’
                     set newtekst $woord;

                   } else {
                     # Indien er een x0e (andere representatie van .br) volgt: nieuwe regel
                     if {[cequal $woord x0e]} then {
                       set returnlist [lappend returnlist $newtekst];
                       set newtekst “”;

                     } else {
                       # Nu wordt de ‘nieuwe’ lengte bepaald: lengte ‘woord’ + lengte ‘nieuwe tekst’ + 1 (spatie)
                       set nl [expr [clength $woord] + [clength $newtekst] + 1];
                       
                       # Als ‘nieuwe’ lengte groter dan $lengte, dan wordt de ‘newtekst’ aan de ‘returnlist’ toegevoegd
                       if {$nl > $lengte} {
                         set returnlist [lappend returnlist $newtekst];
                         set newtekst $woord;
                       } else {
                         # Anders wordt ‘woord’ aan ‘newtekst’ (met een spatie) toegevoegd
                         set newtekst [string trim [cconcat $newtekst ” ” $woord]]
                       };
                     };
                   };
                 };
                 # De laatste ‘newtekst’ wordt nog aan de ‘returnlist’ toegevoegd.
                 lappend returnlist $newtekst;
               } else {
                 # Hele tekst kan aan returnlist worden toegevoegd
                 if {[string length $tekst] > 0} {
                   lappend returnlist $tekst;
                 }
               };

               return $returnlist;

              }

              Documentation in Dutch though…

              Use the proc like this:

              Code:

              set lpostekst [orbis_split_tekst  $postekst 132]

              As with most things, if I look at this proc now, I’m wondering what I’m doing at some lines. Especially the line ‘set returnlist [lappend returnlist $newtekst]’…

              Hope you can do something with this.

              Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

            • #77109
              Mary Kobis
              Participant

                Thank you Robert and James. I have coded the first proc to identify the paragraphs in the messages (OBX5). I replaced OBX4 (not being used) with a counter and sub-counter so I can track when a paragraph starts and ends. It is not perfect but it seems as though it will get most of them. Now I can evaluate each paragraph and use logic (which we have and Robert and James have supplied) to create the finished report.

                Thank you both for some great ideas! Mary

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