Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
588 views

Geolog6.6 Loglan Programming Tutorial

Uploaded by

jimmymorelos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
588 views

Geolog6.6 Loglan Programming Tutorial

Uploaded by

jimmymorelos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

Geolog 6.

6
Loglan Programming
Tutorial
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial 01 / 2006 1
Contents
Introduction to Geolog's
Loglan Programming Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Document Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Tutorial Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Loglan Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
What is Loglan?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Create a New Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Getting Started. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
The Loglan Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
The Loglan Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Loglan Program Development Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Starting Loglan. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Loglan Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
The Module Launcher Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Single Well Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Multiwell Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
How to Write a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Make a Plan. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Make the Code Maintainable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Make the Code Robust . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Remain Logical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Re-Use Existing Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Loglan Language Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Program Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Source File Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Types of Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Loglan Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Arrays in Loglan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Log Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
External Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Introduction 1
Introduction to Geolog's
Loglan Programming Tutorial
Welcome to Paradigms Geolog Loglan Programming tutorial.
This tutorial teachs you to develop log processing modules to perform your own processing
algorithms on your Geolog data. These modules will be fully integrated into the Geolog6
environment, and will function in exactly the same way as any other module in Geolog6.
The tutorial guides you through:
a simple example to give you a feel for how Loglan works
the general structure of a Loglan program and the program development interface
Loglan variables
the Module Launcher interface
an introduction to general programming principles
specific details of the syntax of the Loglan language
A number of exercises are included throughout to demonstrate concepts and to allow you to
check your progress.
Prerequisites
Basic familiarity with the Geolog6 environment is the only prerequisite for this course, although
some prior experience with programming concepts would be helpful. Geologs online help for
Loglan also provides further information.
Document Conventions
In this document, all INPUT to the computer is in Bold Courier New, while all OUTPUT from
the computer is in Courier New, but not bold.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Introduction 2
Tutorial Data
The following additional files (files not supplied with software) are used in this tutorial:
DATA: stars_master.unl
nuke.asc
sonic.asc
REPORTS:
LAYOUTS: SECTIONS:
LOGLAN: ./examples/ans*.lls and ans*.info
c_extern.c
extern_c.lls and extern_c.info
launcher.lls and launcher.info
validation.lls and validation.info
SPECS:
PLOTS: WELLS: atlas
botein
capella
deneb
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Overview 3
Loglan Overview
What is Loglan?
Loglan (an acronym for Logging Language) is Geologs log processing language and provides
the Software Development Kit for Geolog.
Loglan is a programming language especially suited to log processing and its syntax is similar
to that of C, but it is reasonably intuitive so familiarity with C is no great advantage for learning
Loglan. It does help if you have a programming background, if only because it makes you
realise how unintelligent computers are, in that they will do exactly and only what they are told
to do!
Loglan is fully integrated into the Geolog environment. There is a Graphical User
Interface (GUI) for creating and modifying Loglan programs, and, as far as Geolog is
concerned, a Loglan program is no different from any other module.
When you compile your Loglan program, it is first translated into the C programming language;
then it is compiled and linked to produce an executable program. To create and edit Loglan
programs, you need to have an ANSI C compiler installed on your computer. The default
compiler used is the one provided by the hardware vendor for Unix, and Visual C++ for Windows.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Create a New Program 4
Create a New Program
Procedure
In this section, you are introduced to the Loglan programming interface, and you will:
create a simple program for use in Geologs Well application.
Getting Started
Before getting into the details of the language, we will perform a simple exercise to
demonstrate how easy it is to write and run a Loglan program (do not worry if you
do not understand exactly what is happeningthe details will be covered later).
The program will calculate porosity from sonic according to the algorithm of
Raymer, Hunt and Gardner (SPWLA, 1980), valid for porosities of less than 0.37,
using the formula:
Eq. [1]
and
Eq. [2]
where:
is the porosity to be calculated
is the matrix t in s/ft
is the fluid t in s/ft
is the value of the sonic log in s/ft
To start the program development interface
1. Start Geolog and open the STARS project.
2. Start the Well application.
Exercise 1

2
t
ma
t
------------ 1 + =

t
m
2t
fl
------------ 1 =

t
ma
t
t
fl
t
t
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Create a New Program 5
3. Open the BOTEIN well.
4. On the Well menu, select General > Loglan... to open the Loglan
development interface mui_loglan and present its base window.
5. Select Loglan > New to display the Loglan Properties dialog box (see
Figure 2).
Figure 1: Blank Loglan Window
Menu Bar
Toolbar
Message Area
Status Bar
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Create a New Program 6
6. In the "Program" field, enter the program name rhg_por.
7. In the "Description" field, enter Raymer-Hunt-Gardner Porosity.
8. Do not enter a layout name. This field allows you to specify a layout to be
opened automatically when the Loglan program is executed.
9. Leave Hide insensitive arguments as toggled ON. This means insensitive
arguments wil not be displayed when the program is run in Geologs Module
Launcher (the SHOW INSENS checkbox will be toggled OFF in the Module
Launcher).
10. Click OK open the Loglan window ready for program creation.
Figure 2:Loglan Properties Dialog Box
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Create a New Program 7
The Loglan window contains three tabs; Input/Output, Source and
Description.
Input/Output Tab - Inserting Variables
The program variables and the interface displayed when the program is executed
are defined here. This information is saved as <program_name>.info when the
loglan is saved.
The next step is to define the variables required by our program:
an input sonic log, DT
two input constants, DT_MA and DT_FL, for the matrix and fluid delta t
an output porosity log which we will call PHIE_RHG
another output porosity log limited to the range, zero to one, which we will call
PHIE
a temporary (local) variable alpha
You can insert variables with a mode of input, input/output, and output, and Local
variables. In this example, you will insert six rows on the Input/Output tab for
variables DT,DT_FL, DT_MAS, PHIE_RHG, PHIE, and alpha.
Figure 3: Loglan Window Ready for the New rhg_por Program
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Create a New Program 8
11. Select Edit > Insert (or press Insert on the keyboard) to display the Insert
Row window.
12. Enter DT (for the sonic log) as the Name, set the Location to Log and the
Mode to Input, and click OK.
13. Repeat steps 11. and 12. using the data provided in the following table.
Specifying units
A default list of applicable units is generated if the Name is defined in the
loginfo file (e.g., if the log name used is DEPTH, a list of valid length units,
such as metres, centimetres, millimetres, is generated).
14. In the Input/Output tab, ensure the units for DT_FL, DT_MA, and DT are set
to s/f and the units for PHIE and PHIE_RHG as v/v (volume ratio).
NAME LOCATION MODE
DT_FL
This is set to Input-Output so that when the
program is run, the value we enter is saved and
then used as the default next time the program is
run.
The reason we make this an interval value rather
than a constant is that the value is interval
related. If we are not processing intervals, the
value will be obtained from and saved as a well
constant; otherwise, a log in the interval set will
be used.
Interval Input/Output
DT_MA Interval Input/Output
PHIE_RHG Log Output
PHIE
This is a copy of the PHIE_RHG curve limited
between zero and one.
Log Output
ALPHA
Local variables are used within the program for
"local" processing, and are not input or output.
Local "greyed out"
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Create a New Program 9
Specifying default values
15. The following values are used as the defaults when the program is run if
values cannot be obtained from the constants or interval information:
Default value for: use:
DT_FL 189
DT_MA 55.5
The following specifies the default curve names for the output logs, which will
be placed into the output set when the program is executed.
Default value for: use:
PHIE_RHG PHIE_RHG
PHIE PHIE
Specifying comments
16. Edit the Comments as shown in Figure 4:
Source Tab - Entering the Code
The actual Loglan code for the program is typed into the Source tab.

To indent text, press the Spacebar or Ctrl+Tab.


Figure 4: Completed Input / Output Tab of Loglan Program
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Create a New Program 10
17. Click the Source Tab and enter the code as shown in Figure 5 using the
following guidelines:
Instructions which are to be executed for each frame of data must be
entered within the dowhile get_frame ()enddo loop. Instructions
before or after this loop are executed only once.
As the variable alpha is a local variable and is constant throughout the well
or interval, it does not need to be recalculated for every frame. Therefore, it
can be placed BEFORE the dowhile get_frame ()enddo loop.

To toggle off the Arguments table click the icon.


Description Tab - Entering Program Documentation
18. Click the Description Tab and type in the description as shown in Figure 7.
Figure 5: Code for Loglan Program Entered in Source Tab
Argument Table
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Create a New Program 11
19. Select Loglan > Save.
This creates two files in the loglan directory in the local project area:
rhg_por.lls which contains the source code and rhg_por.info which
contains descriptive information about the loglan, as well as information on
how to control the variables displayed in Geologs Module Launcher.
20. Compile the program by selecting Tools > Compile.
If your program compiles successfully, the message
Loglan program <./loglan/rhg_por.lls> compiled ok is displayed
in the Message area at the bottom of the Loglan window. The program can be
run in the same way as any Geolog-supplied program.
Executing the program
21. Close the Loglan application and return to Geologs Well application.
22. In Well, select General > Module... to invoke Geologs Module Launcher and
open the File Select dialog box.
Figure 6: Description Tab
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Create a New Program 12
23. Select the rhg_por.info module to open the Loglan program you have just
created (see Figure 8).
Figure 7: Geologs Module Launcher
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Create a New Program 13
24. Click Start to execute your Loglan program.
Note
If you are running with metric units, the values displayed for DT_MA and DT_FL are in s/m, but
they are passed to your Loglan program in s/f.
Figure 8: rhg_por Module Displayed in Geologs Module Launcher
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Loglan Environment 14
The Loglan Environment
Procedure
The Loglan environment has three components the Loglan program, the Loglan
development interface mui_loglan, and the Module Launcher. In this section, you will learn
about the Loglan program. The Loglan development interface mui_loglan is covered in
"Loglan Program Development Interface" on Page 17, and the Module Launcher, a
component of both Geologs Well and Project applications, is covered in "The Module
Launcher Interface" on Page 31.
The Loglan Program
A compiled Loglan program actually comprises three files:
the source code file, identified by the .lls (loglan source) suffix
the module information file (identified by the .info suffix)
the executable file created when the Loglan program is compiled (no suffix on
Unix, .exe on Windows).
Loglan Source File
The source file consists of a header section with the program description as
entered in the Description tab (see Figure 6 on Page 11) of mui_loglan, then a list
of the variables used by the program, followed by the executable code. Using the
program created in Exercise 1, the source file rhg_por.lls contains:
PROGRAM: RHG_POR Raymer-Hunt-Gardner Porosity
/*-------------------------------------------------------------
/*start_doc
/*This program calculates the Raymer Hunt Gardner
/*porosity using the equation:
/*
/*Porosity = -alpha - SQRT ( alpha**2 + DT_MA/DT -1)
/*
/*where:
/*
/*alpha = DT_MA/(2*DT_FL) -1
/*
/*end_doc
/*-------------------------------------------------------------
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Loglan Environment 15
INPUT
/*
/* INTERVALS --------------
/*
DT_FL US/F /* Delta T Matrix
DT_MA US/F /* Delta T Fluid
/*
/* LOGS -------------------
/*
DT US/F /* Sonic log
LOCAL
alpha /* Temporary
OUTPUT
/*
/* INTERVALS --------------
/*
DT_FL US/F /* Delta T Matrix
DT_MA US/F /* Delta T Fluid
/*
/* LOGS -------------------
/*
PHIE_RHG V/V /* Limited porosity
PHIE V/V /* Raw proosity
START:
/* Calculate the constant before looping through the data.
alpha = DT_MA / ( 2 * DT_FL ) -1
/* Now loop through the data calculating the porosity.
dowhile GET_FRAME ()
/* Skip calculation if value is missing.
if ( DT == MISSING ) then
goto finish
endif
PHIE_RHG = -alpha - SQRT ( alpha**2 + DT_MA / DT -1 )
/* Apply limit.
PHIE = LIMIT ( PHIE_RHG, 0, 1 )
finish:
call PUT_FRAME ()
enddo
end
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Loglan Environment 16
TIP
Generally, source files are edited using the Loglan program development interface (Loglan
window) but it is quite easy to edit them using your favourite editor. If you want to edit source
files using a text editor other than the Loglan window, you should be very careful when
changing anything before the START: label. Variables should be inserted, deleted and
modified only through the Loglan window, since changes to these require the .info file to be
changedthis process is handled automatically by mui_loglan.
Module Information File
The module information file, identified by the .info suffix, is a Geolog
specification file which controls the appearance of the module, including default
values and logs, comments, data validation and the visibility of variables in the
Module Launcher window, when invoked from Geologs Well or Project
applications.
This file should not be changed except through the Loglan window.
Executable File
This file has no suffix under Unix, and a suffix of .exe under Windows; it is created
by the Loglan compilation procedure.
All of these files are stored in the loglan directory of the local project. If they are
to be made available to your entire company, they can be copied to your site/
loglan directory. It is good practice to create programs with names that describe
what they are designed to do.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 17
Loglan Program Development Interface
Procedure
In this section, you will learn the various methods for starting the Loglan development interface
(Loglan window) and the components of the interface are covered in detail. You will:
Practice using most of the commands available in the Loglan window.
Edit a program which demonstrates validation string usage.

For the remainder of this manual, the "Loglan program development


interface" will be referred to as the "Loglan window".
Starting Loglan
The Loglan window can be opened using several different methods:
From Geologs Project or Well application menu, select General > Loglan...
OR
From Geologs Launcher Bar, click on the Loglan button or select
Applications > Loglan.
OR
At a Unix prompt, enter geolog6 mui_loglan.
The Loglan window is fully documented in Geologs Loglan online help documentation, so the
main points will be mentioned only briefly here. Loglan operation is quite intuitive.
1. If you do not have a Loglan window already open, open one now so that you
can try out the commands as they are explained.
Create a New Loglan Program
2. Select Loglan > New from the menu to create a new Loglan program.
Open an Existing Loglan Program
3. Select Loglan > Open to open and edit an existing Loglan program.
Exercise 1
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 18
Save a Loglan Program
4. Select Loglan > Save to save the currently open program. NOTE, however,
that this command does not create a new executable; to do that you have to
use the Compile command.
Save a Loglan with a Different Name
5. Select Loglan > Save As... to save the currently open program under a
different name.
Run Command
6. Select Loglan > Run... to execute an external program or command.
Delete a Loglan Program
7. To delete an existing program which is no longer required, select Loglan >
Delete... All the files associated with the program (the source, information,
and executable files) will be deleted.
Exit the Loglan Window
8. Select Loglan > Exit. If any of your loglans have not been saved, you are
prompted to Save or Discard the open Loglan program, or Cancel the Exit
command.
Edit Menu
Undo Only available when a row has been removed in the
Input/Output tab.
Insert Used for inserting rows in the Input/Output tab in which
program inputs and outputs are defined.
Find Select to open the Find dialog box. If you have the Input/
Output tab selected, the Quick Find dialog is displayed; if
you have the Source or Description tab selected, the
Loglan Find dialog box is displayed.
Sort Sorts Input/Output variables by location.
Sort By Name Sorts Input/Output variables by location and name.
Properties... Display/modify details of the program's name, description
and documentation.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 19
Externals... Specify the path names for included files and directories,
external libraries and directories, external objects, and
the Linker used to load the compiled program.
Loglan programs are converted to C language and
compiled to produce an executable module. This requires
a C compiler in your environment. The environment
variable MIN_CC defines the C compiler to be used.
Code... Start the editor specified by the environment variable
MIN_EDITOR to edit the Loglan code. If a compile error
has previously occurred, the editor will be started
pointing to the line containing the first error.
The editor must start up in a new window, and the
mui_loglan window is blocked until the editor exits. If no
editor is specified by the environment variable, "xterm
vi" is used. Emacs (usually /usr/local/bin/emacs) is a
good choice.
Description... Used to enter a detailed description (program
documentation or users guide) via the editor specified by
the environment variable MIN_EDITOR.
Input/Output Table Click the Table Menu icon to display editing
functions for the Input/Output tab (see Figure 9).
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 20
Tools Menu
The commands on the Tools menu perform the tasks described below:
Compile Compiles the program. Error messages are displayed
in the message area of the Loglan window. Requires an
ANSI-C compiler.
Windows 2000/XP requires Microsoft Visual C++
version 4, 5 or 6. The installation path cannot contain
spaces (except for the "Program Files" section).
Site Install After compiling the loglan, select this option to install
the program to the Site area to make it available to all
users.
Function Maintenance Select this option to create/modify user defined
functions.
View Menu
Functions Table Select this option to toggle the display of a Functions
list.
Figure 9: Table Menu
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 21
Arguments Table Use this option to toggle the display of the Arguments
table while viewing the Source tab.
Compile Output Use this option to toggle the display of the compilation
output window on the Source tab.
Loglan Variables
As mentioned previously, a Loglan program consists of basically two parts:
the variables or data on which the program operates, and
the code, or instructions, executed by the program.
Variables in Loglan have a number of attributes, most of them displayed in the
Input/Output tab of the Loglan window. These include the name, location, mode,
units, default, comment, validation and visibility of the variable.
Location
A variable's location defines its source and destination, and may be one of:
Parameter
This is generally used for input data which is not well or interval dependent. It is
usually more convenient to use a constant instead.
Constant
This is used for data which is not interval dependent. For Input or In/Out variables,
the value used for a constant will be obtained from the well header constant with
the same name as the variable. If no such constant exists, the default value
specified in the Loglan program is used. For Output or In/Out variables, it will be
stored as a well header constant when the Loglan program is executed.
Variable
attributes
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 22
Log Constant
These variables must have a name of the form <constant>_<logname>, where
<constant> is the name of a log header constant such as UNITS, MAX,
MEAN, etc. (see the Loglan online help for further information), and <logname>
is the name of a log used in the program.
Interval
Interval variables are similar to constants, except that values will be obtained
from and stored in a log in the current interval set. If you are not using interval
processing, well header constants will be used. These are used for data whose
values are interval dependent.
Log
This is used for variables whose values vary for each frame (i.e., for log data).
Local
For variables used only within the Loglan program, usually as temporary
variables to hold intermediate results. Local variables are not stored in the
.info file, so are never displayed in the Module Launcher window.
Mode
A variable's mode defines the way in which it is processed by the Module
Launcher. It must be one of:
Input
For variables which are read by the Loglan module but are not to be written
back to the well.
In/Out
For variables which are used both as input for the Loglan module and output to
the well after the module has executed. Often, this mode is used for constants
and interval parameters so that the values used for an analysis will be stored in
the well and used as defaults next time the Loglan module is run.
Output
For variables which are calculated by the Loglan module and are to be stored in
the well.
Name
Valid names must start with an alphabetic character, and the other characters
must be alphabetic, numeric, or the underscore character. The name may be no
longer than 32 characters for input or output variables, while the limit for local
variables is 63 characters. A name may not end with an underscore followed by a
number, as this could be confused with a version number.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 23
There are a number of names which cannot be used:
words which are reserved in the Loglan language itself (such as endif);
those reserved in the C language (such as case);
those whose names conflict with standard functions used by the C language.
There is a complete list of these in the Loglan online help documentation, but you
do not really need to know the list, as the compile step will report any
transgressions. Names of the form <attribute>_<name> should be avoided, since
these may be confused with Log Constants (see "Log Constants" on Page 66). It
is good programming practice to use meaningful names: this makes it easier for
others to understand what is going on if they need to look at the code.
Type
Variables can be of type Alpha, Numeric (Integer, Real, or Double), or Logical.
Alpha
Alpha variables have an alpha string value and are defined using the following
syntax:
Log Name Type Comment
Log alpha*num /* General case
The units alpha*num specify the maximum number of characters which may be
assigned to the variable. Any characters beyond num will be truncated. The
default length (if the "*num" is omitted) is 4. The maximum length is 72 for
INPUT/OUTPUT variables and 1024 for LOCAL variables.
Numeric
Any variable which is not declared Alpha or Logical is numeric. The units can be
any valid units defined for the variable in the unit category specified in the
variable's loginfo definition.
Logical
Logical variables have the values TRUE or FALSE and are useful for flags,
switches or toggles.
Unit
For a unit to be valid, the variable to which it applies must be defined in a log
information (loginfo.loginfo) file, and the unit must exist in the unit category
for that variable. It is usually easiest to use the List Select dialog box.
Note: Units cannot be specified for Local Variables.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 24
The way the units are used depends on whether the variable is input or output (for
In/Out, both apply).
Input variables
If you specify valid units for an input variable then, when the Loglan program
executes, its data will be passed in those units, irrespective of the units in which
the data is held in the well and displayed, provided the units in the well are valid.
If either the Loglan units or the data units are invalid (or blank), then no unit
conversion can be performed by the Module Launcher and an error will be
reported unless the Loglan units are blank. For character variables, the data will
be truncated (if the Loglan length is less than that of the data in the well), or
padded with spaces (if the Loglan length is longer). If no units are specified for a
numeric variable, the Loglan program will receive the data in the units in which
the data is stored in the well. The log constant UNITS_<variable> can be used
to access these units. This is often useful when reporting data.
Output variables
If you specify valid units for an output variable, these will be used only if the
preferred units for the variable are blank; otherwise, the data will be stored in
(after conversion to) the preferred units. If the units in the Loglan program are
blank, the variable is assumed to be in the preferred units. For character
variables, the length specified in the Loglan program will be used only if the
variable does not already exist in the well; if it does already exist, the length will
not be changed and the data will be truncated or padded with spaces, as
required.
Default
The interpretation of the default depends on both the variable's location and its
mode (see "Location" on Page 21 and "Mode" on Page 22).
Terminology
In the descriptions below:
Launcher default means the value displayed in the Module Launcher (and used by the
Loglan program when it is executed).
Loglan default is the value specified as the default in the Input/Output section of the
Loglan window.
Note that the following discussion implies that there is no defaults file for the
module; the use of a defaults file is explained in "Notes on Saving" on Page 38.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 25
Log constants are not included in this discussion since they do not appear in the
Module Launcher window.
For local variables
the Loglan default is ignored. These variables do not appear on the Module
Launcher window.
For input logs
the Launcher default is a log with the same name as the input variable. The
Loglan default is used only if the log with the same name as the variable cannot
be found. If the variable is numeric, and the Loglan default is numeric, the
Loglan default will be used as a constant value of the input log for all frames
processed by the program. If the variable is numeric, and the Loglan default is a
name, then, if a log of that name exists, it will be used as input to the Loglan
program; otherwise, the Loglan default is ignored. If the variable is of type
character (alpha), the Loglan default will be used as the name of a log if that log
exists; otherwise, it will be used as a constant value.
For input constants
the Launcher default is the value of the well header constant with the same
name as the input constant. The Loglan default will be used if its type (i.e.,
numeric or alpha) matches the type of the constant, and if the constant with the
same name as the input variable does not exist in the well. If the types do not
match, the Loglan default is ignored.
For input interval constants
the Launcher default is the value of the log (in the interval set) with the same
name as the variable, for the current interval. If that log does not exist, or if
interval processing is not enabled, the Launcher default is the value of a well
constant with the same name as the variable. If that does not exist, then the
Loglan default will be used if its type (i.e., numeric or alpha) matches the type of
the interval constant; if the types do not match, the Loglan default is ignored.
For input parameters
the Loglan default will be used if its type matches the type of the parameter; if
the types do not match, the Loglan default is ignored.
For output logs
the Launcher default (i.e., the name of the log produced by the Loglan program)
is the Loglan default, which must be a valid log name.
For output constants and interval constants
the Loglan default is ignored. Interval and well constants are always created
with the name used in the Loglan program, and the value output by the
program.
Output parameters
should not be used.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 26
For Input/Output logs
the Launcher default is a log with the same name as the variable. The Loglan
default is used only if the log with the same name as the variable cannot be
found, in which case the Loglan default must be a valid log name.
Input/Output constants and interval constants
are handled in the same way as input constants and input interval constants,
respectively.
Input/Output parameters
should not be used.
Comment
The comment is displayed on the Module Launcher window and should therefore
be meaningful. It is also stored in the well as the comment for any logs or
constants created by the Loglan module when it is run.
Validation
Validation specified in the Loglan window is applied in the Module Launcher when
the value of an entry is changed, and when Start is selected. There are two types
of validationlists and ranges. For strings, only list validation is permitted. The
validation is ignored for logical variables.
A range validation
is a string of the form lower limit:upper limit, or lower limit<upper limit. ":" means
"less than or equal", while "<" means "strictly less than". One of the limits may
be absent to indicate that only the other limit is to be checked. If the value may
also be missing, ",-"may be appended. For example:
2:100,- means that the value of the numeric variable must be greater than or
equal to 2 and less than or equal to 100, or that it may be missing.
1< indicates that the value must be greater than 1.
A list validation
is a string of the form l1,l2[,l3], where the "li" represent the valid values. If one
of the list elements is a question mark, any other value is also valid, while "-"
means that a blank (for a string) or a missing value (for a numeric) is also valid.
When you use list validation for a variable, a Dropdown List button is
displayed by the Module Launcher when its value field is highlighted.
For numeric variables, the user input will be converted from the displayed units
(usually the preferred units) to the units used by the Loglan program before the
validation is performed. For logical variables, an automatic list containing "Yes"
and "No" is created.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 27
Visibility
Defines input/output visibility when a Loglan module is executed. If TRUE, the
entry is displayed when the program is executed. If FALSE, the entry is not
displayed when the program is executed.
If the visible parameter is a statement in the following form:
variable1:[!]value[,value...]
and is true (if variable1 has any of the specified values), the parameter is visible
and active. If the condition is false, the parameter is not displayed unless the
SHOW INSEN button in the Module Launcher is toggled ON, in which case, it will
be inactive (grayed out). Case is ignored when the value is tested. Use of the !
(exclamation mark) reverses the sense of the test.
Example:
RHO_DSH visibility may be controlled by OPT_PHITYPE:TOTAL. See Figure 10 for
an example.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 28
If controlling visibility with a logical (e.g. OPT_COAL), the following syntax must be
used:
OPT_COAL:YES or OPT_COAL:TRUE or OPT_COAL:1
If more complex control over visibility is required, an expression may be used. This
must be a quoted string, and has exactly the same form as a logical expression in
Loglan (see "Logical expressions" on Page 45).
Figure 10: Examples of Visibility in the Module Launcher
OPT_SON is set to FALSE and therefore,
is not visible in the Module Launcher.
OPT_PHITYPE is not set
to TOTAL, and Show
Insens is toggled on so
RHO_DSH is "grayed
out" - visible but inactive.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 29
For example:
"FILTER_TYPE<>'EXTERNAL' & FILTER_TYPE<>'KLAUDER' & PHASE_MODE ==
'CONSTANT'"
Note that if you are using this form, all literals (character constants) must be
quoted using single quotes.
The objective of this Validation exercise is to test the different kinds of validation
available in Loglan programming.
1. Open the Loglan program, validation.lls, in the Loglan window, and
validation.info in the Module Launcher to see the results of the different
validation strings used.
Exercise 2
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Program Development Interface 30
Note that for variable a3, a blank is allowed. The Dropdown List (in the
Module Launcher window) contains a blank at the end of the list. Click below
the last item in the list to select the blank.
2. In the Loglan window, insert an Input Constant as follows:
call it BS;
set units to inches;
set the default to 7 inches;
set the value to be between 3.625 and 18 inches;
set visibility to be true when ALPHA_LIST:val2.
3. Save the changed programthere is no need to compile since we will not be
executing the program.
4. Update the Module Launcher window by selecting Launcher > Module... and
reopening the module.
5. Toggle on Show Insens to view the BS constant.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Module Launcher Interface 31
The Module Launcher Interface
Procedure
In this section, you are introduced to the components of the Module Launcher interface and
you:
practice using the various components of the Module Launcher.
Overview
The Module Launcher is a component of both Geologs Project and Well
applications and multiwell analysis is carried out within both of these applications.
In Well, several wells can be loaded into memory, processed, and the changes
saved to the database or discarded, as required. You should use the Well
application where only a few wells need to be open at one time. Where a large
numbers of wells are to be processed simultaneously, use the Project application,
as the wells are not stored in memory, and data is immediately processed and
saved to the database.
We discuss the Well interface first using "Single Well Processing" below, and then
examine the additional facilities in the Project interface (see "Multiwell Processing"
on Page 40).
The Module Launcher window is exactly the same for a Loglan program as it is for
any module which is part of Geolog. A user defined module is opened by selecting
General > Module... from the menu, and specific modules are opened directly by
selecting the relevant menu command (e.g. General > Evaluate).
Single Well Processing
1. If it is not already running, start the Well application and open the
BOTEIN well.
2. Select General > Module... to open the Module Launcher and the File Select
dialog box (see Figure 11).
Exercise 1
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Module Launcher Interface 32
3. Enter or locate the required filefor this exercise, open launcher.info.
See "Using Geolog" in the online help documentation for further information
on using the File Select dialog box.
4. Click OK. This causes the .info file to be read and the module arguments
will be displayed in the Parameters section of the window (see Figure 12).
Figure 11: File Select dialog box - Opening a Module
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Module Launcher Interface 33
Input Set
The set displayed is either the set specified for the module, or, if not specified, the
default set specified for the application (select Well > Default Set...). Logs to be
processed by the module come from this set, unless otherwise specified. For
instance, in Figure 12, if COR.DT is entered, the DT log from the COR set is used,
rather than the DT log from the WIRE set.
5. To change, click on the Set Select icon to select from a list of available
sets, or enter a set name in the field.

In previous versions of Geolog, when the Input Set was changed, all
Parameters were reset to the defaults for the module. This no longer occurs.
To reset the Parameter defaults, select Launcher > Reopen.
Output Set
The set displayed is either the set specified for the module, or, if not specified, the
default set specified for the application (select Well > Default Set...). Logs to be
processed by the module are written to this set, unless otherwise specified. For
instance, in Figure 12, if COR.PHIE is entered, the PHIE log from the COR set is
used, rather than the PHIE log from the WIRE set).
If the set specified does not exist, it is created.
Parameters
section
Figure 12: Components of the Module Launcher
Sampling Log
Input /
Output Sets
Set Processing Limits
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Module Launcher Interface 34
6. To change, click on the Set Select icon to select from a list of available
sets, or enter a set name in the field.

To specifiy an Input Set or an Output Set for a Loglan prgram, create an


ALPHA input parameter called SET_IN or SET_OUT and use the required
set name as the default.
Sampling Log
7. Click on the Log Select icon to display a Log Select dialog box and
select the name of the log which will control the sampling (i.e., the data
frames) of the input data to be passed to the module.
If this field is left blank, the input/output sample rate is determined by the input
sets reference (e.g. depth) or, if no input set is specified, by the first input log.
Set Processing Limits
8. Click the Set Processing Limits button to open the Datum dialog box to
specify whether interval processing is to be used (and, if so, which intervals
are to be processed), or the range of reference values to be processed.
Parameters Section
The Parameters section is a table displaying all the visible arguments used by the
module (log constants are never displayed because they are automatically derived
from the associated logs).
colors
The colors in the table depend on both the Mode and the Location of the module
parameters. Data displayed with a colored background is read-only. The Value
column (white background) can be edited. The Location, Mode, Comment, Unit
and Name columns come from the variable definitions in the Loglan program, and
are described in "Loglan Variables" on Page 21.
If interval processing has been selected (either by clicking on the Set Processing
Limits... button or selecting Well > Datum... from the menu), there is a Value
column for each selected interval, and the column heading is the interval name
rather than "Value". Also, the location for the variable "INTERVAL_IN_OUT"
changes from "Constant" to "Interval", and the color of that line changes.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Module Launcher Interface 35
special module parameters
There are a few variables which are handled in a special manner by the Module
Launcher; these are SET_IN, SET_OUT, and INTERVAL. If your program uses
SET_IN or SET_OUT as a parameter, or INTERVAL as an interval constant, these
do not appear on the Module Launcher window but are automatically passed to
your program with the appropriate value(s). A constant named WELL also
automatically receives a value.
Data Entry and Execution
Quick Entry
For small modules, it is quicker to enter/select values directly in the Value column
fields. For large modules, the Quick Entry option opens a dialog box which
enables you to quickly cycle through and select the required values for the Value
column(s) in the Parameters section of the the Input/Output tab.
To use Quick Entry for multiple intervals
1. In the Well application, select Launcher > Module and select
Launcher.info.
2. Set the processing limits to Interval, the interval log to tops.tops, and
select MALABAR FM and THORLEY FM as the intervals.
3. For multiple value columns, where applicable, toggle the ALL column on (see
Figure 13), to enable simultaneous multiple entries for a value entered.
4. Click in a Value field.
5. Select Edit > Quick Entry to display the Quick Entry dialog box (see
Figure 13).
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Module Launcher Interface 36
6. In the Quick Entry dialog box:
double click the required value in the List field to enter the value in the Value
column and go to the next editable cell.
OR
select a value and then click Apply or press ENTER to enter the value in the
Value column and go to the next editable cell.

If the ALL column is available and toggled ON, editing continues down
otherwise, editing continues to the right.
where there are no values in the List field, click in the Selection field and enter a
value, then press ENTER or click Apply to enter the value.
to skip a field, press ENTER or use the Next button.
to finish editing or cancel the operation, click Close.
Figure 13: Using Quick Entry to enter values in Values column(s)
ALL column
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Module Launcher Interface 37
Launcher Menu
The Launcher menu options are used to manage modules.
TOOLBAR MENU ITEM DESCRIPTION
Module... Opens the File Select dialog box to locate and select a module.
A module can also be opened by:
Selecting a relevant menu item (e.g. General > Evaluate);
OR, selecting General > Module... in a Geolog application to
open the Module Launcher and File Select dialog box;
OR, selecting Applicationname > Run... (e.g. Well > Run...) and
entering the command applicationname_module in the Run dialog
box. An empty Module Launcher window is displayedselect
Launcher > Module... to open a module. If you know the name of
the module you wish to open, in the Run dialog box enter
applicationname_module module=modulename
For example:
well_module module=tp_calc
Reopen If and when required, use this function to reload the defaults for the
currently open module. If a defaults file exists, it will be reloaded.
Note: The manual function, Launcher > Reopen, replaces the
automatic function in previous versions of Geolog where,
when the Input Set was changed, the Parameter defaults for
the module were automatically reloaded.
Close Closes the Module Launcher window. Note that if you have not saved
the specifications currently entered, they will be permanently
removed (see "Launcher > Save As" below).
Well...
Well Previous
Well Next
Use to specify the well(s) to process. Not available/applicable in all
multiwell processing applications.
Datum Use to specify datum to use for the currently active view.
Start Select to start execution of the module.
Cancel Some functions run a series of modules and/or other processes. Use
the Cancel option to cancel the operation before or after execution of
any process in the series. The entire operation will be cancelled and
the Module Launcher window cleared. The function can then be
restarted, or the Module Launcher closed.
Note the Module Launcher is also cleared after a series of processes
have been run.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Module Launcher Interface 38
Edit > Undo/Redo
If this option is selected after the module has executed, the changes resulting from
the execution of the module will be undone. Clicking it again undoes the effect of
the "Undo".
Notes on Saving
When saving specifications, if you do not enter a file name extension, the module
name is used as the extension. If you do enter an extension, the information will be
saved with the file name and extension you specify, but that file will NOT be
automatically displayed when you select Restore (you need to change the Filter to
locate the file).
Note: When one of the three commands listed below is selected, the Filter field in the File Select dialog
box defaults to *.<modulename> (where <modulename> is the name of the currently open
module) therefore, if you wish to find/save/delete a file with a different extension, you must
change the filter.
Restore... Restore previously saved or executed specifications for the module.
When the File Select Dialog Box opens, select your saved file (see
Save As below) or "previous.<modulename>". Geolog automatically
saves the last specifications used when the module was run in a file
called previous.<module_name> (located in the project's
specs directory). Therefore, when you select the Restore command
to retrieve your saved specifications, you will see files similar to the
following:
previous.tp_evaluate specifications when last executed
mysettings.tp_evalutespecifications you have saved
Use the Restore Previous icon to quickly reload (Files Select
dialog box is not opened) the last specifications run.Note that the
"previous" file is always REPLACED, so specifications are only those
relevant to the last execution.
Save As... Save the specifications you have entered in the currently open
module. See "Notes on Saving" below for further information.
Delete... Opens the File Select Dialog Box to locate and permanently delete
files containing previously saved specifications.
Module Help Opens a separate window that displays the Detailed Description (see
Figure 2 on Page 6) from the .info file for the module
documentation for this module. You can also click the
button.
TOOLBAR MENU ITEM DESCRIPTION
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Module Launcher Interface 39
When the values for a module are first displayed, the Module Launcher checks to
see if a defaults.<module_name> specification exists. If it does, the values in
that specification will be automatically restored. So, if you save your values with
the name defaults, the information will subsequently be automatically restored
whenever you run the module. This is useful if you want to always use the same
values.
Warning
The saved data contains interval information. If your processing limits (i.e., intervals) are
different from those which were applied when you performed the save, the results may not be
exactly what you expect. If the data was saved without intervals, and restored with interval
processing enabled, every interval will receive the same value.
As well, when you select Launcher > Reopen to reload the parameters, the defaults file is
used, not the original defaults for the module.
1. Select General > Loglan... and open the Loglan program, launcher.lls, in
the Loglan window (launcher.info should still be open in the Module
Launcher, as well).
2. Use this Loglan program to experiment with different modes of processing
(i.e. interval and depth range).
3. Open a Text view (Well > View > Text) to check the results.
Experiment with the Undo/Redo, Save and Restore functions.
Exercise 2
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial The Module Launcher Interface 40
Multiwell Processing
When in Geologs Well or Project application with more than one well open to be
processed, the window displayed when you select General > Module... has an
additional column in the Parameters section of the Input/Output tab.
The additional column after the Name column specifies the source for the
parameter; "S" for "screen", "W" to indicate the information must come from the
well (the well is not processed if the value cannot be obtained), or "P" to indicate
the value is to be obtained from the well, if possible, otherwise the screen value is
used.
Multiwell processing is beyond the scope of this tutorial, and is covered in detail in
the Deterministic Petrophysics tutorial.
Figure 14: Multiwell Processing - Loglan Program Displayed in Module Launcher
Extra column
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial How to Write a Program 41
How to Write a Program
Procedure
In this section of the tutorial, we will look at some general programming principles to help you
get your Loglan programs written and working as quickly as possible.
Make a Plan
The most important part of writing a program is to have a plan showing how the
program will operate. It does not need to be "formal": a written description of the
steps involved is often adequate, though sometimes a flowchart can be helpful if
the program is complicated and involves a number of different paths, depending
on the data. It is often easiest to start off with a very high level plan, and then fill in
the details later. The important point is that you have at least some kind of plan as
a starting point.
Make the Code Maintainable
A program is almost never be perfect on the first attempt as problems may occur,
or enhancements may be requested. It is very important to make the maintenance
and enhancement procedures as straightforward as possible, and the best way to
ensure this is to document your code. This means using meaningful names for
your variables, adding comments as often as possible, and making sure that the
program header explains what the program is intended to do. It is often worthwhile
to keep some form of revision history.
The Description tab (see Figure 6 on Page 11) is a facility within Loglan to place a
documentation section in the header that allows other users or programmers
investigating the Loglan program to know what the program is supposed to be
doing, and how it is doing it. It cannot be stressed enough that the more
documentation exists within a program, the easier it is for other users to
understand the processes used.
Another important consideration is to make your code easy to follow. It is all very
well to do really neat, clever things, but when you or someone else needs to
modify the code some months later, practices like these can lead to frustration,
errors and wasted time. Generally speaking, efficiency is nowhere near as
important as maintainability.
If your site has any standards for coding, documentation, or variable naming
conventions, adhering to these makes it easier for others to maintain your code.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial How to Write a Program 42
Make the Code Robust
Protecting your code against bad data and inexperienced users is also important.
If there is something wrong, display an error message. Failure to do so can lead to
wasted time on the part of the user in trying to track down the cause of erroneous
results. If you are thorough in ensuring that your data is valid, you can also prevent
the user from having to call the programmer to sort out these problems.
Remain Logical
When a program does not work, and resists all your best efforts to make it work, it
is easy to become desperate and frustrated. It is important to tackle the problem in
a logical, analytical way, working through the code by hand. If necessary, use
debugging display statements to report what the program is doing.
Re-Use Existing Code
Often, problems related to the one you are trying to solve will have been tackled
before. Looking through existing code is an efficient way of learning how to go
about solving your own problem, as well as providing an insight as to how the
Loglan language can be used. The Loglan programs included in the Geolog
distribution would often be a good place to start. Generally speaking, these
programs are well documented and well written, and provide worthwhile examples
of good programming techniques.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 43
Loglan Language Syntax
Procedure
This section deals with the details of the language itself. You should also have access to the
Loglan online help documentation, as this tutorial contains only general information to guide
you on what to look for in the documentation. You will:
Create a program to calculate and display porosity.
Create an interactive user input program.
Create several programs to read or write to external files.
Create a program to analyze data on an interval basis across multiple wells.
Create a program using data from frames other than the current one.
Program Structure
The first section of any Loglan program is the declaration section, which is used to
declare the variables used by the program. It is maintained by mui_loglan (using
the Input/Output tab of the Loglan window), and it should not be otherwise
modified.
The next logical section is the program code section, containing the instructions to
be executed by the program when it runs. This may be logically subdivided into:
the initialisation section, which contains code which does not need to be
executed for each data frame; this code precedes the program's "dowhile
GET_FRAME" loop.
the processing section, which contains the code to be executed for each data
frame.
Then follows the end section, which consists only of the keyword end and tells the
Loglan processor that the end of the code has been reached. It is required only if
the program contains subroutines. When the end statement is executed, the
Loglan program terminates.
Optionally, there may be a subroutines section containing segments of code which
may be executed from within the processing section. See "Subroutines" on
Page 48 for further information.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 44
Source File Format
Continuation character
Generally, the Loglan source contains one command or statement per line. If a
statement is long, it may be split over more than one line by terminating every line
but the last with the continuation character, ~ (tilde).
Statement separator
More than one statement may be placed on a line by using the statement
separator character, ; (semicolon).
Comment
A comment, preceded by the comment specifier, /* (forward slash and star), may
appear either on a line by itself or at the end of a statement.
Blank lines
Blank lines are ignored but may be used to logically group sections of code.
Case
Case, except in character constants, is ignored. Conventionally, local variables
are lowercase while all other variables are uppercase, but you are free to use no
case or your own convention.
Types of Statement
Loglan has three fundamental types of statement:
assignment statements used to assign a value to a variable.
control statements change the normal sequential flow of a program;
among other things, they may be used to either
conditionally or repeatedly execute groups of
statements.
function call statements executes a Loglan provided function.
We will deal with each of these types in turn.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 45
Assignment Statements
An assignment statement has the form:
variable = expression
where variable is any variable defined in your Loglan program, and
expression is a combination of variables, constants, function calls and
operators, whose result is a single value.
A function call in an expression consists of the function name, an opening round
bracket, the function argument (or arguments, separated by commas), and a
closing round bracket. For example: ATAN ( 5, 10 ). Details of the functions
available in Loglan are covered in "Loglan Functions" on Page 49.
Expressions
An expression in Loglan has two attributes, a type and a value. The type of an
expression may be numeric, alphanumeric or character, or logical; these are the
same types which are defined for variables. The type of an expression is determined
by the types of the variables and constants it contains; in general, all the variables in
an expression must be of the same type, and the expression in an assignment
statement must have the same type as the variable to which it is being assigned.
Numeric expressions
Numeric expressions can contain numeric variables (e.g. depth), numeric
constants (e.g. 3.14159), or functions returning a numeric value (e.g. SQRT),
combined with numeric operators.
The operators and their order of precedence are described in "Operators" under
the "Program Syntax" section of the Loglan online help documentation. Note that
operators of equal precedence are evaluated from left to right; thus 5/2*4
evaluates to 8. This is because when all the components of an expression are
integers, the expression will be evaluated using integer arithmetic, so 5/2 = 2. If
you want the evaluation performed using real values, add a decimal point at least
one of the numbers.
Character expressions
Like numeric expressions, character expressions can contain character variables,
character constants (e.g. 'Hello'), or functions returning a character value
(e.g. UPCASE), combined with character operators. The only character operator is
the concatenation operator, //.
Logical expressions
Logical expressions contain logical variables, logical constants (e.g. TRUE),
logical functions (e.g. MISS), and logical operators such as NOT, AND, and OR.
Additionally, logical expressions may contain other types of variables combined
with relational operators such as < (less than), <> (not equal to), etc.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 46
Constants
Constants, like variables and expressions, come in 3 flavours: numeric, character,
and logical. Numeric constants are just numbers, such as 5 or 1.234. Additionally,
Loglan has pre-defined numeric constants such as PI, MISSING, and TOP_DATA.
A character constant consists of a sequence of characters enclosed in single
quotes, such as 'Here is an example'.
There are two logical constants, TRUE and FALSE.
Control Statements
Normally, statements in a Loglan program are executed sequentially. Control
statements are used to alter this flow.
if statement
The if statement lets you conditionally execute other statements. Its basic form is:
if ( logical-expression ) then
statements
endif
This statement will cause the statements following the "if" to be executed if the
logical expression evaluates to TRUE. The brackets around the logical expression
are optional. You may optionally have one or more elseif statements, optionally
followed by an else statement. For example:
if ( OPT_GR == 'LINEAR' ) then
VSH_GR = v
elseif ( OPT_GR == 'STIEBER1' ) then
VSH_GR = v / ( 3.0 - 2.0 * v )
elseif ( OPT_GR == 'LARINOV1' ) then
VSH_GR = 0.33 * (( 2.0 ** ( 2.0 * v )) - 1.0 )
else
DISPLAY_ERROR ( 'Invalid option: ' // OPT_GR )
endif
for statement
The for statement is used to repeatedly execute a group of statements. Its form is:
for <numeric variable> = <init> to <final> [by <step>] do
statements
endfor
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 47
This statement will execute the statements in the body of the loop, varying the loop
variable from the initial value to the final value, incrementing the loop variable by
the step after each iteration. If the "by step" is omitted, a value of 1 is assumed.
The loop is pre-tested. This means that the loop is not executed if the value of the
loop variable is greater than the final value. The step may be negative. For
example:
sum = 0
for i = 1 to 20 do
sum = sum + i
endfor
do until statement
This is a post tested loop which executes a group of statements until the
termination condition evaluates to TRUE. Its format is:
do
<statements>
until <logical expression>
See "Program Control" under the "Program Syntax" section of the Loglan online
help documentation for an example.
dowhile statement
The dowhile statement has the form:
dowhile <logical expression>
statements
enddo
It is more or less the opposite of the do until statement: the condition is tested
before the statements in the body are executed, and the loop continues to execute
until the condition evaluates to FALSE.
goto statement
The goto statement has the form:
goto <label-name>
where label-name is a name (the validity rules are the same as for variables)
which appears elsewhere in the program as a label, consisting of the label name
immediately followed by a colon (:). This command causes execution flow to be
transferred to the statement following the label. It can be useful for skipping
sections of the program, if an error occurs.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 48
Function Call Statements
A function call statement is used to execute an internal Loglan function. This may
be done in one of two ways. The first method is to use the function name in place
of a variable name, with the arguments to the function (separated by commas if
the function has more than one argument) in round brackets after the function
name. If the function has no arguments, you must use () after the function name.
The second method is to use the call command before the function name,
followed by the arguments as before; in this case, the function result is ignored.
This will be more fully described in "Loglan Functions" on Page 49.
Subroutines
A subroutine is a block of code which may be called from (often multiple places)
within a Loglan program. It is often preferred to inline code to make the program
more modular and easier to understand, or to eliminate duplication of the
subroutine code if it is to be executed from more than one place in your program.
Subroutines are coded after the end statement within the Loglan program (the
end statement causes the Loglan program to terminate execution), and are
executed by the perform command. A subroutine begins with a label, which is the
name of the subroutine used in the perform command. A label consists of a name
(the validity rules are the same as for variables) followed by a colon (:). Then
follow the instructions to be executed in the subroutine, including one or more
return commands. The return command causes execution to transfer to the
command immediately following the perform command which caused the
subroutine to be called. For example:
<statements>
perform sub1
<statements>
end
sub1:
<statements>
return
would execute the expressions up to the perform command, then transfer
execution to subroutine sub1, and then jump back to the line following the perform
statement.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 49
Loglan Functions
Much of the power of the Loglan language comes from the wide variety of
functions supported by the language. These are all described in the "Functions"
section of the Loglan online help documentation. In this tutorial, we will discuss
only the more important ones.
All Loglan functions return a result, but often the result is ignored (for example
put_frame). The case of the function name is not significant. Spaces around the
parentheses, as well as between the arguments, are ignored.

In the examples which follow, the word "text is used to indicate an alpha or
text variable, while "numeric" is used for a numeric variable, and logical for
a logical variable.
Display Functions
At any time during the execution of a Loglan program, you can display messages
in the Message area at the bottom of Geologs Well or Project application
windows. These messages could be results of calculations, status comments,
variable input values, or any other text.
The Loglan functions in this category are:
DISPLAY_MESSAGE ( 'Text for Display' )
and
DISPLAY_ERROR ( 'Error message' )
The argument can be either a quoted string (as in the examples above), or an
alpha variable or expression. Both functions display their argument in the
Message area of the window. In addition, the second function causes the Loglan
program to abort with an error condition. It is useful if you want the program to
abort if, for example, the input data is invalid. A few further examples:
DISPLAY_MESSAGE ( 'Processing interval ' // INTERVAL )
call DISPLAY_ERROR ( 'Invalid option: ' // option )
Note that the call can be omitted. In the first example, if INTERVAL was defined
as an interval constant, it would automatically contain the name of the interval
being processed, if you are processing intervals (otherwise, it will be blank).
If you want to display the value of a numeric variable, you will first need to convert
its value to text using one of the functions described in "Conversion Functions" on
Page 50. For example:
DISPLAY_MESSAGE ( 'Value of SW: ' // NUMSTR ( SW ) )
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 50
Conversion Functions
This group of functions converts character to numeric variables and vice versa.
These include:
NUMSTR function
Converts a numeric variable to a string (text), using a fixed precision of 13 digits.
The syntax for this is:
text = NUMSTR ( numeric )
CONVERT function
Similar to the NUMSTR function, except that it provides two additional facilities.
Firstly, you can control the number of character positions (field width) as well as
the number of decimal places to be used. Secondly, you can add additional text to
the resulting text string.
text = convert ( format, numeric )
where format is a text literal or variable which defines how the numeric variable is
to be converted. It consists of text which is copied to the function result, and a field
code enclosed in curly brackets. The value of the numeric, formatted according to
the field code, replaces the field code in the function result. The field code has the
form Nw.d, where "w" is the number of characters to be used, and "d" specifies
the number of decimal places. For example:
CONVERT ( 'The value of Sw is:{N8.3}', sw )
would produce the string "The value of Sw is:0.134" (where "" represents a
space) if the value of sw was 0.134234455. As a further example, if you have
variables DEPTH, RHOB and NPHI with values of 5200, 2.56, and 0.176
respectively, then
CONVERT ( '{N8.3}', DEPTH ) // ~
CONVERT ( '{N8.3}', RHOB ) // ~
CONVERT ( '{N8.3}', NPHI )
would produce "5200.0002.5600.176".
STRNUM function
Converts a string to a number:
text = STRNUM ( '1.23456' )
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 51

In this and the other exercises which follow, the variables listed are only
suggestions. Also, the flow of the program is indicated by comments.
Example solutions can be found in the /loglan/examples subdirectory.
In this exercise, you will write a program to display the average value of porosity
for a well.
The program is to calculate a simple value of density porosity and display the
average for the well to the Message area of the Well application. Use the
formula porosity = ( RHO
ma
- RHOB ) / ( RHO
ma
- RHO
fl
).
Program: DISP_POR
Input variables:
RHO_MA (Constant, G/CC) (Validation Range 1.5 - 3.5)
RHO_FL (Constant, G/CC) (Validation Range 0.5 - 1.2)
RHOB (Log)
Local variables:
poro, count, sum
Program steps:
/* Initialise variables.
/* Loop through the data.
/* Calculate porosity, increment sums.
/* End loop.
/* Calculate average.
/* Display the calculated average.

REMEMBER: all INPUT to the computer is in Bold Courier New, while all
OUTPUT from the computer is in Courier New, but not bold (i.e., the code
for the comments listed above which are NOT bold are automatically
created by mui_loglan).
ASK Functions
ASK are used to obtain interactive user input. They are most often used when the
input required depends on the parameters passed to the programotherwise, it
would be much more efficient to get the required values by using module
parameters. For these functions to work, the environment variable MIN_DIALOGS
must be set to TRUE, otherwise, the default value is returned. If you are not sure
how to do this, contact your Geolog administrator.
Exercise 1
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 52
In the normal case, a popup window appears into which the user enters the
required value. There are three functions involvedone each for text, numeric,
and logical values; these are ASKS, ASKN, and ASKL, respectively. They all have
the same syntax:
result = ASKx ( prompt, default )
where prompt is a literal or text variable containing the prompt to be displayed,
and default is the value (which must be of the appropriate type) to be used if the
user does not enter a value. For example:
rho_ma = ASKN ( 'Enter value of Rho Matrix:', 2.65 )
or, exactly equivalently:
string = 'Enter value of Rho Matrix:'
rho_ma = 2.65
rho_ma = ASKN ( string, rho_ma )
In this exercise, you will create an "interactive" program.
The program will calculate Sw using the Archie formula
sw=SQRT(rw/(rt*phi**m))
and display the result in the feedback window.
Because the program requires no input or output parameters, all variables will
be local.
The program should ask for, and display, a username (merely so we can
demonstrate ASKS), and should iterate, if required.
Exercise 2
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 53
Program: ASK_SW
Local variables:
rw, m, phi, rt, sw, name (ALPHA*16), again (LOGICAL)
Program steps:
/* Initialize logical variable.
/* Ask for the user's name.
/* Start the iteration loop.
/* Get the values for the variables.
/* Calculate the water saturation.
/* Display the results.
/* Ask the user whether to run again.
File Access Functions
In addition to accessing data from the Geolog database, Loglan programs can
access external files for both input and output. Text files can be both read and
written by a Loglan program, allowing you to perform data manipulation as well as
loading or unloading data. In this section of the tutorial, we will discuss the
functions involved in opening and closing external files, and those which facilitate
reading and storing data in those files.
File Opening
To access a text file in a Loglan program, it must first be opened:
logical = FOPEN ( mode, filename, index )
where:
mode is the action that is to be performed on the file'read' opens an
existing file for reading; 'owrite' overwrites an existing file or creates a
new one for writing; and 'awrite' either appends to an existing file, or
creates a new file if the named file does not exist.
filename is the name of the file to be opened, either a literal (quoted string), or
a text variable.
index is a number (or the name of a numeric variable). This index is used to
read from or write to the file. Up to 40 files may be opened at any one
time within a Loglan program, so it is possible to read and write many
files simultaneously.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 54
The function returns TRUE if the file was successfully opened. Possible causes of
failure are:
an invalid file name
a non-existent file opened for read
a non-existent directory
a protection failure
It is good practice to test the result of the FOPEN call so your program can take
the appropriate action if it fails:
if ( ^ FOPEN ( 'read', filename, 1 ) ) then
DISPLAY_ERROR ( 'Failed to open file ' // filename )
endif
This checks if the file can be opened for reading, and aborts the program with an
error message if the file cannot be opened; otherwise, the file is opened and the
index 1 is associated with it.
File Closing
When your Loglan processing has finished processing a file, it must be closed
using the FCLOSE function:
FCLOSE ( index )
where index is the file index with which was opened by FOPEN.
Reading from a File
External files are always read sequentially; the next line from the file is returned by
the FREAD function:
text = FREAD ( index )
where index is the number used in the FOPEN call. If no more data remains to be
read from the file, the string EOF is returnedif you want to detect end-of-file, you
must test for this result. This is a common way of processing a file:
record = FREAD ( 1 )
dowhile ( record <> 'EOF' )
<process data in "record">
record = FREAD ( 1 )
enddo
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 55
Processing the Data Read from a File
Because FREAD returns a single character string, you usually need to do some
work to extract the data from this string. The method used depends on how the
data is stored in the file. If it is in fixed columns, it is most efficient to use the
SUBSTRING function. If the data is not stored this way, or if you want to take the
easy way out, use the TOKEN function:
text = TOKEN ( string, index )
where string contains the text from which a token is to be extracted, and index is
the number of the token to be extracted. A token is a string of characters delimited
by one or more spaces. The function draws a blank if there are fewer then index
characters in the passed string. For example, if the variable record contained "a b
ab 123.456", then
numeric = STRNUM ( TOKEN ( record, 4 ) )
would assign 123.456 to the variable numeric.
To retrieve data from fixed positions in a record, use the SUBSTRING function:
text = SUBSTRING ( string, start, length )
where string contains the text from which the substring is to be extracted, start is
the position of the first character to be extracted, and length is the number of
characters to be extracted from the string. For example:
SUBSTRING ( '1234567890', 3, 6 )
would return the text 3456.
Other functions which are useful for manipulating text in buffers are INDEX and
TRIM (see "String Related" under "Functions" in the Loglan online
help documentation).
Writing to a File
The FWRITE function is used to write a buffer of data to a file opened for write. Its
format is:
logical = FWRITE ( index, buffer )
where buffer contains the text to be written to the file, and index is the number
used in the FOPEN call. The function returns TRUE unless an error occurred.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 56
By now you should have enough knowledge to complete an exercise to process a
text file containing log data and load it into Geolog.
In this exercise, you will write a program to read data from a fixed-column format
file.
The file to be loaded is in your data subdirectory and is named nuke.asc. The
data contains GR, DRHO, RHOB and NPHI curves in the following fixed-column
format:
DEPTH GR DRHO RHOB NPHI
5100.000 61.155 -0.022 2.452 0.268
5100.500 60.522 -0.018 2.445 0.262
5101.000 58.631 -0.012 2.437 0.253
5101.500 54.852 -0.002 2.425 0.238
5102.000 51.073 0.008 2.414 0.223
5102.500 50.139 0.010 2.421 0.213
As you can see, the file has a header line and then data lines each containing
5 values in fixed fields each 10 character positions long.
In this exercise, the data will be read one line at a time using the FREAD
function, and the resulting text string split into the separate numbers to be used
as data using the SUBSTRING function.
Note that, because there are no input logs, you will not require the dowhile
get_frame loop.
It is VERY important to specify units for the output logs, otherwise, they will be
assumed to be in your preferred units when they are written to the Geolog
database.
Program: READ_COL
Input variable:
FILENAME (Alpha*32) (PARAMETER)
Output variables:
DEPTH (FEET) (LOG)
GR (GAPI) (LOG)
DRHO (G/C3) (LOG)
RHOB (G/C3) (LOG)
NPHI (V/V) (LOG)
Local variable:
buffer (Alpha*80)
Exercise 3
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 57
Program steps:
/* Open the input file, checking for errors.
/* Read (and ignore) the header line.
/* Read first line of data
/* Loop through all the remaining records.
/* Decode the fields in the current record.
/* Write the data to Geolog.
/* Read the next record.
/* Close the input file.
In this exercise, you write a program to read data from a space or tab delimited
file.
This exercise is similar to the previous one, except that the file to be processed
is space or tab delimited rather than in fixed columns. This means that instead
of using the SUBSTRING function, we will use TOKEN.
Note that we could have used TOKEN in the previous exercise, but it is much
less efficient.
The file to be loaded is ./data/sonic.asc, which contains:
# DEPTH DT LLD LLS GR
5100.000 98.9480 4.08 3.01 61.1547
5100.500 99.5305 4.19 3.07 60.5218
5101.000 99.7355 4.39 3.18 58.6305
5101.500 99.3742 4.72 3.36 54.8517
As you can see, the columns are not aligned as they were in the previous
exercise, so it would be very difficult to specify start and length numbers for
each variable; hence, we have to use the TOKEN function.
As in the preceding example, it is VERY important to specify units for the output
logs, otherwise, they will be assumed to be in your preferred units when they are
written to the Geolog database.
Program: LOADER2
Input variable:
FILENAME (Alpha*32) (PARAMETER)
Exercise 4
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 58
Output variables:
DEPTH (LOG), DT (LOG), LLD (LOG), LLS (LOG), GR (LOG)
Local variable:
buffer (ALPHA*100)
Program steps:
/* Open the input file, checking for errors.
/* Read (and ignore) the header line.
/* Read first line of data
/* Loop through all the remaining records.
/* Decode the fields in the current record.
/* Write the data to Geolog.
/* Read the next record.
/* Close the input file.
Note the program steps are exactly the same as those for the previous example.
In this exercise, you create a program which writes data to a text file (data from
the Geolog database will be written to a text file).
Writing to text files has to be done one line at a time, so the buffer to be output
first has to be assembled (unless, of course, you want to output the values one
per line). This is done by concatenating the data values which have first been
converted from numeric to text using the NUMSTR or CONVERT functions.
Program: UNLOAD1
Requirements:
Your Loglan program will create a text file with header lines containing:
LINE1: the well name
LINE2: x location
LINE3: y location
LINE4: the porosity constants RHO_MA and RHO_FL
LINE5: the log names
LINE6: and then, for each data frame, a line containing the depth, RHOB, and
the calculated porosity PHIE
Exercise 5
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 59
See the example below.
In the example above, the items in angle brackets are replaced by values passed
to your program. The format for the lines containing the data values for depth, etc.,
is to be a field width of 10, with 3 decimal places. The porosity PHIE is calculated
using:
PHIE = ( RHO_MA - RHOB ) / ( RHO_MA - RHO_FL )
The calculated porosity, as well as the other module parameters (RHO_MA, etc.),
are to be written back to the Geolog database. The program will be passed a file
name without a directory, but the output file is to be created in the data
subdirectory.
Input variables:
FILENAME (ALPHA*32) (PARAMETER)
WELL (ALPHA*16) (CONSTANT)
X_LOCATION (DOUBLE) (CONSTANT)
Y_LOCATION (DOUBLE) (CONSTANT)
RHOB (K/M3) (LOG)
Input/Output variables:
RHO_MA (K/M3) (INTERVAL)
RHO_FL (K/M3)(INTERVAL)
Output variable:
PHIE (V/V) (LOG)
Local variables:
outfile (ALPHA*32)
repline (ALPHA*80)
EXAMPLE:
Well: <well name>
X_LOCATION: <x location>
Y_LOCATION: <y location>
RHO Matrix: <rho_ma> RHO Fluid: <rho_fluid>
DEPTH RHOB PHIE
<depth> <rhob> <phie>
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 60
Program steps:
/* Create full pathname of the output file.
/* Open the output file.
/* Write the first three lines of header data.
/* Write porosity constants.
/* Start per-frame loop.
/* Calculate porosity.
/* Assemble output line.
/* Output data to text file and database.
/* Close the output file.
Interval and Multiwell Processing Functions
When a Loglan program executes, it is passed the data for one interval (if you are
processing intervals) and for one well (if you are processing multiple wells),
although local variables are initialized only once. Sometimes, you need to be able
to identify whether you are starting a complete run, a new well, or a new interval
(e.g. if you want to calculate an average for an entire project or well). Loglan has a
number of functions to facilitate this:
START ()
FINISH ()
These functions return a logical result which indicates that the current data is
either the first or last to be passed to your Loglan program.
WELL_START ()
WELL_FINISH ()
These functions allow you to identify whether the current data is the first or last for
a well. If you are processing only a single well (using mui_well), these functions
will return TRUE only once (at the start and end of processing). If you are
processing multiple wells (using mui_project), the functions will return TRUE at the
start and end of each well.
INTERVAL_START ()
INTERVAL_FINISH ()
These functions return TRUE when the first or last frame for an interval is being
processed. If you are not processing on an interval basis, they are equivalent to
WELL_START and WELL_FINISH. You would normally use these functions only
within the dowhile GET_FRAME loop, since the code before this loop is executed
at the start of an interval and the code after the loop at the end.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 61
In this exercise, you write a program to calculate Well and Interval Average
values for Porosity.
This exercise is designed to demonstrate the use of the WELL_START and
INTERVAL_START functions to initialize variables at the beginning of the well
and at each interval change. Values of density porosity are to be calculated, and
then averages output to a text file as a report.
Use wells ATLAS, BOTEIN, CAPELLA and DENEB to test your loglan program.
Program: PHI_AVG_RPT
Input variables:
FILENAME (ALPHA*32) (PARAMETER)
WELL (ALPHA*32) (CONSTANT)
RHOB (G/C3) (LOG)
INTERVAL (ALPHA*32) (INTERVAL)
Input/Output variables:
RHO_MA (G/C3) (INTERVAL)
RHO_FL (G/C3) (INTERVAL)
Output variables:
PHIE (V/V) (LOG)
Local variables:
wcount
wsum
icount
isum
Exercise 6
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 62
Program steps:
/* Initialize well totals.
/* Initialize interval totals.
/* Open text file for output if first time.
/* Start looping through the data.
/* Calculate porosity if RHOB is present.
/* Increment interval totals.
/* Increment well totals.
/* At interval end write average porosity.
/* At well end, write well average porosity.
/* At the very end, close the text file.
Frame Positioning Functions
All of the previous exercises have assumed that the process to be carried out is
done on a depth-by-depth basis, so any calculations are only written to a single
depth with inputs from that depth and that depth alone. If a program needs to input
data from surrounding frames, then positioning within the data stream must be
undertaken. This is carried out using the POS_FRAME function, which has the
syntax:
logical = POS_FRAME ( frame_number )
where frames are numbered sequentially from the first depth point to the last depth
point, starting at 1.
In this exercise, you will create a program to calculate a 5-point moving average
of the GR log.
The exercise is designed to demonstrate the use of data from frames other than
the current one. The program should input the GR curve, count the number of
frames, and then position itself frame by frame. At every depth it should read the
GR values from the 2 frames on either side of the current frame, and output an
average value.
Program: MAV_GR
Input variables:
GR (GAPI) (LOG)
Exercise 7
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Loglan Language Syntax 63
Output variables:
GR_MAV (GAPI) (LOG)
Local variables:
count /* Number of frames in average.
frame /* Current frame number.
i /* Loop variable.
n /* Number of frames in data.
sum /* Sum of GR values.
Program steps:
/* Get the number of frames.
/* Loop through the data again.
/* Compute average over window.
/* Calculate value of output log.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Arrays in Loglan 64
Arrays in Loglan
Procedure
In this section, using arrays in Loglan is explained, and you:
Create an array program to sort GR data and derive the 5th and 95th percentiles
of the GR.
Overview
Loglan supports the use of one dimensional arrays. The size of an array is
specified in mui_loglan by specifying the number of elements in the array in
square brackets after the name:
VARIABLE_NAME[array size]
For example, if a variable called arraylog is to have 2000 elements, it would be
declared as arraylog[2000]. The first element of an array has a subscript of one.
References to elements of an array use the same syntax (i.e., variable[subscript]).
The first element of the above array would be arraylog[1].
In this exercise, you create a program which uses an array to 'bubble sort' GR
data, and use this to derive percentiles for use in Vshale calculations.
The exercise is designed to demonstrate the use of arrays, and also to show the
bubble sort algorithm. The GR data is read into an array and then sorted using a
bubble sort procedure. This is then used to derive the 5th and 95th percentiles
of the GR, which are stored into the database as GR Matrix and GR Shale,
respectively.
The algorithm for a bubble sort is as follows:
for i = 1 to n - 1 do
for j = i + 1 to n do
if ( data[i] > data[j] ) then
temp = data[j]
data[j] = data[i]
data[i] = temp
endif
endfor
endfor
This sorts array data, containing n elements, into ascending order.
Exercise 1
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Arrays in Loglan 65
Program: PERCENTILE
Input variable:
GR (GAPI) (LOG)
Output variables:
GR_MA (GAPI) (CONSTANT)
GR_SH (GAPI) (CONSTANT)
Local variables:
n /* Frame count.
i, j /* Loop variables.
data[5000] /* Stored GR values.
temp /* Temporary.
Program steps:
/* Store GR values.
/* Check if room in array.
/* Sort GR values.
/* Calculate the constants.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Log Constants 66
Log Constants
Procedure
This section is a brief overview of using Loglan to access log constants. You will:
Create a program to convert NPHI from decimal to percent if the mean of
NPHI < 1.
Overview
A Loglan program can access log constants for both input and output. They are
defined in mui_loglan using, for example, InsertInputLog Constant. Log
constants have names of the form constant_logname, where constant is the name
of the required constant and logname is the name of a log (which must have been
previously defined).
The available constants include: NAME, MEAN, MIN, MAX, STDDEV, TOP,
BOTTOM, and UNITS (see "Declaration Section" under "Program Syntax" in the
Loglan online help documentation for a full list). Note that the value of most output
log constants is ignored, since these are normally calculated automatically by the
Geolog database. Log constants are never displayed in the Module Launcher
window, as they are always automatically derived from the corresponding log.
In this exercise, you will write a program to convert NPHI from decimal to
percent if the mean of NPHI < 1.
The exercise shows the use of Log header constants to determine whether a log
has a mean of less than 1, and multiplies it by 100 if it does. This is (or should
be) a somewhat artificial example, since, if proper procedures have been
followed, the NPHI log should have its units specified, and if we specified units
in our Loglan program, the data would be automatically converted to these units.
Also, it is important that, for this exercise, the output log not exist in the loginfo
file, otherwise, the results would be automatically converted to your preferred
units.
Program: NPHI_PC
Input variables:
NPHI (no units) (LOG)
MEAN_NPHI(no units) (LOG CONSTANT)
Exercise 1
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial Log Constants 67
Output variable:
NEW_NPHI (%) (LOG)
Program steps:
/* Calculate conversion factor.
/* Check mean of nphi log.
/* Start looping through data.
/* Convert.
/* Write to Geolog database.
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial External Functions 68
External Functions
Procedure
External C and Fortran functions can be called from within a Loglan program. Because the
Loglan program is converted to C, it is easier if the external function is also written in this
language, although Fortran may also be called if the argument passing mechanism
is compatible.
Because Loglan does not allow unknown external functions to be called directly, it is
necessary to enter into C mode in order to make the function call. This is done using the
following syntax:
.cc_begin
Variable = user_function (arg1,arg2...)
.cc_end
The "CPUTIME Example" on Page 69 is a Loglan programme that calls a
C function named c_cputime. The variable CPUTIME_C is the Loglan variable that
is passed to the function, modified by the function and then passed back to Loglan
to be written to the Geolog database.
You have a copy of this examplecompile and run it, and then view the results.
You may also look at the external C function which is located in the /loglan
directory and called c_extern.c
Exercise 1
www.fanarco.net
Geolog 6.6 - Loglan Programming Tutorial External Functions 69
CPUTIME Example
PROGRAM: EXTERN External C example.
/*------------------------------------------------------------------
/*start_doc
/*
/*end_doc
/*------------------------------------------------------------------
INPUT
/*
/* LOGS
---------------------------
/*
DEPTH /* Depth log
LOCAL
OUTPUT
/*
/* LOGS
---------------------------
/*
CPUTIME_C /* CPU time from C
START:
.cc_begin
extern void c_cputime ( double* time );
.cc_end
dowhile GET_FRAME ()
.cc_begin
c_cputime ( &cputime_c );
.cc_end
call PUT_FRAME ()
enddo
end
www.fanarco.net

You might also like