c***********************************************************************
c B P A M E R I C A
c PROPRIETARY - TO BE MAINTAINED IN CONFIDENCE
c COPYRIGHTED 2006
c***********************************************************************
c
c TEMPLATE 1
c
c FORTRAN TEMPLATE DEMONSTRATING THE USE OF THE BASE DDS ROUTINES
c FOR A SIMPLE TRACE-TO-TRACE PROCESSING SCHEME.
c
c Use a file extension of ".F" instead of ".f" to pull in the
c compiler preprocessor.
c
c Written by Jerry Ehlers November 2006
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
program template1
c
implicit none
c
#include <fdds.h>
c
integer in_bin,in_buf_bin,out_buf_bin,out_bin
character*(2*PATHNAME_MAX) in_dict
character*(PATHNAME_MAX) in_buf_dict,out_buf_dict,out_dict
character*80 title
c
integer ier,ns,nout,tag,ndxsmp,nbytes
real scale
c
c Dynamic Arrays
c
real inbuf(1),outbuf(1)
pointer (ptr_inbuf,inbuf)
pointer (ptr_outbuf,outbuf)
c
data title/'template1: example of Fortran DDS program'/
data in_bin,in_buf_bin,out_buf_bin,out_bin/-1,-1,-1,-1/
c
c=======================================================================
c initialize
c=======================================================================
c
ier=fdds_openpr('f_template1', '$Id: f_template1.html 125 2009-10-27 17:55:30Z ehlersjw $')
if (ier.gt.0) call help()
c
c=======================================================================
c open input data file
c=======================================================================
c
ier=fdds_in(in_dict,'in','stdin:',title)
in_bin=fdds_open(in_dict,'in_format','in_data','r')
if (in_bin.lt.0) then
ier=fdds_prterr('Unable to open input data\n\0')
endif
c
c Get input data parameters
c
ier=fdds_scanf('size.axis(1)','%d\0',ns)
c
c=======================================================================
c open input data buffer
c=======================================================================
c
c Define the input buffer Samples as host-dependent float
c
ier=fdds_dict('override:','print')
ier=fdds_printf('fmt:*:ibuf.SAMPLE_TYPE','\n\0')
ier=fdds_printf(' ',' typedef float SAMPLE_TYPE;\n\0')
c
ier=fdds_out(in_buf_dict,'ibuf',' ',in_dict)
ier=fdds_printf('$old_format','format\n\0')
ier=fdds_printf('ibuf_fmt','asp\n\0')
in_buf_bin=fdds_open(in_buf_dict,'ibuf_fmt',' ','m')
if (in_buf_bin.lt.0) then
ier=fdds_prterr('Unable to open internal input buffer!\n\0')
endif
c
ier=fdds_openm(in_buf_bin,0,in_bin,0)
c
c=======================================================================
c read parameters
c=======================================================================
c
ier=fdds_dict('par:','scan')
c
c get scale parameter (default 1.0)
c
scale=1.0
ier=fdds_scanf('scale','%f\0',scale)
c
c get # samples out (default ns)
c
nout=ns
ier=fdds_scanf(nout,'%d\0',nout)
c
c=======================================================================
c print user parameters
c=======================================================================
c
ier=fdds_prtmsg('\n*** USER PARAMETERS ***\n\n\0')
ier=fdds_prtmsg('\tscale = %g\n\0',scale)
ier=fdds_prtmsg('\tnout = %d\n\0',nout)
ier=fdds_prtmsg('\n\0')
c
c Check parameters
c
if (scale.lt.0.0) then
ier=fdds_prtcon('WARNING: "scale" is negative!\n\0')
endif
c
c=======================================================================
c allocate dynamic arrays
c=======================================================================
c
if (fdds_errors().ne.0) goto 900
c
c Allocate memory for an entire input record & single output trace
c
nbytes=fdds_prec(in_buf_bin,0)
ptr_inbuf=fdds_malloc(nbytes)
c
nbytes=fdds_prec(out_buf_bin,0)
ptr_outbuf=fdds_malloc(nbytes)
c
c get index to samples (allowing for possible trace headers)
c (since we are not modifying any trace headers in this program,
c we can use the same index for both input and output buffers.)
c
tag=fdds_member(in_buf_bin,0,'Samples')
ndxsmp=1+fdds_index(in_buf_bin,tag,DDS_REAL)
c
c=======================================================================
c open internal output buffer
c=======================================================================
c
if (fdds_errors().ne.0) goto 900
c
ier=fdds_dict('override:','print')
ier=fdds_printf('fmt:*:obuf.SAMPLE_TYPE','\n\0')
ier=fdds_printf(' ',' typedef complex SAMPLE_TYPE;\n\0')
c
c open output buffer dictionary
c
ier=fdds_out(out_buf_dict,'obuf',' ',in_buf_dict)
c
c print any definitions that might have changed from the input
c
ier=fdds_printf('size.axis(1)','%d\n\0',nout)
c
c open output buffer binary (using "asp" format)
c
ier=fdds_printf('obuf_fmt','asp\n\0')
out_buf_bin=fdds_open(out_buf_dict,'obuf_fmt',' ','m')
if (out_buf_bin.lt.0) then
ier=fdds_prterr('Unable to open output buffer!\n\0')
endif
c
c=======================================================================
c open output data
c=======================================================================
c
c open the output dictionary from the internal output buffer
c
ier=fdds_out(out_dict,'out','stdout:',out_buf_dict)
c
c open the output binary
c
out_bin=fdds_open(out_dict,'out_format','out_data','w+')
if (out_bin.lt.0) then
ier=fdds_prterr('Unable to open output file!\n\0')
endif
c
c explicitly open the mapping from the internal output buffer to
c the output dataset
c
ier=fdds_openm(out_bin,0,out_buf_bin,0)
c
c=======================================================================
c process the data
c=======================================================================
c
if (fdds_errors().ne.0) goto 900
c
call doit(in_bin,in_buf_bin,out_buf_bin,out_bin,ns,nout,
* scale,inbuf,outbuf)
c
c=======================================================================
c close files, clean-up, & exit
c=======================================================================
c
900 ier=fdds_close(in_bin)
ier=fdds_close(in_buf_bin)
ier=fdds_close(out_buf_bin)
ier=fdds_close(out_bin)
c
ier=fdds_closepr()
end
c
c***********************************************************************
c
c doit
c
c***********************************************************************
c
subroutine doit(in_bin,in_buf_bin,out_buf_bin,out_bin,ns,nout,
* scale,inbuf,outbuf)
c
implicit none
c
#include <fdds.h>
c
integer in_bin,in_buf_bin,out_buf_bin,out_bin
integer ns,nout,ndxsmp
real scale
real inbuf(*)
real outbuf(*)
c
integer ier,i
c
c loop over each trace
c
ier=fdds_readm(in_bin,0,in_buf_bin,0,inbuf,1)
do while(ier.eq.1)
c
c save trace headers to output buffer
c
do i=1,ndxsmp-1
outbuf(i)=inbuf(i)
enddo
c
c process the trace Samples
c
call process(ns,nout,scale,inbuf(ndxsmp),outbuf(ndxsmp))
c
c write the trace
c
ier=fdds_writem(out_bin,0,out_buf_bin,0,outbuf,1)
if (ier.ne.1) then
ier=fdds_prterr('writing output\n\0')
return
endif
c
c read the next trace
c
ier=fdds_readm(in_bin,0,in_buf_bin,0,inbuf,1)
enddo
c
return
end
c
c***********************************************************************
c
c help
c
c***********************************************************************
c
subroutine help()
c
write(0,*) 'Template program demonstraing the use of the base'
write(0,*) 'DDS routines for a simple trace-to-trace processing'
write(0,*) 'scheme.'
write(0,*) ' '
write(0,*) 'usage:'
write(0,*)
* ' f_template [in=dat] [in_data=bin] [in_format=fmt] \\'
write(0,*)
* ' [out=dat] [out_data=bin] [out_format=fmt] \\'
write(0,*)
* ' [nout=n] [scale=f]'
write(0,*) ' '
write(0,*) 'where:'
write(0,*) ' in= input dataset'
write(0,*) ' in_data= input binary'
write(0,*) ' in_format= input format'
write(0,*) ' out= output dictionary'
write(0,*) ' out_data= output binary'
write(0,*) ' out_format=output format'
write(0,*) ' nout= output samples (dflt=input)'
write(0,*) ' scale= scale factor (dflt=1.0)'
write(0,*) ' '
stop 0
end