Module Simula

Class RTS_Imagefile

All Implemented Interfaces:
Runnable
Direct Known Subclasses:
RTS_Directfile, RTS_Infile, RTS_Outfile

public class RTS_Imagefile extends RTS_File
System class Imagefile.

The (file) class "imagefile" defines the common attributes for all image- oriented files.

      file class imagefile;
           begin text image;
              procedure setpos(i);  integer i;  image.setpos(i);
              integer procedure pos;     pos    := image.pos;
              Boolean procedure more;    more   := image.more;
              integer procedure length;  length := image.length;
           end imagefile;
 

The individual logical unit of an external file associated with an imagefile is called an "external image". Each external image is an an ordered sequence of characters.

The variable "image" is used to reference a text frame which acts as a buffer, in the sense that it contains the external image currently being processed.

The procedures "setpos", "pos", "more" and "length" are introduced for reasons of convenience.

The three standard subclasses of imagefile are "infile" (sequential input file), "outfile" (sequential output file) and "directfile" (bidirectional direct file). In addition, "printfile", a standard subclass of class outfile, is available. It represents a line printer oriented file.

Link to GitHub: Source File.

Author:
SIMULA Standards Group, Øystein Myhre Andersen
  • Field Details

    • image

      public RTS_TXT image
      The image attribute of this _Imagefile.
    • _ENDFILE

      protected boolean _ENDFILE
      The variable ENDFILE. It is true when the file is closed or when an image with location greater than "lastloc" has been input (through "inimage"). It is set after each "inimage" statement. The procedure "endfile" returns the current value.
  • Constructor Details

    • RTS_Imagefile

      public RTS_Imagefile(RTS_RTObject SL, RTS_TXT FN)
      Create a new _Imagefile.
      Parameters:
      SL - staticLink
      FN - file name
  • Method Details

    • _STM

      public RTS_Imagefile _STM()
      Description copied from class: RTS_RTObject
      Method representing the Statements in this Block
      This method is virtual and must be redefined in blocks.
      Overrides:
      _STM in class RTS_File
      Returns:
      a pointer to this _RTObject
    • setpos

      public void setpos(int p)
      Set pos indikator in image.
      Parameters:
      p - new pos in image
    • pos

      public int pos()
      Returns the image's pos.
      Returns:
      the image's pos
    • more

      public boolean more()
      Returns the image's more.
      Returns:
      the image's more
    • length

      public int length()
      Returns the image's length.
      Returns:
      the image's length
    • outimage

      public void outimage()
      Procedure outimage.

      This method is virtual and may be redefined in subclasses.

      Throws:
      RTS_SimulaRuntimeError - if no redefinition is available
    • outchar

      public void outchar(char c)
      Procedure outchar.
       procedure outchar(c); character c;
       begin
          if not more then outimage;
          image.putchar(c)
       end outchar;
       

      The procedure "outchar" stores a character in the POS position of "image". If "more" is false, "outimage" is called first.

      Parameters:
      c - the character to output
    • _FIELD

      private RTS_TXT _FIELD(int w)
      Utility procedure _FIELD.
        text procedure FIELD(w); integer w;
            if w>length then error("..." ! Item too long; )
            else begin
               if pos+w-1 > length then outimage;
               FIELD :- image.sub(pos,w);
               setpos(pos+w)
            end FIELD;
       
      See outint(int,int)
      Parameters:
      w - the width of the field.
      Returns:
      the resulting text field
      Throws:
      RTS_SimulaRuntimeError - if Item is too long
    • outint

      public void outint(int i, int w)
      Procedure outint.

      The procedures "outint", "outfix", "outreal" and "outfrac" are defined in terms of the corresponding editing procedures of "image". They provide facilities for "item-oriented" output. Each item is edited into a "field" (subtext of "image") normally starting at the current accessible character. POS is advanced correspondingly. If the remainder of "image" is too short to contain the item, "outimage" is called implicitly prior to the editing operation. The field is space-filled before the editing operation.

      A run-time error occurs if a field cannot be contained within the full length of "image".

      Parameter "w" determines both the length of this field and the adjustment of the item within it, as follows.

           w > 0 The field length is w, the item is right-adjusted.
       
           w < 0 The field length is abs(w), the item is left-adjusted.
       
           w = 0 The field length is the exact number of characters needed to
           contain the item (i.e. no leading or trailing spaces).
           
           
       procedure outint(i,w); integer i,w;
           if      w = 0 then FIELD(...).putint(i)   ! see below;
           else if w < 0
           then begin text f;
                  f :- FIELD(-w);
                  f := notext;
                  f.sub(1,...).putint(i) end
           else FIELD(w).putint(i);
       
      Parameters:
      i - the integer value to be edited and outputed
      w - the width of editing field
      Throws:
      RTS_SimulaRuntimeError - if the Item is too long in output operation
    • outfix

      public void outfix(double r, int n, int w)
      Procedure outfix.

      See outint(int,int)

      Parameters:
      r - the long real value to be edited and outputed
      n - the number of digits after decimal sign
      w - the width of editing field
      Throws:
      RTS_SimulaRuntimeError - if the Item is too long in output operation
    • outreal

      public void outreal(double r, int n, int w)
      Procedure outreal.

      See outint(int,int)

      Parameters:
      r - the long real value to be edited and outputed
      n - the number of digits after decimal sign
      w - the width of editing field
      Throws:
      RTS_SimulaRuntimeError - if the Item is too long in output operation
    • outreal

      public void outreal(float r, int n, int w)
      Procedure outreal.

      See outint(int,int)

      Parameters:
      r - the real value to be edited and outputed
      n - the number of digits after decimal sign
      w - the width of editing field
      Throws:
      RTS_SimulaRuntimeError - if the Item is too long in output operation
    • outfrac

      public void outfrac(int i, int n, int w)
      Procedure outfrac.

      See outint(int,int)

      Parameters:
      i - the integer value to be edited and outputed
      n - the number of digits after decimal sign
      w - the width of editing field
      Throws:
      RTS_SimulaRuntimeError - if the Item is too long in output operation
    • outtext

      public void outtext(String s)
      Procedure outtext.
       procedure outtext(t); text t;
       begin
          if pos>1 and then t.length>length-pos+1 then outimage;
          t.setpos(1);
          while t.more do outchar(t.getchar);
       end outtext;
       
      Parameters:
      s - the String representation of the text
    • outtext

      public void outtext(RTS_TXT t)
      Procedure outtext.

      See outtext(String)

      Parameters:
      t - the _TXT representation of the text
    • inimage

      public void inimage()
      Procedure inimage.

      This method is virtual and may be redefined in subclasses.

      Throws:
      RTS_SimulaRuntimeError - if no redefinition is available
    • inchar

      public char inchar()
      Procedure inchar.
       character procedure inchar;
       begin
          if not more then inimage;
          inchar:= image.getchar
       end inchar;
       

      The procedure "inchar" gives access to and scans past the next character. Note: The result may be the "EOF-character" EM (ISOrank 25).

      Returns:
      the resulting character
    • intext

      public RTS_TXT intext(int w)
      Procedure intext.
       text procedure intext(w); integer w;
                  begin text t;
                     intext :- t :- blanks(w);
                     while t.more do t.putchar(inchar)
                  end intext;
       

      The expression "intext(w)" where "w" is a positive integer is a reference to a new alterable main frame of length w containing a copy of the next w characters of the file. POS is set to the following character. The expression "intext(0)" references notext. In contrast to the item-oriented procedures (see below), "intext" operates on a continuous stream of characters, reading several images if necessary.

      Note: The result may be a reference to an "EOF-image" (cf. inimage/inrecord).

      Parameters:
      w - the width of the input field.
      Returns:
      the resulting text
    • lastitem

      public boolean lastitem()
      Procedure lastintem.
        Boolean procedure lastitem;
        begin character c;
           c := ' ';
           while not ENDFILE and then (c=' ' or else c='!9!')
           do c := inchar;
           lastitem := ENDFILE;
           if c ne ' ' then setpos(pos-1)
       end lastitem;
       

      The purpose of the procedure "lastitem" is to skip past all SP and HT characters (ISOrank 32 and 9 respectively). The process of scanning may involve the transfer of several successive external images. If the file contains no further non-space, non-tab characters the value true is returned.

      Returns:
      the resulting boolean value
    • ImageRest

      private RTS_TXT ImageRest()
      Starting at pos return the rest of image.
      Returns:
      the rest of image
    • inint

      public int inint()
      Procedure inint.
       integer procedure inint;
       if lastitem then error("..." ! Inint: End of file ;)
       else begin text t;
               t:- image.sub(pos,length-pos+1);
               inint := t.getint;
               setpos(pos+t.pos-1)
       end inint;
       

      The procedures "inint" is defined in terms of the corresponding de-editing procedure of "image". This procedure, starting at the current "pos", skip spaces and tab's, and then scan past and convert a numeric item.

      Returns:
      the value of an integer item.
    • inreal

      public double inreal()
      Procedure inreal.
       long real procedure inreal;
       if lastitem then error("..." ! Inreal: End of file; )
       else begin text t;
          t :- image.sub(pos,length-pos+1);
          inreal := t.getreal;
          setpos(pos+t.pos-1)
       end inreal;
       

      The procedure "inreal" is defined in terms of the corresponding de-editing procedure of "image". This procedure, starting at the current "pos", skip spaces and tab's, and then scan past and convert a numeric item.

      Returns:
      the value of an real item.
    • infrac

      public int infrac()
      Procedure infrac.
       integer procedure infrac;
       if lastitem then error("..." ! Infrac: End of file; )
       else begin text t;
          t :- image.sub(pos,length-pos+1);
          infrac := t.getfrac;
          setpos(pos+t.pos-1)
       end infrac;
       

      The procedure "infrac" is defined in terms of the corresponding de-editing procedure of "image". This procedure, starting at the current "pos", skip spaces and tab's, and then scan past and convert a numeric item.

      Returns:
      the value of a fractionated integer item.