PROGRAM SAMPLE

#include "TKHEADERS.h"
#include "TK_3DPR.h"
#include "tkiofortdeclare.h"

RECORD /TKINFO/ granuleHandle3DPR
RECORD /L3DPR_FS/ L3DPR

    PARAMETER( N_LTL=28, N_LHL=72, N_CHN=3, N_RT=3, N_ST=3 )

	INTEGER status
	INTEGER st, rt, chn, lnL, ltL 
	CHARACTER*255 jobname, file

    REAL*4 precipEsurf(N_LTL,N_LHL,N_CHN,N_RT,N_ST)
    REAL*4 lat, lon

	call getarg( 1, jobname )
	call getarg( 2, file )

! 	Open the file for reading.
!	status = TKopen( file, '3DPR', TKREAD, 'HDF5', jobname, granuleHandle3DPR, 0 )
        status = TKopen( file, '3DPR', TKREAD, 'NETCDF4', jobname, granuleHandle3DPR, 0 )
	IF ( status .NE. TK_SUCCESS ) THEN 
		status = TKmessage( granuleHandle3DPR.jobname, TKERROR,'message to print' )
	ENDIF

!   Grid data read
	status = TKreadGridMulti( granuleHandle3DPR, L3DPR, 'L3DPR_FS' )

    do ltL=1, N_LTL
        do lnL=1, N_LHL
            do chn=1, N_CHN
                do rt=1, N_RT
                    do st=1, N_ST
                        ! precipRateESurface.mean Read
                        precipEsurf(ltL, lnL, chn, rt, st) = L3DPR.G1.precipRateESurface.mean(ltL, lnL, chn, rt, st)

                        ! print the value
                        IF(lnL .eq. 64 .and. ltL .eq. 15 .and. chn .eq. 1 .and. st .eq. 1 ) THEN
                            write(*,*) "st=",st-1,"rt=",rt-1
                            lat = (140.0/28.0) * (ltL-1) - 70.0 + (140.0/28.0/2)
                            lon = (360.0/72.0) * (lnL-1) - 180.0 + (360.0/72.0/2)
                            write(*,*) "lat=",lat,"lon=",lon
                            write(*,*) "chn=1 lnL=64 ltL=15 precipRateEsurface.mean=",precipEsurf(ltL, lnL, chn, rt, st), "(mm/hr)" 
                        ENDIF
                    enddo
                enddo
            enddo
        enddo
    enddo

!   HDF file close
	status = TKclose( granuleHandle3DPR )
	STOP
END
	
