Commit 44b1d794 authored by Zolnierczuk, Piotr's avatar Zolnierczuk, Piotr
Browse files

small optimization in read_data

parent 995e14e2
Loading
Loading
Loading
Loading
+23 −18
Original line number Diff line number Diff line
@@ -829,7 +829,7 @@ contains
      integer :: it  , ix,   iy
      integer :: itp , ixp,  iyp
      integer :: itmp
      real(kind=DBL) :: ctmp, mtmp
      real(kind=DBL) :: mtmp
      real(kind=DBL) :: monitor_scaling_factor
      integer :: no_monitors
      !
@@ -893,6 +893,7 @@ contains

      !loop over time and detector channels
      !TODO: reading detector data definitely needs some serious optimization
      associate(pix => scan_point%pixelbin)
      loop_t: do it=1, no_tchans
         itp = get_bin(tbins, it)
         if (itp<=0) cycle loop_t
@@ -904,14 +905,13 @@ contains
               if (ixp<=0) cycle loop_x
               itmp = det_counts(ix, iy, it)
               ! full band-width of data
               scan_point%pixelbin(  0,ixp,iyp)%counts_pixel_bin(nphase)%value = &
                    scan_point%pixelbin(  0,ixp,iyp)%counts_pixel_bin(nphase)%value + itmp
               pix(  0,ixp,iyp)%counts_pixel_bin(nphase)%value = pix(  0,ixp,iyp)%counts_pixel_bin(nphase)%value + itmp
               ! selected band data
               scan_point%pixelbin(itp,ixp,iyp)%counts_pixel_bin(nphase)%value = &
                    scan_point%pixelbin(itp,ixp,iyp)%counts_pixel_bin(nphase)%value + itmp
               pix(itp,ixp,iyp)%counts_pixel_bin(nphase)%value = pix(itp,ixp,iyp)%counts_pixel_bin(nphase)%value + itmp
            end do loop_x
         end do loop_y
      end do loop_t
      end associate


      ! fill the detector spectrum
@@ -930,27 +930,32 @@ contains


      phase_angle = deg2rad(phase_angle)
      mtmp = counters(norm_counter)  * monitor_scaling_factor !!<<mm 11.09.2018
      ! J0
      scan_point%pixelbin%J0  = scan_point%physics%field_integral%value
      !
      ! loop over pixels
      ! fill in the structure
      loop_itp: do itp=0, tbins%nbins
         loop_iyp: do iyp=1, ybins%nbins
            loop_ixp: do ixp=1, xbins%nbins
               ! J0, delta-J
               scan_point%pixelbin(itp,ixp,iyp)%J0              = scan_point%physics%field_integral%value
               scan_point%pixelbin(itp,ixp,iyp)%delta_J(nphase) = &
                    value_struct(VAL_NO_ERROR, get_field_integral(phase_angle, scan_point%physics%lambda), 0.0)
               ! monitor/detector counts & errors
               mtmp = counters(norm_counter)  * monitor_scaling_factor !!<<mm 11.09.2018
               ctmp = scan_point%pixelbin(itp,ixp,iyp)%counts_pixel_bin(nphase)%value
               scan_point%pixelbin(itp,ixp,iyp)%monitor(nphase)          = value_struct(VAL_WITH_ERROR, mtmp, mtmp)
               scan_point%pixelbin(itp,ixp,iyp)%counts_pixel_bin(nphase) = value_struct(VAL_WITH_ERROR, ctmp, ctmp)
               !
               scan_point%pixelbin(itp,ixp,iyp)%n_all  = number_of_phases
               scan_point%pixelbin(itp,ixp,iyp)%n_down = point_to_down
               scan_point%pixelbin(itp,ixp,iyp)%n_up   = point_to_up
               associate(pix => scan_point%pixelbin(itp,ixp,iyp))
               ! delta-J
               pix%delta_J(nphase)%value = get_field_integral(phase_angle, scan_point%physics%lambda)
               pix%delta_J(nphase)%state = VAL_NO_ERROR
               ! detector errors
               pix%counts_pixel_bin(nphase)%sigma2 = pix%counts_pixel_bin(nphase)%value
               pix%counts_pixel_bin(nphase)%state  = VAL_WITH_ERROR
               ! monitors counts & errors
               pix%monitor(nphase) = value_struct(VAL_WITH_ERROR, mtmp, mtmp)
               end associate
            end do loop_ixp
         end do loop_iyp
      end do loop_itp
      !
      scan_point%pixelbin%n_all  = number_of_phases
      scan_point%pixelbin%n_down = point_to_down
      scan_point%pixelbin%n_up   = point_to_up

    end subroutine read_phase_point