Fortran language example

This example uses the following file name: libenv.f.

Code

The environment and shared library classes provide information about the environment and libraries associated with an AE. This example takes one argument, an integer. If the integer equals 0, the AE outputs the environment it sees. If the integer equals 1, the AE looks the environment up as a library.
program logRunUdtf
call nzaeRun()
stop
end
subroutine nzaeHandleRequest(handle)
integer outputType, hasNext, isNull
hasNext = -1
outputType = -1
isNull = -1
c GET INPUT.
call nzaeGetNext(handle, hasNext)
if (hasNext .eq. 0) then
return
endif
c OUTPUT EITHER THE ENVIRONMENT OR THE LIBRARIES.
call nzaeGetInputInt32(handle, 0, outputType, isNull)
if (outputType .eq. 0) then
call outputEnvironment(handle)
else
call outputLibraries(handle)
endif
return
end
subroutine outputEnvironment(handle)
character(1000) name, value
integer hasNext
name = "init"
value = "init"
hasNext = -1
c OUTPUT THE FIRST VALUE.
call nzaeGetFirstEnvironmentVariable(handle, name, value)
call nzaeSetOutputString(handle, 0, name)
call nzaeSetOutputString(handle, 1, value)
call nzaeOutputResult(handle)
100 call nzaeGetNextEnvironmentVariable(handle, name, value, hasNext)
if (hasNext .eq. 0) then
return
endif
call nzaeSetOutputString(handle, 0, name)
call nzaeSetOutputString(handle, 1, value)
call nzaeOutputResult(handle)
goto 100
end
subroutine outputLibraries(handle)
character(1000) name, path
integer number, autoload, onLibrary
name = "init"
path = "init"
number = -1
autoload = -1
onLibrary = 0
c GET THE NUMBER OF SHARED LIBRARIES.
call nzaeGetNumberOfSharedLibraries(handle, number)
c GET SHARED LIBRARY INFO.
200 if (onLibrary .eq. number) then
return
endif
call nzaeGetSharedLibraryInfo
+ (handle, onLibrary, name, path, autoload)
onLibrary = onLibrary + 1
c OUTPUT THE NAME AND PATH.
call nzaeSetOutputString(handle, 0, name)
call nzaeSetOutputString(handle, 1, path)
call nzaeOutputResult(handle)
goto 200
end

Compilation

Use the standard compile:
$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language fortran --version 3 \
--template compile libenv.f

Registration

Register the example:
$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language fortran --version 3 \
--template udtf --exe libenv --sig "lib_env(int4)" \
--return "table(name varchar(1000), value varchar(1000))"

Running

Note that the output from this example is specific to the environment. Therefore, your actual output will resemble, but not match, the following text.
SELECT * FROM TABLE WITH FINAL(lib_env(1));
NAME | VALUE
----------------+--------------------------------------------------------
LIBNZAEADAPTERS | /nz/DATA/base/1/library/200245/host/libnzaeadapters.so
LIBNZAECHILD | /nz/DATA/base/1/library/200247/host/libnzaechild.so
LIBNZAEPARENT | /nz/DATA/base/1/library/200244/host/libnzaeparent.so
(3 rows)
SELECT * FROM TABLE WITH FINAL (lib_env(0)) LIMIT 5;
NAME | VALUE
-----------------------+-------------------------------------------------
NZAE_NZREP_VERSION | 6
NZREP_TEMP_FILE | /nz/tmp/nzrep_DYxBgF
NZREP_PARAMETER1 | 12
NZREP_PARAMETER0 | 11
NZAE_EXECUTABLE_PATH_RUN | /nz/export/ae/applications/system/admin/host/libenv
(5 rows)
Note: This output might vary as the name might be preceded by a database name with periods separating it from the library name. For example, xxx..LIBNZAECHILD. Also, the numbers displayed in the value path name might be different and of the form: /nz/DATA/base/<dbOID>/library/<objectOID>/host/<libraryname>.so.