Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

Hull and Outfitting

Example 'C' Program

  • Last UpdatedJan 05, 2024
  • 5 minute read

The 'C' source of this program (FORTRAN source of a similar program is in Section Example 1) is as follows:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include "d3libc.h"

void main (int argc, char **argv)

{

/*

** Main c test program

*/

#define PARAM_ARRAY_LEN 100

PDMS_NAME spcref, catref ;

PDMS_WORD cd3wor, words [ PARAM_ARRAY_LEN ] ;

LOGICAL lval ;

DARS_MESS cd3msg ;

PDMS_TEXT cd3tex, cd3bef, cd3aft ;

DARS_CERR cd3err ;

DARS_RDAT cd3dat ;

float params [ PARAM_ARRAY_LEN ] ;

int id3err, id3nou, i, ival, ilen, id3dat[ 6 ], iparam ;

/* Project entry */

d3init ( "DAR", "SYSTEM", "XXXXXX", "FULL", " ", &id3err ) ;

if ( id3err != 0 ) goto finish ;

/* Get project details */

/* Use fprintf to check that writing to stdout works */

d3umon ( "NONE" ) ;

d3rprj ( "code", cd3tex, &id3err ) ;

fprintf ( stdout, "Project Code: %s\n", cd3tex ) ;

d3rprj ( "name", cd3tex, &id3err ) ;

fprintf ( stdout, "Project Name: %s\n", cd3tex ) ;

d3rprj ( "numb", cd3tex, &id3err ) ;

fprintf ( stdout, "Project Number: %s\n", cd3tex ) ;

d3rprj ( "mess", cd3tex, &id3err ) ;

fprintf ( stdout, "Project Message: %s\n", cd3tex ) ;

/* Return string length */

ilen = d3ulen ( cd3tex ) ;

printf ( "Length of %s -> %d\n", cd3tex, ilen ) ;

/* Get date */

d3udtm ( id3dat, cd3dat ) ;

printf ( "Date is: %s or...", cd3dat ) ;

for ( i = 0; i < 6; i++ ) printf ( " %d", id3dat[ i ] ) ;

printf ( "\n" ) ;

/* Extract integer */

strcpy ( cd3tex, "abcd12345XYZ" ) ;

lval = d3ucti ( cd3tex, &ival, cd3bef, cd3aft, cd3err ) ;

if ( lval != 0 )

{

printf ( "For string: %s\n", cd3tex ) ;

printf ( "Returned integer %d\n", ival ) ;

}

else

{

printf ( "For string: %s", cd3tex ) ;

printf ( ", returned error %s\n", cd3err ) ;

if ( !strcmp ( cd3err, "ADD" ) )

{

printf ( "Returned integer %d\n", ival ) ;

printf ( "String before: %s\n", cd3bef ) ;

printf ( "String after: %s\n", cd3aft ) ;

}

}

strcpy ( cd3tex, "abcdXYZ" ) ;

lval = d3ucti ( cd3tex, &ival, cd3bef, cd3aft, cd3err ) ;

if ( lval != 0 )

{

printf ( "For string: %s\n", cd3tex ) ;

printf ( "Returned integer %d\n", ival ) ;

}

else

{

printf ( "For string: %s", cd3tex ) ;

printf ( ", returned error %s\n", cd3err ) ;

if ( !strcmp ( cd3err, "ADD" ) )

{

printf ( "Returned integer %d\n", ival ) ;

printf ( "String before: %s\n", cd3bef ) ;

printf ( "String after: %s\n", cd3aft ) ;

}

}

/* Select MDB */

d3umon ( "FULL" ) ;

d3mmdb ( "DESIGN/PLANT", " ", &id3err ) ;

if ( id3err != 0 ) goto finish ;

/* Get datestamp */

d3rdat ( id3dat, cd3dat, &id3err ) ;

printf ( "Datestamp is: %s\nor...", cd3dat ) ;

for ( i = 0; i < 6; i++ ) printf ( " %d", id3dat[ i ] ) ;

printf ( "\n" ) ;

/* Move to a pipe component */

d3mnam ( "/100-B-1", &id3err ) ;

ival = 1 ;

d3mnum ( "BRAN", &ival, &id3err ) ;

d3mrel ( "LAST", "FLAN", &id3err ) ;

/* Get spec ref and goto it */

d3rnam ( "SPRE", spcref, &id3err ) ;

printf ( "spcref is: %s\n", spcref ) ;

d3mnam ( spcref, &id3err ) ;

/* Get cat ref and goto it */

d3rnam ( "CATR", catref, &id3err ) ;

d3mnam ( catref, &id3err ) ;

/* Get parameters of component and dehash conn types */

/* Cancel monitor and construct own PRINT statements */

d3umon ( "NONE" ) ;

puts ( "Getting elements with D3RRA" ) ;

ival = PARAM_ARRAY_LEN ;

d3rra ( "PARA", &ival, params, &id3nou, &id3err ) ;

printf ( "Number of elements found: %d\n", id3nou ) ;

for ( i = 0; i < id3nou; i++ )

{

strcpy ( cd3wor, "\0" ) ;

/* If possibly a word, dehash */

if ( params [ i ] >= 531442.0 )

{

iparam = params[ i ] ;

d3udeh ( &iparam, cd3wor ) ;

}

if ( strlen ( cd3wor ) == 0 )

/* Not a word; print real value */

printf ( "Element %d: %f\n", i+1, params [ i ] ) ;

else

/* Valid word; print word */

printf ( "Element %d: %s\n", i+1, cd3wor ) ;

}

/* Alternatively, use D3RWA directly (non-words don"t give error) */

puts ( "Getting elements with D3RWA" ) ;

ival = PARAM_ARRAY_LEN ;

d3rwa ( "WPAR", &ival, words, &id3nou, &id3err ) ;

for ( i = 0; i < id3nou; i++ )

{

if ( strlen ( words [ i ] ) != 0 )

printf ( "Element %d: %s\n", i+1, words [ i ] ) ;

}

finish: ;

/* Cancel monitor and output message */

d3umon ( "NONE" ) ;

lval = FALSE ;

d3emsg ( &id3err, &lval, cd3msg ) ;

printf ( "%s\n", cd3msg ) ;

/* Exit project */

d3fin ( &id3err ) ;

/* Exit DARs */

d3fend ( ) ;

return ;

}

The expected output from this program is as follows. There may some differences in the precision and format of variables. Some of the output is printed by the FORTRAN DARs interface (with monitoring) and some is printed by the 'C' program.

AVEVA DARs C Interface Mk12.000 (WINDOWS-NT 5.2) (7 Sep 2007 : 23:36)

This version of Marine was issued to <your company>

and will only operate on registered hardware

PDMS DARs Mk12.0.0.0 (WINDOWS-NT 5.2) (7 Sep 2007 : 23:36)

(c) Copyright 1974 to 2007 AVEVA Solutions Limited

Issued to <your company>

Entering subroutine D3INIT

Input arguments:

Project name DAR

Username SYSTEM

Password XXXXXX

Monitoring level FULL

Read/Write key

Exiting subroutine D3INIT

Output arguments:

Error code 0

Entering subroutine D3UMON

Input arguments:

Monitoring level NONE

Exiting subroutine D3UMON

Entering subroutine D3MMDB

Input arguments:

MDB name DESIGN/PLANT

Read/Write key

Exiting subroutine D3MMDB

Output arguments:

Error code 0

Entering subroutine D3RDAT

Exiting subroutine D3RDAT

Output arguments:

Date-stamp 04 Jul 2000 17:56:24

Year, Month, Day 2000 7 4

Hour, Minute, Second 17 56 24

Error code 0

Entering subroutine D3MNAM

Input arguments:

Element name/ref /100-B-1

Exiting subroutine D3MNAM

Output arguments:

Error code 0

Entering subroutine D3MNUM

Input arguments:

Element type BRAN

List position 1

Exiting subroutine D3MNUM

Output arguments:

Error code 0

Entering subroutine D3MREL

Input arguments:

Relative position LAST

Element type FLAN

Exiting subroutine D3MREL

Output arguments:

Error code 0

Entering subroutine D3RNAM

Input arguments:

Attribute required SPRE

Exiting subroutine D3RNAM

Output arguments:

Name/Reference /A3B/100F1

Error code 0

Entering subroutine D3MNAM

Input arguments:

Element name/ref /A3B/100F1

Exiting subroutine D3MNAM

Output arguments:

Error code 0

Entering subroutine D3RNAM

Input arguments:

Attribute required CATR

Exiting subroutine D3RNAM

Output arguments:

Name/Reference /FUAAPAMM

Error code 0

Entering subroutine D3MNAM

Input arguments:

Element name/ref /FUAAPAMM

Exiting subroutine D3MNAM

Output arguments:

Error code 0

Entering subroutine D3UMON

Input arguments:

Monitoring level NONE

Related Links
TitleResults for “How to create a CRG?”Also Available in