summaryrefslogtreecommitdiff
path: root/lib/q65_host_support.f90
diff options
context:
space:
mode:
Diffstat (limited to 'lib/q65_host_support.f90')
-rw-r--r--lib/q65_host_support.f9064
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/q65_host_support.f90 b/lib/q65_host_support.f90
new file mode 100644
index 00000000..95e4f2d4
--- /dev/null
+++ b/lib/q65_host_support.f90
@@ -0,0 +1,64 @@
+module q65_host_support
+ use q65_decode, only: q65_decoder,q65_options
+ use q65_callers, only: Q65_MAX_CALLERS,q65_load_callers,q65_save_callers
+ use types, only: q3list
+ use prog_args, only: data_dir,temp_dir
+ implicit none
+ private
+ public :: load_q65_history,save_q65_history,write_q65_curves,write_q65_diagnostic
+contains
+ subroutine load_q65_history(decoder,status)
+ class(q65_decoder), intent(inout) :: decoder
+ integer, intent(out) :: status
+ type(q3list) :: callers(Q65_MAX_CALLERS)
+ integer :: count
+ call q65_load_callers(trim(data_dir)//'/tsil.3q',callers,count,status)
+ call decoder%set_callers(callers,count)
+ end subroutine
+
+ subroutine save_q65_history(decoder,load_status)
+ class(q65_decoder), intent(in) :: decoder
+ integer, intent(in) :: load_status
+ type(q3list) :: callers(Q65_MAX_CALLERS)
+ integer :: count,status
+ if(load_status/=0) return
+ call decoder%get_callers(callers,count)
+ call q65_save_callers(trim(data_dir)//'/tsil.3q',callers,count,status)
+ end subroutine
+
+ subroutine write_q65_diagnostic(line)
+ character(len=*), intent(in) :: line
+ integer :: unit,status
+ open(newunit=unit,file=trim(data_dir)//'/q65_decodes.txt',status='unknown',position='append',iostat=status)
+ if(status/=0) return
+ write(unit,'(a)') trim(line)
+ close(unit)
+ end subroutine
+
+ subroutine write_q65_curves(decoder,options)
+ class(q65_decoder), intent(in) :: decoder
+ type(q65_options), intent(in) :: options
+ real, allocatable :: current(:),average(:)
+ real :: df,dt,y0,y0_average,g_average,empty_current(0),empty_average(0)
+ integer :: even_count,odd_count,count,i1,i2,i,unit,status,active_count
+ call decoder%get_curves(even_count,odd_count,df,dt,empty_current,empty_average,count)
+ if(count<=0.or.df<=0) return
+ allocate(current(count),average(count))
+ call decoder%get_curves(even_count,odd_count,df,dt,current,average,count,active_count)
+ i1=max(1,nint(options%low_frequency/df))
+ i2=min(count,int(options%high_frequency/df))
+ if(i2<i1) return
+ y0=minval(current(i1:i2))
+ y0_average=minval(average(i1:i2))
+ g_average=0
+ if(active_count>=2) g_average=0.4
+ open(newunit=unit,file=trim(temp_dir)//'/red.dat',status='replace',iostat=status)
+ if(status/=0) return
+ write(unit,1000) dt,g_average*minval(average),g_average*maxval(average)
+ do i=i1,i2
+ write(unit,1000) i*df,g_average*(average(i)-y0_average),0.4*(current(i)-y0)
+ enddo
+1000 format(f10.3,2f15.6)
+ close(unit)
+ end subroutine
+end module q65_host_support