program chi_square_sum !********************************************************************** ! * . . . ! * PROGRAM: CHI_SQUARE_SUM ! * PRGMMR: M. ZUPANSKI ORG: CIRA/CSU DATE: 2003-10-21 ! * ! * ABSTRACT: CALCULATE INNER PRODUCT BETWEEN TWO VECTORS ! * SUM OVER ALL OBS CATEGORIES ! * ! * PROGRAM LOG: ! * ! * 10/21/2003 ..... M. ZUPANSKI: ! * 01/02/2004 ..... M. ZUPANSKI: moving average added ! * 09/08/2004 ..... M. ZUPANSKI: single program for obs and model chi-square ! * 09/08/2004 ..... M. ZUPANSKI: on-the-fly chi-square ! * ! ********************************************************************** !---------------------------------- ! INPUT: ! product - inner product: (x_1**T)*x_1 ! ! OUTPUT: ! product_sum - total chi square (sum) ! !---------------------------------- !----- integer,parameter::inner=21 ! input file # integer,parameter::chi_sum=51 ! input-output file # !----- integer :: N_dim,N_sum real :: product real :: product_sum real,dimension(:),allocatable::x_1 logical :: file_exist character*1 categ !----- !==============start calculation=================== !-- read innov file rewind inner read(inner) N_dim allocate(x_1(1:N_dim)) read(inner) x_1 product=0.0 do i=1,N_dim product=product+x_1(i)*x_1(i) end do deallocate(x_1) 100 format(I15,E20.10) !---- read previous sum of chi_squares ------- ! call getenv("icateg",categ) ! write(*,*) "Current category=",categ ! if(categ.eq.'1') then ! write(*,*) "Previous CHI_SUM file DOES NOT exist" N_sum=0 product_sum=0.0 ! else ! write(*,*) "Previous CHI_SUM file DOES exist" rewind chi_sum read(chi_sum,100,err=220) N_sum,product_sum ! end if !-- Inner product -------------------- 220 product_sum=float(N_sum)*product_sum + product N_sum=N_sum+N_dim product_sum=product_sum/float(N_sum) rewind chi_sum write(chi_sum,100) N_sum,product_sum end program chi_square_sum