Previous: More Object Description Files
Up: Tutorial
Next: Using object classes
Previous Page: More Object Description Files
Next Page: Using object classes

Access to data

Following fortran subroutine accesses DSPACK data. It expects a structure of constants POINT_C_T to exist, copies it's contents into it's own structure and uses it to create 10 entries of structure point_t.

Example of access to data - point_fill.f file

subroutine fill_points(ierr)
* 
*   ********************************************************************
*   *                                                                  *
*$$ *   subroutine fill_points  put some random data into 10 points    *
*   *                                                                  *
*   ********************************************************************
* 
      structure /V3/                                    
         real  x               
         real  y               
         real  z               
      end structure
      structure /point_t/                               
         record/V3/  pos             
         record/V3/  d               
         integer  flags(2)        
         integer  next           
      end structure
      record/point_t/ point(1)
      pointer ( point_p,point )

structure/POINT_C_T/ real A real B real C real D end structure record/POINT_C_T/ PC(2)

data ivdsn_point/0/ data ivdsn_const/0/

* Get constants into PC

call dsget('POINT_C_T',ivdsn_const,2,nent,PC,ierr) if( nent.eq.0 ) return

* Tell DSPACK that right now we want pointers (remember what it was before)

mode_old = ids_pnt_conv(1)

* Make 10 points

point_p = idsput_ds('point_t',ivdsn_point,10) if( point_p.eq.0 ) then write(*,*)'Cannot make points' go to 995 endif

* Build two link-lists of points: * (1 3 5 7 9) and (2 4 6 8 10)

z0 = 0.0 do i=1,9,2 point(i).pos.z = z0 point(i).pos.y = PC(1).A*point(i).pos.z + PC(1).B point(i).pos.x = PC(1).C*point(i).pos.z + PC(1).D

point(i).d.z = 0.01 point(i).d.y = 0.01*point(i).pos.y point(i).d.x = 0.01*point(i).pos.x

point(i).flags(1) = 1 point(i).flags(2) = 2

point(i).next = loc(point(i+2)) z0 = z0 + 1.0 enddo point(9).next = 0

z0 = 0.0 do i=2,10,2 point(i).pos.z = z0 point(i).pos.y = PC(2).A*point(i).pos.z + PC(2).B point(i).pos.x = PC(2).C*point(i).pos.z + PC(2).D

point(i).d.z = 0.01 point(i).d.y = 0.01*point(i).pos.y point(i).d.x = 0.01*point(i).pos.x

point(i).flags(1) = 1 point(i).flags(2) = 2

point(i).next = loc(point(i+2)) z0 = z0 + 1.0 enddo point(10).next = 0

* Tell DSPACK that we have finished with point_t

call ds_update('point_t',ivdsn_point,ierr)

* Reset pointer/index flag to what it was before

995 continue idum = ids_pnt_conv(mode_old)

end

Structure of constants POINT_C_T is defined and initialized in another object description file which should be used now instead of dspack_tut_2.d.

Object initialization - dspack_tut_4.d

* 
*   ********************************************************************
*   *                                                                  *
*$$ *   dspack_tut_4.d  DSPACK tutorial - example 2                    *
*   *                                                                  *
*   ********************************************************************
*

DEFINE point_t S 1 ! define structure point_t, section 1 V3 pos ! position V3 d ! position errors .INT4 flags(2) point_t *next ! pointer to the next hit on track END DEFINE -CLASS point -TYPE 0

DEFINE vertex_t S 1 ! define structure point_t, section 1 V3 pos ! position V3 d ! position errors .INT4 n_tracks ! number of tracks .INT4 flags(2) track_t *tracks ! pointer to tracks END DEFINE

DEFINE POINT_C_T R 2 ! define point constants, section 2 "Y slope" A "Y intercept" B "X slope" C "X intercept" D END DEFINE

INIT POINT_C_T(1) CREATE 2 ! Initialize two entries A = 0.01 B = 1.0 C = 0.02 D = 0.5 END INIT

INIT POINT_C_T(2) A = 0.03 B = 3.0 C = {POINT_C_T(1).C} D = 2.5 END INIT

This file defines POINT_C_T as well as point_t and vertex_t and then proceeds to initialize POINT_C_T. Note how POINT_C_T(2).C is initialized in terms of another object. The definition of point_t has changed - it contains keywords setting a class of an object. Before this file is used we have to establish a new class of objects called point.

wwwd@na49
Fri Nov 4 01:54:15 MET 1994