! $Id: cabb_init_calc.f90,v 1.2 2009/04/10 12:28:24 wil844 Exp wil844 $ ! ! Initialise CALC ! - Read Database ! - Setup EOP parameters ! - Setup sites ! - Set current source ! ! integer*4 function cabb_init_calc( utctag, nsrc, c_src_name, src_ra, src_dec,& & src_pmra, src_pmdec, src_pmepoch, pm_enable, & & c_return_msg ) implicit none ! PARAMETERS integer*2 utctag(5) integer*4 nsrc byte c_src_name(24,*) real*8 src_ra(*), src_dec(*) real*8 src_pmra(*), src_pmdec(*), src_pmepoch(*) integer*4 pm_enable byte c_return_msg(*) ! EXTERNAL ROUTINES integer*4 cabb_load_sites integer*4 load_source integer*4 cabb_eop_setup ! For OLD EOP method - using eopc04.yy format ! integer*4 eop_setup integer*4 IFLAG(62) ! LOCAL VARIABLES integer*4 i, j, lun, status, kount character*80 str, return_msg character*16 src_name ! For OLD EOP method - using eopc04.yy format ! character*48 eop_str(4) ! BEGIN lun = 19 ! Open CALC database file - defined in environment variable 'CALC_DATABASE' call get_environment_variable( 'CALC_DATABASE', str ) if( str(1:8) .eq. ' ' ) then return_msg = 'CALC_DATABASE Environment NOT SET' go to 1099 end if open( UNIT=lun, STATUS='old', FILE=str, ERR=9766 ) go to 9767 9766 continue return_msg = 'CALC DATABASE: "' // TRIM( str ) // '" NOT FOUND' go to 1099 9767 continue ! Read control flags from calc database file and load /CON/ common area call dbflag( lun, iflag, status ) if( status .ne. 0 ) then return_msg = 'BAD CONTROL FLAG READ in DBFLAG() ' go to 1098 end if ! Overwrite proper motion enable control flag if( pm_enable .ne. 0 ) iflag(21) = 2 ! Load flags into calc common area - ! also sets iluout=-1 to disable debug printouts call load_flags( iflag ) ! Read data from calc database file call dbcom( lun, status ) if( status .ne. 0 ) then return_msg = 'BAD DATABASE READ in DBCOM()' go to 1098 end if ! Close database file close( lun ) ! Load initial start UTC call load_start_utctag( utctag ) ! Load sites status = cabb_load_sites( str ) if( status .ne. 0 ) then return_msg = ' LOAD_SITES(): ' // TRIM( str ) go to 1099 end if ! Load sources do i = 1, nsrc ! Convert C string ( byte array ) to Fortran string call c2fstr( c_src_name(1,i), src_name ) ! status = load_source( i, src_name, src_ra(i), src_dec(i), & & src_pmra(i), src_pmdec(i), src_pmepoch(i) ) if( status .ne. 0 ) then return_msg = ' LOAD_SOURCE(): Too many sources ' go to 1099 end if print *, ' INIT_CALC: Loaded source ', i, src_name, src_ra(i), src_dec(i) end do ! Load EOP parameters ! For NEW EOP method- using ATCA iersa.file format if( cabb_eop_setup( utctag, str ) .lt. 0 ) then return_msg = 'In cabb_eop_setup(): ' // TRIM( str ) go to 1099 end if ! For OLD EOP method - using eopc04.yy format ! if( eop_setup( utctag, eop_str, str ) .eq. 0 ) then ! return_msg = 'In eop_setup(): ' // TRIM( str ) ! go to 1099 ! end if ! Initialise CALC call tocup call initl( kount ) ! Normal return cabb_init_calc = 0 c_return_msg( 1 ) = 0 return ! Error return 1098 continue close( lun ) 1099 continue j = LEN( TRIM( return_msg ) ) do i = 1, j c_return_msg( i ) = ICHAR( return_msg(i:i) ) end do c_return_msg( j + 1 ) = 0 cabb_init_calc = -1 return end function cabb_init_calc