Read the node properties#

See also

Visual Basic for Applications - Examples

Problem Description#

In this example we will read the nodes data from the database.

Following values are extracted:

  • NR (node number)

  • INR (internal node number)

  • KFIX (degree of freedoms, bitwise encoded)

  • NCOD (additional bit code)

  • X (global X coordinate)

  • Y (global Y coordinate)

  • Z (global Z coordinate)

The nodes description can be found in CDBASE.CHM as shown in figure below:

../../_images/vba_read_nodes_1.png

The [INT] means that the data-type is integer. The data-type can easily be checked in the data-type list given in the example.

Problem Solution#

The example can be found by following:

C:\<sofistik_installation>\2024\SOFiSTiK 2024\interfaces\examples\fortran\read_nodes

Here is a code example how to read the nodes from the CDB:

program read_nodes
   use cdbase
   implicit none

   ! this is our data type for nodes
   type cnode                   ! 20/00  Nodes
      sequence
      integer   nr             !        node-number
      integer   inr            !        internal node-number
      integer   kfix           !        degree of freedoms
      integer   ncod           !        additional bit code
      real*4      xyz(3)       ! [1001] X-Y-Z-ordinates
   end type cnode

   ! Define the variable
   integer :: nid, l, ie, index
   character(len=30)   :: file
   character(len=72)   :: text
   type(CNODE) :: dataval
   integer :: datalen, pos
   integer :: kwh, kwl, ret

   ! Define the parameters for cdinti()
   ! nid = 99,     test if NAME is a valid database and open the base if possible.
   !               Return with the assigned index.
   !               If the file does not exist, it will be created.

   nid=99

   !name of the cdb or the full path
   file = "S:\test\read_nodes.cdb"

   ! Connect to the CDB
   call cdinit(file,nid)
   if (nid > 0) then
      write(*,*) "  cdb_init of ", file," successful ", nid
   else
      write(*,*) "  cdb_init of ", file," not successful ", nid
   endif

   ! Lets read the nodes now
   index = nid
   kwh = 20
   kwl = 0
   datalen = 28    ! for nodes we have datalen = 28
   pos = 1         ! set position to 1, see cdbase.chm
                  ! = 0 Position to first Item (REWIND)
                  ! > 0 Read next item from current read pointer
                  !     read pointer will advance by one item.
   ie = 0          ! return value for the cdget

   ! Read the nodes
   do while (ie == 0)  ! Read data while ie == 0, Returnvalue:
                        ! (0) no error,
                        ! (1) Item is longer than Data,
                        ! (2) End of file reached
                        ! (3) key does not exist

      call cdget(index, 20, 0, dataval, datalen, pos, ie)
      print *, dataval
   end do

   ! Close the CDB
   call cdclose(0)

   ! Get the status and print it (if .cdb is closed status = 0)
   call cdstat(nid, ret)
   print *, "Status:", ret

   ! The console will close if we press <ENTER> key
   print *, "Press <ENTER> key to close the program"
   read (*,*)
end program read_nodes