Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minizip and extract .npz files #771

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Setup MinGW native environment
- name: Setup environment
uses: msys2/setup-msys2@v2
if: contains(matrix.msystem, 'MINGW')
with:
msystem: ${{ matrix.msystem }}
update: false
Expand All @@ -34,28 +33,10 @@ jobs:
mingw-w64-${{ matrix.arch }}-gcc
mingw-w64-${{ matrix.arch }}-gcc-fortran
mingw-w64-${{ matrix.arch }}-python
mingw-w64-${{ matrix.arch }}-python-pip
mingw-w64-${{ matrix.arch }}-python-setuptools
mingw-w64-${{ matrix.arch }}-python-fypp
mingw-w64-${{ matrix.arch }}-cmake
mingw-w64-${{ matrix.arch }}-ninja

- name: Setup msys POSIX environment
uses: msys2/setup-msys2@v2
if: contains(matrix.msystem, 'MSYS')
with:
msystem: MSYS
update: false
install: >-
git
mingw-w64-x86_64-gcc
mingw-w64-x86_64-gcc-fortran
python
python-pip
cmake
ninja

- name: Install fypp
run: pip install fypp
mingw-w64-x86_64-minizip-ng

- run: >-
PATH=$PATH:/mingw64/bin/ cmake
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ if(NOT FYPP)
message(FATAL_ERROR "Preprocessor fypp not found! Please install fypp following the instructions in https://fypp.readthedocs.io/en/stable/fypp.html#installing")
endif()

# --- find dependencies
if (NOT TARGET "minizip::minizip")
find_package("minizip" REQUIRED)
endif()

# Custom preprocessor flags
if(DEFINED CMAKE_MAXIMUM_RANK)
set(fyppFlags "-DMAXRANK=${CMAKE_MAXIMUM_RANK}")
Expand Down
14 changes: 14 additions & 0 deletions config/cmake/Findminizip.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set(_NAME "minizip")
set(_URL "https://github.com/zlib-ng/minizip-ng")
set(_TAG "4.0.4")

message(STATUS "Retrieving ${_NAME} from ${_URL}")
include(FetchContent)
FetchContent_Declare(
${_NAME}
GIT_REPOSITORY ${_URL}
GIT_TAG ${_TAG}
)
FetchContent_MakeAvailable(${_NAME})
add_library("${_NAME}::${_NAME}" INTERFACE IMPORTED)
target_link_libraries("${_NAME}::${_NAME}" INTERFACE "${_NAME}")
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
macro(ADD_EXAMPLE name)
add_executable(example_${name} example_${name}.f90)
target_link_libraries(example_${name} "${PROJECT_NAME}")
target_link_libraries(example_${name} ${PROJECT_NAME} "minizip::minizip")
add_test(NAME ${name}
COMMAND $<TARGET_FILE:example_${name}> ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
2 changes: 1 addition & 1 deletion example/io/example_loadnpy.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
program example_loadnpy
use stdlib_io_npy, only: load_npy
use stdlib_io_np, only: load_npy
implicit none
real, allocatable :: x(:, :)
call load_npy('example.npy', x)
Expand Down
2 changes: 1 addition & 1 deletion example/io/example_savenpy.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
program example_savenpy
use stdlib_io_npy, only: save_npy
use stdlib_io_np, only: save_npy
implicit none
real :: x(3, 2) = 1
call save_npy('example.npy', x)
Expand Down
10 changes: 6 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Create a list of the files to be preprocessed
set(fppFiles
stdlib_array.fypp
stdlib_ascii.fypp
stdlib_bitsets.fypp
stdlib_bitsets_64.fypp
Expand All @@ -17,9 +18,9 @@ set(fppFiles
stdlib_hash_64bit_pengy.fypp
stdlib_hash_64bit_spookyv2.fypp
stdlib_io.fypp
stdlib_io_npy.fypp
stdlib_io_npy_load.fypp
stdlib_io_npy_save.fypp
stdlib_io_np.fypp
stdlib_io_np_load.fypp
stdlib_io_np_save.fypp
stdlib_kinds.fypp
stdlib_linalg.fypp
stdlib_linalg_diag.fypp
Expand Down Expand Up @@ -101,7 +102,6 @@ set(SRC
stdlib_ansi.f90
stdlib_ansi_operator.f90
stdlib_ansi_to_string.f90
stdlib_array.f90
stdlib_codata.f90
stdlib_error.f90
stdlib_hashmap_wrappers.f90
Expand All @@ -115,6 +115,8 @@ set(SRC
stdlib_specialfunctions_legendre.f90
stdlib_quadrature_gauss.f90
stdlib_stringlist_type.f90
stdlib_io_zip.f90
stdlib_io_minizip.f90
${outFiles}
${outPreprocFiles}
)
Expand Down
68 changes: 0 additions & 68 deletions src/stdlib_array.f90

This file was deleted.

120 changes: 120 additions & 0 deletions src/stdlib_array.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
! SPDX-Identifier: MIT

#:include "common.fypp"
#:set RANKS = range(1, MAXRANK + 1)
#:set KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES + CMPLX_KINDS_TYPES

!> Module for index manipulation and general array handling
!>
!> The specification of this module is available [here](../page/specs/stdlib_array.html).
module stdlib_array
use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, xdp, qp
implicit none
private

public :: trueloc, falseloc

!> Helper class to allocate t_array as an abstract type.
type, public :: t_array_wrapper
class(t_array), allocatable :: array
contains
#:for k1, t1 in KINDS_TYPES
#:for rank in RANKS
generic :: allocate_array => allocate_array_${t1[0]}$${k1}$_${rank}$
procedure :: allocate_array_${t1[0]}$${k1}$_${rank}$
#:endfor
#:endfor
end type

type, abstract, public :: t_array
character(:), allocatable :: name
end type

#:for k1, t1 in KINDS_TYPES
#:for rank in RANKS
type, extends(t_array), public :: t_array_${t1[0]}$${k1}$_${rank}$
${t1}$, allocatable :: values${ranksuffix(rank)}$
end type
#:endfor
#:endfor

contains

#:for k1, t1 in KINDS_TYPES
#:for rank in RANKS
!> Allocate an instance of the array within the wrapper.
subroutine allocate_array_${t1[0]}$${k1}$_${rank}$ (wrapper, array, stat, msg)
class(t_array_wrapper), intent(out) :: wrapper
${t1}$, intent(in) :: array${ranksuffix(rank)}$
integer, intent(out) :: stat
character(len=:), allocatable, intent(out) :: msg

allocate (t_array_${t1[0]}$${k1}$_${rank}$ :: wrapper%array, stat=stat)
if (stat /= 0) then
msg = 'Failed to allocate array.'; return
end if

select type (typed_array => wrapper%array)
class is (t_array_${t1[0]}$${k1}$_${rank}$)
typed_array%values = array
class default
msg = 'Failed to allocate values.'; stat = 1; return
end select
end
#:endfor
#:endfor

!> Version: experimental
!>
!> Return the positions of the true elements in array.
!> [Specification](../page/specs/stdlib_array.html#trueloc)
pure function trueloc(array, lbound) result(loc)
!> Mask of logicals
logical, intent(in) :: array(:)
!> Lower bound of array to index
integer, intent(in), optional :: lbound
!> Locations of true elements
integer :: loc(count(array))

call logicalloc(loc, array, .true., lbound)
end

!> Version: experimental
!>
!> Return the positions of the false elements in array.
!> [Specification](../page/specs/stdlib_array.html#falseloc)
pure function falseloc(array, lbound) result(loc)
!> Mask of logicals
logical, intent(in) :: array(:)
!> Lower bound of array to index
integer, intent(in), optional :: lbound
!> Locations of false elements
integer :: loc(count(.not. array))

call logicalloc(loc, array, .false., lbound)
end

!> Return the positions of the truthy elements in array
pure subroutine logicalloc(loc, array, truth, lbound)
!> Locations of truthy elements
integer, intent(out) :: loc(:)
!> Mask of logicals
logical, intent(in) :: array(:)
!> Truthy value
logical, intent(in) :: truth
!> Lower bound of array to index
integer, intent(in), optional :: lbound
integer :: i, pos, offset

offset = 0
if (present(lbound)) offset = lbound - 1

i = 0
do pos = 1, size(array)
if (array(pos) .eqv. truth) then
i = i + 1
loc(i) = pos + offset
end if
end do
end
end
Loading
Loading