next up previous contents index
Next: Library Only Mode Up: The Library Version Previous: The Library Version

Creating the Library Interface

Once you have completed the previous operations, an interactive system is available. The system can also be used in batch or within command procedures. It is very easy to make a Fortran callable version of this system by adding only one extra subroutine. Taking again the same example this subroutine will be:    

      FUNCTION US_ERROR(dummy)
*
*       Library version of the user program.
*       All the user commands are accessible through calls 
*       in the form:
*
*       CALL US_EXEC ('This_command')
*
*       The error status can be checked and reset using the
*       function US_ERROR(). If an error exist, the program
*       aborts when trying to execute the next command.
*
      INCLUDE 'inc:errcod.inc'
* The above line defines the FATALE error code used below
      LOGICAL ERROR, US_ERROR
      CHARACTER*(*) BUFFER
      CHARACTER LINE*256, COMM*12, LANG*12, MESSAGE*60
      INTEGER NL, DUMMY, LENC
* Save the error code from last call
      SAVE ERROR
*
* Transmit error status, and reset it
      US_ERROR = ERROR
      ERROR = .FALSE.
      RETURN
*
      ENTRY US_EXEC(BUFFER)
*
* Check error status, abort if not cleared
      IF (ERROR) THEN
         WRITE(6,*) MESSAGE
         WRITE(6,*) LINE(1:NL)
         CALL SYSEXI (FATALE)
      ENDIF
*
* Copy the command line in argument to the local buffer LINE
* Format it and Analyse it
      LINE = BUFFER
      NL=LENC(LINE)
      CALL SIC_FORMAT (LINE,NL)
      CALL SIC_ANALYSE(COMM,LINE,NL,ERROR)
      IF (ERROR) THEN
         MESSAGE = 'E-US_EXEC,  Error Interpreting Line'
         RETURN
      ENDIF
* 
* If your application is multi-language, then make sure that the 
* command belongs to your language.
      CALL SIC_LANG(LANG)
      IF (LANG.NE.'USER') THEN
         ERROR = .TRUE.
         MESSAGE = 'E-US_EXEC,  Language Mismatch Line'
         RETURN
      ENDIF
*
* Execute it
      CALL RUN_USER(LINE,COMM,ERROR)
      IF (ERROR) THEN
         MESSAGE 'E-US_EXEC,  Error Executing Line'
      ENDIF
      END
      A program can then be written just by typing the same commands as in interactive. Of course, this is not always convenient, but you should be able to provide additional routines to make the formatting of the line, or give a more direct argument transmission. Note that all errors are absolutely fatal in this Library Mode, and must be handled by the calling program. This is in contrast with the EXEC_USER routine which provided a SIC like error recovery, but at the expense of a compulsory interactive use of the program.



Gildas manager
2002-06-07