df_filter_rows_real_range Function

public function df_filter_rows_real_range(df, col_index, min_val, max_val) result(filtered_df)

Filter rows by real value range

Creates a new data frame containing only rows where the specified real column value is within [min_val, max_val]

@param[in] df The source data frame @param[in] col_index Index of the real column to filter by @param[in] min_val Minimum value (inclusive) @param[in] max_val Maximum value (inclusive) @return filtered_df New data frame with filtered rows

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
integer, intent(in) :: col_index
real(kind=rk), intent(in) :: min_val
real(kind=rk), intent(in) :: max_val

Return Value type(data_frame)


Source Code

    function df_filter_rows_real_range(df, col_index, min_val, max_val) result(filtered_df)
        type(data_frame), intent(in) :: df
        integer, intent(in) :: col_index
        real(rk), intent(in) :: min_val, max_val
        type(data_frame) :: filtered_df

        integer, dimension(:), allocatable :: selected_rows
        integer :: i, count, idx
        real(rk) :: val
        type(column) :: col

        col = df % get_data_col(col_index)

        if (col % get_type() /= REAL_NUM) error stop "column is not real type"

        ! Count matching rows
        count = 0
        do i = 1, df % nrows()
            val = col % getr(i)
            if (val >= min_val .and. val <= max_val) count = count + 1
        end do

        ! Collect matching row indices
        allocate (selected_rows(count))
        idx = 0
        do i = 1, df % nrows()
            val = col % getr(i)
            if (val >= min_val .and. val <= max_val) then
                idx = idx + 1
                selected_rows(idx) = i
            end if
        end do

        ! Create filtered dataframe
        call filtered_df % new(df % get_max_char_len())
        do i = 1, df % ncols()
            call copy_filtered_column(df, filtered_df, i, selected_rows)
        end do

        deallocate (selected_rows)
    end function df_filter_rows_real_range