--- src/pima_acta.f	2018-09-03 11:00:35.819242780 -0400
+++ src/pima_acta.f~	2018-09-03 10:29:57.159588480 -0400
@@ -11,7 +11,7 @@
 ! *   It exludes autcorrelation with weights less than                   *
 ! *   FRIB.AUTOCORR_THRESHOLD.                                           *
 ! *                                                                      *
-! *  ### 11-APR-2014   PIMA_ACTA   v1.1 (c)  L. Petrov  03-SEP-2018 ###  *
+! *  ### 11-APR-2014   PIMA_ACTA   v1.0 (c)  L. Petrov  18-APR-2014 ###  *
 ! *                                                                      *
 ! ************************************************************************
       IMPLICIT   NONE 
@@ -21,7 +21,7 @@
       INTEGER*8  STREAM, DIR_DESC
       CHARACTER  STR*128, STR1*128
       LOGICAL*1, ALLOCATABLE :: FL_USE(:)
-      COMPLEX*8, ALLOCATABLE :: AC(:,:,:,:), AC_OBS(:,:)
+      COMPLEX*8, ALLOCATABLE :: AC(:,:,:), AC_OBS(:,:)
       REAL*8,    ALLOCATABLE :: FRQ_OBS(:,:)
       CHARACTER, ALLOCATABLE :: OUT(:)*80
       CHARACTER  C_STA(PIM__MSTA)*8, FILOUT*128, DIROUT*128
@@ -30,7 +30,7 @@
      &           NUM_EPC_MAX, L_STA, IND_STA, IND_CHN, UV_IND, &
      &           IND_FRQ,  LCHN, LFRQ, LTIM, MOUT, NO, IER
       REAL*8     AP_LEN, TIM_ARR(PIM__MUV), DURA_ACC
-      REAL*4     WEI_1D(PIM__MUV,0:2), AC_MEAN(PIM__MFRQ,2), WEI_SUM
+      REAL*4     WEI_1D(PIM__MUV), AC_MEAN(PIM__MFRQ), WEI_SUM
       INTEGER*4, EXTERNAL :: ILEN, I_LEN, ADD_CLIST, LTM_DIF 
       INTEGER*4, EXTERNAL :: FFTWF_IMPORT_WISDOM_FROM_FILE
       INTEGER*8, EXTERNAL :: FOPEN, FCLOSE, FUNC_OPENDIR, MKDIR
@@ -101,7 +101,7 @@
      &         'memory for array AC_OBS' )
            RETURN
       END IF
-      AC_OBS = 0.0
+      CALL NOUT_R4 ( LCHN*LFRQ, AC_OBS )
 !
       ALLOCATE ( FRQ_OBS(LCHN,LFRQ), STAT=IER )
       IF ( IER .NE. 0 ) THEN
@@ -112,7 +112,7 @@
      &         'memory for array FRQ_OBS' )
            RETURN
       END IF
-      FRQ_OBS = 0.0D0
+      CALL NOUT_R8 ( LCHN*LFRQ, FRQ_OBS )
 !
 ! --- Cycle over scans
 !
@@ -168,7 +168,7 @@
             END IF
 !
             LTIM = PIM%OBS(IND_OBS_STA)%NUM_EPC(FRG_IND)
-            ALLOCATE ( AC(PIM%NCHN,LFRQ,LTIM,2), STAT=IER )
+            ALLOCATE ( AC(PIM%NCHN,LFRQ,LTIM), STAT=IER )
             IF ( IER .NE. 0 ) THEN
                  CALL CLRCH ( STR )
                  CALL IINCH ( 8*PIM%NCHN*LFRQ*LTIM, STR )
@@ -177,33 +177,30 @@
      &                'memory for array AC' )
                   RETURN
             END IF
-            AC = 0.0
-            DO 460 J6=1,2
+            CALL NOUT_R4 ( PIM%NCHN*LFRQ*LTIM, AC )
 !
-! ------------ Get autocorrelation data
+! --------- Get autocorrelation data
 !
-               CALL ERR_PASS ( IUER, IER )
-               CALL PIMA_GET_UV ( PIM, IND_OBS_STA, LFRQ, PIM%CONF%BEG_FRQ, &
-     &                            PIM%CONF%END_FRQ, PIM%CONF%FRQ_GRP, &
-     &                            AC(1,1,1,J6), WEI_1D(1,J6), AP_LEN, J6, IER  )
-               IF ( IER .NE. 0 ) THEN
-                    CALL CLRCH ( STR )
-                    CALL INCH  ( IND_OBS, STR )
-                    CALL ERR_PASS ( IUER, IER )
-                    CALL ERR_LOG  ( 7520, IER, 'PIMA_ACTA', 'Failure to '// &
-     &                  'get autocorrelation data for station '// &
-     &                   C_STA(PIM%OBS(IND_OBS_STA)%STA_IND(J6))// &
-     &                  ' for the '//STR(1:I_LEN(STR))//'th observation'// &
-     &                  ' from input FITS-IDI file ' )
-                    RETURN 
-               END IF
- 460        CONTINUE 
+            CALL ERR_PASS ( IUER, IER )
+            CALL PIMA_GET_UV ( PIM, IND_OBS_STA, LFRQ, PIM%CONF%BEG_FRQ, &
+     &                         PIM%CONF%END_FRQ, PIM%CONF%FRQ_GRP, &
+     &                         AC, WEI_1D, AP_LEN, IND_STA_BAS, IER  )
+            IF ( IER .NE. 0 ) THEN
+                 CALL CLRCH ( STR )
+                 CALL INCH  ( IND_OBS, STR )
+                 CALL ERR_PASS ( IUER, IER )
+                 CALL ERR_LOG  ( 7520, IER, 'PIMA_ACTA', 'Failure to '// &
+     &               'get autocorrelation data for station '//C_STA(J4)// &
+     &               ' for the '//STR(1:I_LEN(STR))//'th observation'// &
+     &               ' from input FITS-IDI file ' )
+                 RETURN 
+            END IF
 !
 ! --------- Apply bandpass mask and re-normalize autocorrelation
 !
             CALL ERR_PASS ( IUER, IER )
-            CALL PIMA_ACCOR_MEAN ( PIM, IND_OBS_STA, LTIM, AC, WEI_1D, AC_MEAN, &
-     &                             .FALSE., IER  )
+            CALL PIMA_ACCOR_MEAN ( PIM, IND_OBS_STA, LTIM, AC, WEI_1D, &
+     &                             AC_MEAN, .FALSE., IER  )
             IF ( IER .NE. 0 ) THEN
                  CALL CLRCH ( STR )
                  CALL INCH  ( IND_OBS, STR )
@@ -218,42 +215,42 @@
             AC_OBS   = (0.0, 0.0)
             WEI_SUM  = 0.0
 !
-! --------- Cycle over epochs
+! --------- Cycele over epochs
 !
-            DO 470 J7=1,LTIM
+            DO 460 J6=1,LTIM
 !
 ! ------------ check for the autocorrelation threshold
 !
-               IF ( WEI_1D(J7,IND_STA_BAS) < PIM%CONF%FRIB_WEIGHTS_THRESHOLD ) GOTO 470
-               UV_IND  = PIM%OBS(IND_OBS_STA)%UV_IND(J7,FRG_IND)
-               TIM_ARR(J7) = PIM%TIM_R8(PIM%UV_IND(UV_IND)%TIM_IND) - &
+               IF ( WEI_1D(J6) < PIM%CONF%FRIB_WEIGHTS_THRESHOLD ) GOTO 460
+               UV_IND  = PIM%OBS(IND_OBS_STA)%UV_IND(J6,FRG_IND)
+               TIM_ARR(J6) = PIM%TIM_R8(PIM%UV_IND(UV_IND)%TIM_IND) - &
      &                       PIM%OBS(IND_OBS_STA)%TIM_BEG
 !
 ! ------------ Downweight epochs that are too ealry or too late
-! ------------ according to SCAN_LEN_SKIP/SCAN_LEN_USED options
+! ------------ accordinbgto SCAN_LEN_SKIP/SCAN_LEN_USED options
 !
-               IF ( TIM_ARR(J7) < PIM%CONF%SCAN_LEN_SKIP ) THEN
-                    WEI_1D(J7,IND_STA_BAS) = 0.0D0
+               IF ( TIM_ARR(J6) < PIM%CONF%SCAN_LEN_SKIP ) THEN
+                    WEI_1D(J6) = 0.0D0
                END IF 
-               DURA_ACC = DURA_ACC + WEI_1D(J7,IND_STA_BAS)*AP_LEN
+               DURA_ACC = DURA_ACC + WEI_1D(J6)*AP_LEN
                IF ( DURA_ACC > PIM%CONF%SCAN_LEN_USED ) THEN
-                    WEI_1D(J7,IND_STA_BAS) = 0.0D0
+                    WEI_1D(J6) = 0.0D0
                END IF
-               IF ( WEI_1D(J7,IND_STA_BAS) .GE. PIM%CONF%FRIB_WEIGHTS_THRESHOLD ) THEN
+               IF ( WEI_1D(J6) .GE. PIM%CONF%FRIB_WEIGHTS_THRESHOLD ) THEN
 !
 ! ----------------- Update autocorrelation spectrum accumulators
 !
-                    WEI_SUM = WEI_SUM + WEI_1D(J7,IND_STA_BAS)*PIM%CONF%FRIB_1D_FRQ_MSEG
-                    DO 480 J8=1,LFRQ
-                       DO 490 J9=1,LCHN
-                          DO 4100 J10=1,PIM%CONF%FRIB_1D_FRQ_MSEG
-                             IND_CHN = (J9-1)*PIM%CONF%FRIB_1D_FRQ_MSEG + J10
-                             AC_OBS(J9,J8) = AC_OBS(J9,J8) + AC(IND_CHN,J8,J7,IND_STA_BAS)*WEI_1D(J7,IND_STA_BAS)
- 4100                     CONTINUE 
- 490                   CONTINUE 
- 480                CONTINUE 
+                    WEI_SUM = WEI_SUM + WEI_1D(J6)*PIM%CONF%FRIB_1D_FRQ_MSEG
+                    DO 470 J7=1,LFRQ
+                       DO 480 J8=1,LCHN
+                          DO 490 J9=1,PIM%CONF%FRIB_1D_FRQ_MSEG
+                             IND_CHN = (J8-1)*PIM%CONF%FRIB_1D_FRQ_MSEG + J9
+                             AC_OBS(J8,J7) = AC_OBS(J8,J7) + AC(IND_CHN,J7,J6)*WEI_1D(J6)
+ 490                      CONTINUE 
+ 480                   CONTINUE 
+ 470                CONTINUE 
                END IF
- 470        CONTINUE 
+ 460        CONTINUE 
             IF ( WEI_SUM > PIM%CONF%FRIB_WEIGHTS_THRESHOLD ) THEN
 !
 ! -------------- Get memory for the output buffer
@@ -339,19 +336,19 @@
 ! -------------- Now write down the autocorrelation spectrum in the 
 ! -------------- buffer OUT with contents of the output file
 !
-                 DO 4110 J11=1,LFRQ
-                    DO 4120 J12=1,LCHN
-                       IND_FRQ = 1 + (J12-1)*PIM%CONF%FRIB_1D_FRQ_MSEG + &
+                 DO 4100 J10=1,LFRQ
+                    DO 4110 J11=1,LCHN
+                       IND_FRQ = 1 + (J11-1)*PIM%CONF%FRIB_1D_FRQ_MSEG + &
      &                           ((PIM%CONF%FRIB_1D_FRQ_MSEG-1)/2)
-                       FRQ_OBS = PIM%FREQ_ARR(IND_FRQ,PIM%CONF%BEG_FRQ-1+J11,PIM%CONF%FRQ_GRP)
-                       AC_OBS(J12,J11) = (AC_OBS(J12,J11)/WEI_SUM)/AC_MEAN(J11,IND_STA_BAS)
+                       FRQ_OBS = PIM%FREQ_ARR(IND_FRQ,J10,PIM%CONF%FRQ_GRP)
+                       AC_OBS(J11,J10) = (AC_OBS(J11,J10)/WEI_SUM)/AC_MEAN(J10)
                        NO = NO + 1
-                       WRITE ( UNIT=OUT(NO), FMT=110 ) J11, J12, FRQ_OBS(J12,J11), &
-     &                                                 ABS(AC_OBS(J12,J11))
+                       WRITE ( UNIT=OUT(NO), FMT=110 ) J10, J11, FRQ_OBS(J11,J10), &
+     &                                                 ABS(AC_OBS(J11,J10))
  110                   FORMAT ( 'ACRL  Lchn: ', I5, ' Lfrq: ', I4, &
      &                          ' Freq: ', F15.2, ' Hz   Ac: ', F12.5 )
- 4120               CONTINUE 
- 4110            CONTINUE 
+ 4110               CONTINUE 
+ 4100            CONTINUE 
 !
 ! -------------- Build the name of the output directory ...
 !
