├── .editorconfig ├── API-doc-FORD-file.md ├── CHANGELOG.md ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── STYLE_GUIDE.md ├── VERSION ├── WORKFLOW.md ├── cmake └── stdlib.cmake ├── config ├── CMakeLists.txt ├── DefaultFlags.cmake ├── cmake │ └── Findtest-drive.cmake ├── fypp_deployment.py ├── requirements.txt ├── template.cmake └── template.pc ├── doc ├── License.md ├── changelog.md ├── contributing │ ├── CodeOfConduct.md │ ├── StyleGuide.md │ ├── Workflow.md │ └── index.md ├── index.md ├── media │ └── favicon.ico └── specs │ ├── index.md │ ├── stdlib_ansi.md │ ├── stdlib_array.md │ ├── stdlib_ascii.md │ ├── stdlib_bitsets.md │ ├── stdlib_constants.md │ ├── stdlib_error.md │ ├── stdlib_error_state_type.md │ ├── stdlib_hash_procedures.md │ ├── stdlib_hashmaps.md │ ├── stdlib_intrinsics.md │ ├── stdlib_io.md │ ├── stdlib_kinds.md │ ├── stdlib_linalg.md │ ├── stdlib_linalg_state_type.md │ ├── stdlib_logger.md │ ├── stdlib_math.md │ ├── stdlib_optval.md │ ├── stdlib_quadrature.md │ ├── stdlib_random.md │ ├── stdlib_selection.md │ ├── stdlib_sorting.md │ ├── stdlib_sparse.md │ ├── stdlib_specialfunctions.md │ ├── stdlib_specialfunctions_activations.md │ ├── stdlib_specialfunctions_gamma.md │ ├── stdlib_stats.md │ ├── stdlib_stats_distribution_exponential.md │ ├── stdlib_stats_distribution_normal.md │ ├── stdlib_stats_distribution_uniform.md │ ├── stdlib_str2num.md │ ├── stdlib_string_type.md │ ├── stdlib_stringlist_type.md │ ├── stdlib_strings.md │ ├── stdlib_system.md │ └── stdlib_version.md ├── example ├── CMakeLists.txt ├── ansi │ ├── CMakeLists.txt │ ├── example_ansi_color.f90 │ ├── example_ansi_combine.f90 │ ├── example_ansi_concat.f90 │ └── example_ansi_to_string.f90 ├── array │ ├── CMakeLists.txt │ ├── example_falseloc.f90 │ └── example_trueloc.f90 ├── ascii │ ├── CMakeLists.txt │ ├── example_ascii_reverse.f90 │ ├── example_ascii_to_lower.f90 │ ├── example_ascii_to_sentence.f90 │ ├── example_ascii_to_title.f90 │ └── example_ascii_to_upper.f90 ├── bitsets │ ├── CMakeLists.txt │ ├── example_bitsets_all.f90 │ ├── example_bitsets_and.f90 │ ├── example_bitsets_and_not.f90 │ ├── example_bitsets_any.f90 │ ├── example_bitsets_assignment.f90 │ ├── example_bitsets_bit_count.f90 │ ├── example_bitsets_bits.f90 │ ├── example_bitsets_clear.f90 │ ├── example_bitsets_equality.f90 │ ├── example_bitsets_extract.f90 │ ├── example_bitsets_flip.f90 │ ├── example_bitsets_from_string.f90 │ ├── example_bitsets_ge.f90 │ ├── example_bitsets_gt.f90 │ ├── example_bitsets_inequality.f90 │ ├── example_bitsets_init.f90 │ ├── example_bitsets_input.f90 │ ├── example_bitsets_le.f90 │ ├── example_bitsets_lt.f90 │ ├── example_bitsets_none.f90 │ ├── example_bitsets_not.f90 │ ├── example_bitsets_or.f90 │ ├── example_bitsets_output.f90 │ ├── example_bitsets_read_bitset.f90 │ ├── example_bitsets_set.f90 │ ├── example_bitsets_test.f90 │ ├── example_bitsets_to_string.f90 │ ├── example_bitsets_value.f90 │ ├── example_bitsets_write_bitset.f90 │ └── example_bitsets_xor.f90 ├── constants │ ├── CMakeLists.txt │ └── example_constants.f90 ├── error │ ├── CMakeLists.txt │ ├── example_check1.f90 │ ├── example_check2.f90 │ ├── example_check3.f90 │ ├── example_check4.f90 │ ├── example_error_state1.f90 │ ├── example_error_state2.f90 │ ├── example_error_stop1.f90 │ └── example_error_stop2.f90 ├── hash_procedures │ ├── CMakeLists.txt │ ├── example_fibonacci_hash.f90 │ ├── example_fibonacci_hash_64.f90 │ ├── example_fnv_1_hash.f90 │ ├── example_fnv_1_hash_64.f90 │ ├── example_fnv_1a_hash.f90 │ ├── example_fnv_1a_hash_64.f90 │ ├── example_nmhash32.f90 │ ├── example_nmhash32x.f90 │ ├── example_pengy_hash.f90 │ ├── example_spooky_hash.f90 │ ├── example_universal_mult_hash.f90 │ ├── example_universal_mult_hash_64.f90 │ └── example_water_hash.f90 ├── hashmaps │ ├── CMakeLists.txt │ ├── example_hashmaps_calls.f90 │ ├── example_hashmaps_copy_key.f90 │ ├── example_hashmaps_entries.f90 │ ├── example_hashmaps_equal_keys.f90 │ ├── example_hashmaps_fnv_1_hasher.f90 │ ├── example_hashmaps_fnv_1a_hasher.f90 │ ├── example_hashmaps_free_key.f90 │ ├── example_hashmaps_get.f90 │ ├── example_hashmaps_get_all_keys.f90 │ ├── example_hashmaps_get_other_data.f90 │ ├── example_hashmaps_hasher_fun.f90 │ ├── example_hashmaps_init.f90 │ ├── example_hashmaps_key_test.f90 │ ├── example_hashmaps_loading.f90 │ ├── example_hashmaps_map_entry.f90 │ ├── example_hashmaps_num_slots.f90 │ ├── example_hashmaps_probes.f90 │ ├── example_hashmaps_rehash.f90 │ ├── example_hashmaps_remove.f90 │ ├── example_hashmaps_seeded_nmhash32_hasher.f90 │ ├── example_hashmaps_seeded_nmhash32x_hasher.f90 │ ├── example_hashmaps_seeded_water_hasher.f90 │ ├── example_hashmaps_set.f90 │ ├── example_hashmaps_set_other_data.f90 │ ├── example_hashmaps_slots_bits.f90 │ └── example_hashmaps_total_depth.f90 ├── intrinsics │ ├── CMakeLists.txt │ ├── example_dot_product.f90 │ └── example_sum.f90 ├── io │ ├── CMakeLists.txt │ ├── example.csv │ ├── example.dat │ ├── example.npy │ ├── example_fmt_constants.f90 │ ├── example_get_file.f90 │ ├── example_get_line.f90 │ ├── example_loadnpy.f90 │ ├── example_loadtxt.f90 │ ├── example_open.f90 │ ├── example_savenpy.f90 │ └── example_savetxt.f90 ├── linalg │ ├── CMakeLists.txt │ ├── example_blas_gemv.f90 │ ├── example_chol.f90 │ ├── example_cholesky.f90 │ ├── example_cross_product.f90 │ ├── example_determinant.f90 │ ├── example_determinant2.f90 │ ├── example_diag1.f90 │ ├── example_diag2.f90 │ ├── example_diag3.f90 │ ├── example_diag4.f90 │ ├── example_diag5.f90 │ ├── example_eig.f90 │ ├── example_eig_generalized.f90 │ ├── example_eigh.f90 │ ├── example_eigvals.f90 │ ├── example_eigvals_generalized.f90 │ ├── example_eigvalsh.f90 │ ├── example_eye1.f90 │ ├── example_eye2.f90 │ ├── example_get_norm.f90 │ ├── example_hermitian.f90 │ ├── example_inverse_function.f90 │ ├── example_inverse_inplace.f90 │ ├── example_inverse_operator.f90 │ ├── example_inverse_subroutine.f90 │ ├── example_is_diagonal.f90 │ ├── example_is_hermitian.f90 │ ├── example_is_hessenberg.f90 │ ├── example_is_skew_symmetric.f90 │ ├── example_is_square.f90 │ ├── example_is_symmetric.f90 │ ├── example_is_triangular.f90 │ ├── example_kronecker_product.f90 │ ├── example_lapack_getrf.f90 │ ├── example_lstsq1.f90 │ ├── example_lstsq2.f90 │ ├── example_mnorm.f90 │ ├── example_norm.f90 │ ├── example_outer_product.f90 │ ├── example_pseudoinverse.f90 │ ├── example_qr.f90 │ ├── example_qr_space.f90 │ ├── example_schur_complex.f90 │ ├── example_schur_eigvals.f90 │ ├── example_schur_real.f90 │ ├── example_solve1.f90 │ ├── example_solve2.f90 │ ├── example_solve3.f90 │ ├── example_sparse_data_accessors.f90 │ ├── example_sparse_from_ijv.f90 │ ├── example_sparse_spmv.f90 │ ├── example_state1.f90 │ ├── example_state2.f90 │ ├── example_svd.f90 │ ├── example_svdvals.f90 │ └── example_trace.f90 ├── logger │ ├── CMakeLists.txt │ ├── dummy.txt │ ├── example_add_log_unit.f90 │ ├── example_configure.f90 │ ├── example_global_logger.f90 │ ├── example_log_io_error.f90 │ └── example_log_text_error.f90 ├── math │ ├── CMakeLists.txt │ ├── example_clip_integer.f90 │ ├── example_clip_real.f90 │ ├── example_diff.f90 │ ├── example_gcd.f90 │ ├── example_linspace_complex.f90 │ ├── example_linspace_int16.f90 │ ├── example_logspace_complex.f90 │ ├── example_logspace_int.f90 │ ├── example_logspace_rstart_cbase.f90 │ ├── example_math_all_close.f90 │ ├── example_math_arange.f90 │ ├── example_math_arg.f90 │ ├── example_math_argd.f90 │ ├── example_math_argpi.f90 │ ├── example_math_deg2rad.f90 │ ├── example_math_is_close.f90 │ ├── example_math_rad2deg.f90 │ ├── example_math_swap.f90 │ └── example_meshgrid.f90 ├── optval │ ├── CMakeLists.txt │ └── example_optval.f90 ├── quadrature │ ├── CMakeLists.txt │ ├── example_gauss_legendre.f90 │ ├── example_gauss_legendre_lobatto.f90 │ ├── example_simps.f90 │ ├── example_simps_weights.f90 │ ├── example_trapz.f90 │ └── example_trapz_weights.f90 ├── random │ ├── CMakeLists.txt │ ├── example_dist_rand.f90 │ └── example_random_seed.f90 ├── selection │ ├── CMakeLists.txt │ ├── example_arg_select.f90 │ ├── example_select.f90 │ └── selection_vs_sort.f90 ├── sorting │ ├── CMakeLists.txt │ ├── example_ord_sort.f90 │ ├── example_radix_sort.f90 │ ├── example_sort.f90 │ ├── example_sort_bitset.f90 │ └── example_sort_index.f90 ├── specialfunctions_activations │ ├── CMakeLists.txt │ ├── example_elu.f90 │ ├── example_gaussian.f90 │ ├── example_gelu.f90 │ ├── example_leaky_relu.f90 │ ├── example_logsoftmax.f90 │ ├── example_relu.f90 │ ├── example_selu.f90 │ ├── example_silu.f90 │ ├── example_softmax.f90 │ ├── example_softplus.f90 │ └── example_step.f90 ├── specialfunctions_gamma │ ├── CMakeLists.txt │ ├── example_gamma.f90 │ ├── example_gamma_p.f90 │ ├── example_gamma_q.f90 │ ├── example_ligamma.f90 │ ├── example_log_factorial.f90 │ ├── example_log_gamma.f90 │ └── example_uigamma.f90 ├── stats │ ├── CMakeLists.txt │ ├── example_corr.f90 │ ├── example_cov.f90 │ ├── example_mean.f90 │ ├── example_median.f90 │ ├── example_moment.f90 │ └── example_var.f90 ├── stats_distribution_exponential │ ├── CMakeLists.txt │ ├── example_exponential_cdf.f90 │ ├── example_exponential_pdf.f90 │ └── example_exponential_rvs.f90 ├── stats_distribution_normal │ ├── CMakeLists.txt │ ├── example_normal_cdf.f90 │ ├── example_normal_pdf.f90 │ └── example_normal_rvs.f90 ├── stats_distribution_uniform │ ├── CMakeLists.txt │ ├── example_shuffle.f90 │ ├── example_uniform_cdf.f90 │ ├── example_uniform_pdf.f90 │ └── example_uniform_rvs.f90 ├── string_type │ ├── CMakeLists.txt │ ├── example_adjustl.f90 │ ├── example_adjustr.f90 │ ├── example_char.f90 │ ├── example_char_position.f90 │ ├── example_char_range.f90 │ ├── example_constructor_character.f90 │ ├── example_constructor_empty.f90 │ ├── example_constructor_integer.f90 │ ├── example_constructor_logical.f90 │ ├── example_constructor_scalar.f90 │ ├── example_cont.f90 │ ├── example_eq.f90 │ ├── example_fread.f90 │ ├── example_fwrite.f90 │ ├── example_ge.f90 │ ├── example_gt.f90 │ ├── example_iachar.f90 │ ├── example_ichar.f90 │ ├── example_index.f90 │ ├── example_le.f90 │ ├── example_len.f90 │ ├── example_len_trim.f90 │ ├── example_lge.f90 │ ├── example_lgt.f90 │ ├── example_lle.f90 │ ├── example_llt.f90 │ ├── example_lt.f90 │ ├── example_move.f90 │ ├── example_ne.f90 │ ├── example_repeat.f90 │ ├── example_reverse.f90 │ ├── example_scan.f90 │ ├── example_to_lower.f90 │ ├── example_to_sentence.f90 │ ├── example_to_title.f90 │ ├── example_to_upper.f90 │ ├── example_trim.f90 │ ├── example_uread.f90 │ ├── example_uwrite.f90 │ └── example_verify.f90 ├── stringlist_type │ ├── CMakeLists.txt │ ├── example_stringlist_type_clear.f90 │ ├── example_stringlist_type_concatenate_operator.f90 │ ├── example_stringlist_type_constructor.f90 │ ├── example_stringlist_type_equality_operator.f90 │ ├── example_stringlist_type_fidx_bidx.f90 │ ├── example_stringlist_type_get.f90 │ ├── example_stringlist_type_inequality_operator.f90 │ ├── example_stringlist_type_insert_at.f90 │ └── example_stringlist_type_len.f90 ├── strings │ ├── CMakeLists.txt │ ├── example_chomp.f90 │ ├── example_count.f90 │ ├── example_ends_with.f90 │ ├── example_find.f90 │ ├── example_join.f90 │ ├── example_padl.f90 │ ├── example_padr.f90 │ ├── example_replace_all.f90 │ ├── example_slice.f90 │ ├── example_starts_with.f90 │ ├── example_stream_of_strings_to_numbers.f90 │ ├── example_string_to_number.f90 │ ├── example_strip.f90 │ ├── example_to_c_char.f90 │ ├── example_to_string.f90 │ └── example_zfill.f90 ├── system │ ├── CMakeLists.txt │ ├── example_delete_file.f90 │ ├── example_get_runtime_os.f90 │ ├── example_is_directory.f90 │ ├── example_null_device.f90 │ ├── example_os_type.f90 │ ├── example_process_1.f90 │ ├── example_process_2.f90 │ ├── example_process_3.f90 │ ├── example_process_4.f90 │ ├── example_process_5.f90 │ ├── example_process_6.f90 │ ├── example_process_7.f90 │ └── example_sleep.f90 └── version │ ├── CMakeLists.txt │ └── example_version.f90 ├── fpm.toml ├── include └── common.fypp ├── src ├── CMakeLists.txt ├── blas │ ├── CMakeLists.txt │ ├── stdlib_blas.fypp │ ├── stdlib_blas_constants.fypp │ ├── stdlib_blas_level1.fypp │ ├── stdlib_blas_level2_ban.fypp │ ├── stdlib_blas_level2_gen.fypp │ ├── stdlib_blas_level2_pac.fypp │ ├── stdlib_blas_level2_sym.fypp │ ├── stdlib_blas_level2_tri.fypp │ ├── stdlib_blas_level3_gen.fypp │ ├── stdlib_blas_level3_sym.fypp │ ├── stdlib_blas_level3_tri.fypp │ └── stdlib_linalg_blas_aux.fypp ├── f08estop.f90 ├── f18estop.f90 ├── lapack │ ├── CMakeLists.txt │ ├── stdlib_lapack_auxiliary.fypp │ ├── stdlib_lapack_base.fypp │ ├── stdlib_lapack_blas_like_base.fypp │ ├── stdlib_lapack_blas_like_l1.fypp │ ├── stdlib_lapack_blas_like_l2.fypp │ ├── stdlib_lapack_blas_like_l3.fypp │ ├── stdlib_lapack_blas_like_mnorm.fypp │ ├── stdlib_lapack_blas_like_scalar.fypp │ ├── stdlib_lapack_cosine_sine.fypp │ ├── stdlib_lapack_cosine_sine2.fypp │ ├── stdlib_lapack_eig_svd_lsq.fypp │ ├── stdlib_lapack_eigv_comp.fypp │ ├── stdlib_lapack_eigv_comp2.fypp │ ├── stdlib_lapack_eigv_gen.fypp │ ├── stdlib_lapack_eigv_gen2.fypp │ ├── stdlib_lapack_eigv_gen3.fypp │ ├── stdlib_lapack_eigv_std_driver.fypp │ ├── stdlib_lapack_eigv_svd_bidiag_dc.fypp │ ├── stdlib_lapack_eigv_svd_drivers.fypp │ ├── stdlib_lapack_eigv_svd_drivers2.fypp │ ├── stdlib_lapack_eigv_svd_drivers3.fypp │ ├── stdlib_lapack_eigv_sym.fypp │ ├── stdlib_lapack_eigv_sym_comp.fypp │ ├── stdlib_lapack_eigv_tridiag.fypp │ ├── stdlib_lapack_eigv_tridiag2.fypp │ ├── stdlib_lapack_eigv_tridiag3.fypp │ ├── stdlib_lapack_givens_jacobi_rot.fypp │ ├── stdlib_lapack_householder_reflectors.fypp │ ├── stdlib_lapack_lsq.fypp │ ├── stdlib_lapack_lsq_aux.fypp │ ├── stdlib_lapack_lsq_constrained.fypp │ ├── stdlib_lapack_orthogonal_factors.fypp │ ├── stdlib_lapack_orthogonal_factors_ql.fypp │ ├── stdlib_lapack_orthogonal_factors_qr.fypp │ ├── stdlib_lapack_orthogonal_factors_rz.fypp │ ├── stdlib_lapack_others.fypp │ ├── stdlib_lapack_others_sm.fypp │ ├── stdlib_lapack_solve.fypp │ ├── stdlib_lapack_solve_aux.fypp │ ├── stdlib_lapack_solve_chol.fypp │ ├── stdlib_lapack_solve_chol_comp.fypp │ ├── stdlib_lapack_solve_ldl.fypp │ ├── stdlib_lapack_solve_ldl_comp.fypp │ ├── stdlib_lapack_solve_ldl_comp2.fypp │ ├── stdlib_lapack_solve_ldl_comp3.fypp │ ├── stdlib_lapack_solve_ldl_comp4.fypp │ ├── stdlib_lapack_solve_lu.fypp │ ├── stdlib_lapack_solve_lu_comp.fypp │ ├── stdlib_lapack_solve_tri_comp.fypp │ ├── stdlib_lapack_svd_bidiag_qr.fypp │ ├── stdlib_lapack_svd_comp.fypp │ ├── stdlib_lapack_svd_comp2.fypp │ └── stdlib_linalg_lapack_aux.fypp ├── stdlib_ansi.f90 ├── stdlib_ansi_operator.f90 ├── stdlib_ansi_to_string.f90 ├── stdlib_array.f90 ├── stdlib_ascii.fypp ├── stdlib_bitsets.fypp ├── stdlib_bitsets_64.fypp ├── stdlib_bitsets_large.fypp ├── stdlib_codata.f90 ├── stdlib_codata_type.fypp ├── stdlib_constants.fypp ├── stdlib_error.fypp ├── stdlib_hash_32bit.fypp ├── stdlib_hash_32bit_fnv.fypp ├── stdlib_hash_32bit_nm.fypp ├── stdlib_hash_32bit_water.fypp ├── stdlib_hash_64bit.fypp ├── stdlib_hash_64bit_fnv.fypp ├── stdlib_hash_64bit_pengy.fypp ├── stdlib_hash_64bit_spookyv2.fypp ├── stdlib_hashmap_chaining.f90 ├── stdlib_hashmap_open.f90 ├── stdlib_hashmap_wrappers.f90 ├── stdlib_hashmaps.f90 ├── stdlib_intrinsics.fypp ├── stdlib_intrinsics_dot_product.fypp ├── stdlib_intrinsics_sum.fypp ├── stdlib_io.fypp ├── stdlib_io_npy.fypp ├── stdlib_io_npy_load.fypp ├── stdlib_io_npy_save.fypp ├── stdlib_kinds.fypp ├── stdlib_linalg.fypp ├── stdlib_linalg_blas.fypp ├── stdlib_linalg_cholesky.fypp ├── stdlib_linalg_constants.fypp ├── stdlib_linalg_cross_product.fypp ├── stdlib_linalg_determinant.fypp ├── stdlib_linalg_diag.fypp ├── stdlib_linalg_eigenvalues.fypp ├── stdlib_linalg_inverse.fypp ├── stdlib_linalg_kronecker.fypp ├── stdlib_linalg_lapack.fypp ├── stdlib_linalg_least_squares.fypp ├── stdlib_linalg_norms.fypp ├── stdlib_linalg_outer_product.fypp ├── stdlib_linalg_pinv.fypp ├── stdlib_linalg_qr.fypp ├── stdlib_linalg_schur.fypp ├── stdlib_linalg_solve.fypp ├── stdlib_linalg_state.fypp ├── stdlib_linalg_svd.fypp ├── stdlib_logger.f90 ├── stdlib_math.fypp ├── stdlib_math_all_close.fypp ├── stdlib_math_arange.fypp ├── stdlib_math_diff.fypp ├── stdlib_math_is_close.fypp ├── stdlib_math_linspace.fypp ├── stdlib_math_logspace.fypp ├── stdlib_math_meshgrid.fypp ├── stdlib_optval.fypp ├── stdlib_quadrature.fypp ├── stdlib_quadrature_gauss.f90 ├── stdlib_quadrature_simps.fypp ├── stdlib_quadrature_trapz.fypp ├── stdlib_random.fypp ├── stdlib_selection.fypp ├── stdlib_sorting.fypp ├── stdlib_sorting_ord_sort.fypp ├── stdlib_sorting_radix_sort.f90 ├── stdlib_sorting_sort.fypp ├── stdlib_sorting_sort_index.fypp ├── stdlib_sparse.f90 ├── stdlib_sparse_constants.fypp ├── stdlib_sparse_conversion.fypp ├── stdlib_sparse_kinds.fypp ├── stdlib_sparse_spmv.fypp ├── stdlib_specialfunctions.fypp ├── stdlib_specialfunctions_activations.fypp ├── stdlib_specialfunctions_gamma.fypp ├── stdlib_specialfunctions_legendre.f90 ├── stdlib_stats.fypp ├── stdlib_stats_corr.fypp ├── stdlib_stats_cov.fypp ├── stdlib_stats_distribution_exponential.fypp ├── stdlib_stats_distribution_normal.fypp ├── stdlib_stats_distribution_uniform.fypp ├── stdlib_stats_mean.fypp ├── stdlib_stats_median.fypp ├── stdlib_stats_moment.fypp ├── stdlib_stats_moment_all.fypp ├── stdlib_stats_moment_mask.fypp ├── stdlib_stats_moment_scalar.fypp ├── stdlib_stats_var.fypp ├── stdlib_str2num.fypp ├── stdlib_string_type.fypp ├── stdlib_string_type_constructor.fypp ├── stdlib_stringlist_type.f90 ├── stdlib_strings.fypp ├── stdlib_strings_to_string.fypp ├── stdlib_system.F90 ├── stdlib_system_subprocess.F90 ├── stdlib_system_subprocess.c └── stdlib_version.fypp └── test ├── CMakeLists.txt ├── array ├── CMakeLists.txt └── test_logicalloc.f90 ├── ascii ├── CMakeLists.txt └── test_ascii.f90 ├── bitsets ├── CMakeLists.txt ├── test_stdlib_bitset_64.f90 └── test_stdlib_bitset_large.f90 ├── constants ├── CMakeLists.txt └── test_constants.f90 ├── hash_functions ├── CMakeLists.txt ├── README.md ├── SpookyV2.cpp ├── SpookyV2.h ├── SpookyV2Test.cpp ├── generate_hash_arrays.cpp ├── nmhash.c ├── nmhash.h ├── pengyhash.c ├── pengyhash.h ├── test_hash_functions.f90 ├── waterhash.c └── waterhash.h ├── hash_functions_perf ├── CMakeLists.txt ├── test_32_bit_hash_performance.f90 └── test_64_bit_hash_performance.f90 ├── hashmaps ├── CMakeLists.txt ├── Makefile.manual ├── test_chaining_maps.f90 ├── test_maps.fypp └── test_open_maps.f90 ├── intrinsics ├── CMakeLists.txt └── test_intrinsics.fypp ├── io ├── CMakeLists.txt ├── test_get_line.f90 ├── test_loadtxt.f90 ├── test_loadtxt_qp.fypp ├── test_npy.f90 ├── test_open.f90 ├── test_parse_mode.f90 ├── test_savetxt.f90 └── test_savetxt_qp.fypp ├── linalg ├── CMakeLists.txt ├── test_blas_lapack.fypp ├── test_linalg.fypp ├── test_linalg_cholesky.fypp ├── test_linalg_determinant.fypp ├── test_linalg_eigenvalues.fypp ├── test_linalg_inverse.fypp ├── test_linalg_lstsq.fypp ├── test_linalg_matrix_property_checks.fypp ├── test_linalg_mnorm.fypp ├── test_linalg_norm.fypp ├── test_linalg_pseudoinverse.fypp ├── test_linalg_qr.fypp ├── test_linalg_schur.fypp ├── test_linalg_solve.fypp ├── test_linalg_sparse.fypp └── test_linalg_svd.fypp ├── logger ├── CMakeLists.txt └── test_stdlib_logger.f90 ├── math ├── CMakeLists.txt ├── test_linspace.f90 ├── test_logspace.f90 ├── test_meshgrid.fypp └── test_stdlib_math.fypp ├── optval ├── CMakeLists.txt └── test_optval.fypp ├── quadrature ├── CMakeLists.txt ├── test_gauss.f90 ├── test_simps.fypp └── test_trapz.fypp ├── selection ├── CMakeLists.txt └── test_selection.fypp ├── sorting ├── CMakeLists.txt └── test_sorting.fypp ├── specialfunctions ├── CMakeLists.txt ├── Makefile.manual ├── test_specialfunctions_activations.fypp └── test_specialfunctions_gamma.fypp ├── stats ├── CMakeLists.txt ├── test_corr.f90 ├── test_cov.f90 ├── test_distribution_exponential.fypp ├── test_distribution_normal.fypp ├── test_distribution_uniform.fypp ├── test_mean.fypp ├── test_mean_f03.fypp ├── test_median.fypp ├── test_moment.f90 ├── test_random.f90 ├── test_rawmoment.f90 ├── test_var.f90 └── test_varn.f90 ├── string ├── CMakeLists.txt ├── test_string_assignment.fypp ├── test_string_derivedtype_io.f90 ├── test_string_functions.f90 ├── test_string_intrinsic.f90 ├── test_string_match.f90 ├── test_string_operator.f90 ├── test_string_strip_chomp.f90 ├── test_string_to_number.fypp └── test_string_to_string.f90 ├── stringlist ├── CMakeLists.txt ├── test_append_prepend.f90 └── test_insert_at.f90 ├── system ├── CMakeLists.txt ├── test_filesystem.f90 ├── test_os.f90 ├── test_sleep.f90 └── test_subprocess.f90 └── terminal ├── CMakeLists.txt └── test_colors.f90 /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-2021 stdlib contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.7.0 2 | -------------------------------------------------------------------------------- /config/requirements.txt: -------------------------------------------------------------------------------- 1 | fypp 2 | argparse 3 | joblib -------------------------------------------------------------------------------- /config/template.cmake: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | set("@PROJECT_NAME@_WITH_CBOOL" @WITH_CBOOL@) 4 | set("@PROJECT_NAME@_WITH_QP" @WITH_QP@) 5 | set("@PROJECT_NAME@_WITH_XDP" @WITH_XDP@) 6 | set("@PROJECT_NAME@_WITH_ILP64" @WITH_ILP64@) 7 | 8 | if(NOT TARGET "@PROJECT_NAME@::@PROJECT_NAME@") 9 | include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") 10 | endif() 11 | -------------------------------------------------------------------------------- /config/template.pc: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ 3 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 4 | moduledir=${prefix}/@CMAKE_INSTALL_MODULEDIR@ 5 | 6 | Name: @PROJECT_NAME@ 7 | Description: @PROJECT_DESCRIPTION@ 8 | Version: @PROJECT_VERSION@ 9 | Libs: -L${libdir} -l@PROJECT_NAME@ 10 | Cflags: -I${includedir} -I${moduledir} 11 | -------------------------------------------------------------------------------- /doc/License.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Fortran stdlib License (MIT) 3 | --- 4 | 5 | {!LICENSE!} 6 | -------------------------------------------------------------------------------- /doc/changelog.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Changelog 3 | --- 4 | 5 | {!CHANGELOG.md!} 6 | -------------------------------------------------------------------------------- /doc/contributing/CodeOfConduct.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Contributor Code of Conduct 3 | --- 4 | 5 | {!CODE_OF_CONDUCT.md!} 6 | -------------------------------------------------------------------------------- /doc/contributing/StyleGuide.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Style Guide 3 | --- 4 | 5 | @note 6 | This is a living document. 7 | You are welcome to propose changes to this workflow by opening an 8 | [issue](https://github.com/fortran-lang/stdlib/issues). 9 | 10 | [TOC] 11 | 12 | {!STYLE_GUIDE.md!} 13 | -------------------------------------------------------------------------------- /doc/contributing/Workflow.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Workflow for Contributors 3 | --- 4 | 5 | @note 6 | This is a living document. 7 | You are welcome to propose changes to this workflow by opening an 8 | [issue](https://github.com/fortran-lang/stdlib/issues). 9 | 10 | {!WORKFLOW.md!} 11 | -------------------------------------------------------------------------------- /doc/contributing/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Contributing 3 | --- 4 | 5 | This page aims to provide information that are useful for `stdlib` contributors. 6 | Issues can be reported on [GitHub](https://github.com/fortran-lang/stdlib/issues). 7 | 8 | -------------------------------------------------------------------------------- /doc/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Contributing and specs 3 | --- 4 | 5 | @warning 6 | This page is currently under construction! 7 | 8 | @todo 9 | Improve the title of this FORD "pages" section, and 10 | improve the organization of pages 11 | to separate end-user, high-level documentation and examples from developer documentation and specs. 12 | -------------------------------------------------------------------------------- /doc/media/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fortran-lang/stdlib/30ccd9d46496126a24f240ccfa6f9f9c762219a5/doc/media/favicon.ico -------------------------------------------------------------------------------- /doc/specs/stdlib_optval.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: optval 3 | --- 4 | 5 | # Default values for optional arguments 6 | 7 | [TOC] 8 | 9 | ## `optval` - fallback value for optional arguments 10 | 11 | ### Status 12 | 13 | Experimental 14 | 15 | ### Description 16 | 17 | Returns `x` if it is present, otherwise `default`. 18 | 19 | This function is intended to be called in a procedure with one or more `optional` arguments, in order to conveniently fall back to a default value if an `optional` argument is not present. 20 | 21 | ### Syntax 22 | 23 | `result = ` [[stdlib_optval(module):optval(interface)]] `(x, default)` 24 | 25 | ### Arguments 26 | 27 | `x`: Shall be of type `integer`, `real`, `complex`, or `logical`, or a scalar of type `character`. 28 | 29 | `default`: Shall have the same type, kind, and rank as `x`. 30 | 31 | ### Return value 32 | 33 | If `x` is present, the result is `x`, otherwise the result is `default`. 34 | 35 | ### Example 36 | 37 | ```fortran 38 | {!example/optval/example_optval.f90!} 39 | ``` 40 | -------------------------------------------------------------------------------- /example/ansi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(ansi_color) 2 | ADD_EXAMPLE(ansi_combine) 3 | ADD_EXAMPLE(ansi_concat) 4 | ADD_EXAMPLE(ansi_to_string) -------------------------------------------------------------------------------- /example/ansi/example_ansi_color.f90: -------------------------------------------------------------------------------- 1 | program example_ansi_color 2 | use stdlib_ansi, only : fg_color_blue, style_bold, style_reset, ansi_code, & 3 | & operator(//), operator(+) 4 | implicit none 5 | type(ansi_code) :: highlight, reset 6 | 7 | print '(a)', highlight // "Dull text message" // reset 8 | 9 | highlight = fg_color_blue + style_bold 10 | reset = style_reset 11 | 12 | print '(a)', highlight // "Colorful text message" // reset 13 | end program example_ansi_color -------------------------------------------------------------------------------- /example/ansi/example_ansi_combine.f90: -------------------------------------------------------------------------------- 1 | program example_ansi_combine 2 | use stdlib_ansi, only : fg_color_red, style_bold, ansi_code, operator(+), to_string 3 | implicit none 4 | type(ansi_code) :: bold_red 5 | 6 | bold_red = fg_color_red + style_bold 7 | print '(a)', to_string(bold_red) 8 | 9 | end program example_ansi_combine -------------------------------------------------------------------------------- /example/ansi/example_ansi_concat.f90: -------------------------------------------------------------------------------- 1 | program example_ansi_concat 2 | use stdlib_ansi, only : fg_color_red, style_reset, operator(//) 3 | implicit none 4 | 5 | print '(a)', fg_color_red // "Colorized text message" // style_reset 6 | end program example_ansi_concat -------------------------------------------------------------------------------- /example/ansi/example_ansi_to_string.f90: -------------------------------------------------------------------------------- 1 | program example_ansi_to_string 2 | use stdlib_ansi, only : fg_color_green, style_reset, to_string 3 | implicit none 4 | 5 | print '(a)', to_string(fg_color_green) // "Colorized text message" // to_string(style_reset) 6 | end program example_ansi_to_string -------------------------------------------------------------------------------- /example/array/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(falseloc) 2 | ADD_EXAMPLE(trueloc) 3 | -------------------------------------------------------------------------------- /example/array/example_falseloc.f90: -------------------------------------------------------------------------------- 1 | program example_falseloc 2 | use stdlib_array, only: falseloc 3 | implicit none 4 | real, allocatable :: array(:) 5 | allocate (array(-200:200)) 6 | call random_number(array) 7 | array(falseloc(array < 0.5, lbound(array, 1))) = 0.0 8 | end program example_falseloc 9 | -------------------------------------------------------------------------------- /example/array/example_trueloc.f90: -------------------------------------------------------------------------------- 1 | program example_trueloc 2 | use stdlib_array, only: trueloc 3 | implicit none 4 | real, allocatable :: array(:) 5 | allocate (array(500)) 6 | call random_number(array) 7 | array(trueloc(array > 0.5)) = 0.0 8 | end program example_trueloc 9 | -------------------------------------------------------------------------------- /example/ascii/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(ascii_reverse) 2 | ADD_EXAMPLE(ascii_to_lower) 3 | ADD_EXAMPLE(ascii_to_sentence) 4 | ADD_EXAMPLE(ascii_to_title) 5 | ADD_EXAMPLE(ascii_to_upper) 6 | -------------------------------------------------------------------------------- /example/ascii/example_ascii_reverse.f90: -------------------------------------------------------------------------------- 1 | program example_reverse 2 | use stdlib_ascii, only: reverse 3 | implicit none 4 | print'(a)', reverse("Hello, World!") ! returns "!dlroW ,olleH" 5 | end program example_reverse 6 | -------------------------------------------------------------------------------- /example/ascii/example_ascii_to_lower.f90: -------------------------------------------------------------------------------- 1 | program example_to_lower 2 | use stdlib_ascii, only: to_lower 3 | implicit none 4 | print'(a)', to_lower("HELLo!") ! returns "hello!" 5 | end program example_to_lower 6 | -------------------------------------------------------------------------------- /example/ascii/example_ascii_to_sentence.f90: -------------------------------------------------------------------------------- 1 | program example_to_sentence 2 | use stdlib_ascii, only: to_sentence 3 | implicit none 4 | print *, to_sentence("hello!") ! returns "Hello!" 5 | print *, to_sentence("'enquoted'") ! returns "'Enquoted'" 6 | print *, to_sentence("1st") ! returns "1st" 7 | end program example_to_sentence 8 | -------------------------------------------------------------------------------- /example/ascii/example_ascii_to_title.f90: -------------------------------------------------------------------------------- 1 | program example_to_title 2 | use stdlib_ascii, only: to_title 3 | implicit none 4 | print *, to_title("hello there!") ! returns "Hello There!" 5 | print *, to_title("'enquoted'") ! returns "'Enquoted'" 6 | print *, to_title("1st") ! returns "1st" 7 | end program example_to_title 8 | -------------------------------------------------------------------------------- /example/ascii/example_ascii_to_upper.f90: -------------------------------------------------------------------------------- 1 | program example_to_upper 2 | use stdlib_ascii, only: to_upper 3 | implicit none 4 | print'(a)', to_upper("hello!") ! returns "HELLO!" 5 | end program example_to_upper 6 | -------------------------------------------------------------------------------- /example/bitsets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(bitsets_all) 2 | ADD_EXAMPLE(bitsets_and) 3 | ADD_EXAMPLE(bitsets_and_not) 4 | ADD_EXAMPLE(bitsets_any) 5 | ADD_EXAMPLE(bitsets_assignment) 6 | ADD_EXAMPLE(bitsets_bit_count) 7 | ADD_EXAMPLE(bitsets_bits) 8 | ADD_EXAMPLE(bitsets_clear) 9 | ADD_EXAMPLE(bitsets_equality) 10 | ADD_EXAMPLE(bitsets_extract) 11 | ADD_EXAMPLE(bitsets_flip) 12 | ADD_EXAMPLE(bitsets_from_string) 13 | ADD_EXAMPLE(bitsets_ge) 14 | ADD_EXAMPLE(bitsets_gt) 15 | ADD_EXAMPLE(bitsets_inequality) 16 | ADD_EXAMPLE(bitsets_init) 17 | ADD_EXAMPLE(bitsets_input) 18 | ADD_EXAMPLE(bitsets_le) 19 | ADD_EXAMPLE(bitsets_lt) 20 | ADD_EXAMPLE(bitsets_none) 21 | ADD_EXAMPLE(bitsets_not) 22 | ADD_EXAMPLE(bitsets_or) 23 | ADD_EXAMPLE(bitsets_output) 24 | ADD_EXAMPLE(bitsets_read_bitset) 25 | ADD_EXAMPLE(bitsets_set) 26 | ADD_EXAMPLE(bitsets_test) 27 | ADD_EXAMPLE(bitsets_to_string) 28 | ADD_EXAMPLE(bitsets_value) 29 | ADD_EXAMPLE(bitsets_write_bitset) 30 | ADD_EXAMPLE(bitsets_xor) 31 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_all.f90: -------------------------------------------------------------------------------- 1 | program example_all 2 | use stdlib_bitsets 3 | implicit none 4 | character(*), parameter :: & 5 | bits_all = '111111111111111111111111111111111' 6 | type(bitset_64) :: set0 7 | call set0%from_string(bits_all) 8 | if (.not. set0%all()) then 9 | error stop "FROM_STRING failed to interpret"// & 10 | "BITS_ALL's value properly." 11 | else 12 | write (*, *) "FROM_STRING transferred BITS_ALL properly"// & 13 | " into set0." 14 | end if 15 | end program example_all 16 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_and.f90: -------------------------------------------------------------------------------- 1 | program example_and 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0, set1 5 | call set0%init(166) 6 | call set1%init(166) 7 | call and(set0, set1) ! none none 8 | if (set0%none()) write (*, *) 'First test of AND worked.' 9 | call set0%not() 10 | call and(set0, set1) ! all none 11 | if (set0%none()) write (*, *) 'Second test of AND worked.' 12 | call set1%not() 13 | call and(set0, set1) ! none all 14 | if (set0%none()) write (*, *) 'Third test of AND worked.' 15 | call set0%not() 16 | call and(set0, set1) ! all all 17 | if (set0%all()) write (*, *) 'Fourth test of AND worked.' 18 | end program example_and 19 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_and_not.f90: -------------------------------------------------------------------------------- 1 | program example_and_not 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0, set1 5 | call set0%init(166) 6 | call set1%init(166) 7 | call and_not(set0, set1) ! none none 8 | if (set0%none()) write (*, *) 'First test of AND_NOT worked.' 9 | call set0%not() 10 | call and_not(set0, set1) ! all none 11 | if (set0%all()) write (*, *) 'Second test of AND_NOT worked.' 12 | call set0%not() 13 | call set1%not() 14 | call and_not(set0, set1) ! none all 15 | if (set0%none()) write (*, *) 'Third test of AND_NOT worked.' 16 | call set0%not() 17 | call and_not(set0, set1) ! all all 18 | if (set0%none()) write (*, *) 'Fourth test of AND_NOT worked.' 19 | end program example_and_not 20 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_any.f90: -------------------------------------------------------------------------------- 1 | program example_any 2 | use stdlib_bitsets 3 | implicit none 4 | character(*), parameter :: & 5 | bits_0 = '0000000000000000000' 6 | type(bitset_64) :: set0 7 | call set0%from_string(bits_0) 8 | if (.not. set0%any()) then 9 | write (*, *) "FROM_STRING interpreted "// & 10 | "BITS_0's value properly." 11 | end if 12 | call set0%set(5) 13 | if (set0%any()) then 14 | write (*, *) "ANY interpreted SET0's value properly." 15 | end if 16 | end program example_any 17 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_assignment.f90: -------------------------------------------------------------------------------- 1 | program example_assignment 2 | use stdlib_bitsets 3 | use stdlib_kinds, only: int8, int32 4 | implicit none 5 | logical(int8) :: logical1(64) = .true. 6 | logical(int32), allocatable :: logical2(:) 7 | type(bitset_64) :: set0, set1 8 | set0 = logical1 9 | if (set0%bits() /= 64) then 10 | error stop & 11 | ' initialization with logical(int8) failed to set'// & 12 | ' the right size.' 13 | else if (.not. set0%all()) then 14 | error stop ' initialization with'// & 15 | ' logical(int8) failed to set the right values.' 16 | else 17 | write (*, *) 'Initialization with logical(int8) succeeded.' 18 | end if 19 | set1 = set0 20 | if (set1 == set0) & 21 | write (*, *) 'Initialization by assignment succeeded' 22 | logical2 = set1 23 | if (all(logical2)) then 24 | write (*, *) 'Initialization of logical(int32) succeeded.' 25 | end if 26 | end program example_assignment 27 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_bit_count.f90: -------------------------------------------------------------------------------- 1 | program example_bit_count 2 | use stdlib_bitsets 3 | implicit none 4 | character(*), parameter :: & 5 | bits_0 = '0000000000000000000' 6 | type(bitset_64) :: set0 7 | type(bitset_large) :: set1 8 | logical, allocatable :: logi(:) 9 | 10 | call set0%from_string(bits_0) 11 | if (set0%bit_count() == 0) then 12 | write (*, *) "FROM_STRING interpreted "// & 13 | "BITS_0's value properly." 14 | end if 15 | call set0%set(5) 16 | if (set0%bit_count() == 1) then 17 | write (*, *) "BIT_COUNT interpreted SET0's value properly." 18 | end if 19 | 20 | allocate( logi(1000), source=.false.) 21 | logi(1::7) = .true. 22 | set1 = logi 23 | if (set1%bit_count() == count(logi)) then 24 | write (*, *) "BIT_COUNT interpreted SET1's value properly." 25 | end if 26 | end program example_bit_count 27 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_bits.f90: -------------------------------------------------------------------------------- 1 | program example_bits 2 | use stdlib_bitsets 3 | implicit none 4 | character(*), parameter :: & 5 | bits_0 = '0000000000000000000' 6 | type(bitset_64) :: set0 7 | call set0%from_string(bits_0) 8 | if (set0%bits() == 19) then 9 | write (*, *) "FROM_STRING interpreted "// & 10 | "BITS_0's size properly." 11 | end if 12 | end program example_bits 13 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_clear.f90: -------------------------------------------------------------------------------- 1 | program example_clear 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0 5 | call set0%init(166) 6 | call set0%not() 7 | if (set0%all()) write (*, *) 'SET0 is properly initialized.' 8 | call set0%clear(165) 9 | if (.not. set0%test(165)) write (*, *) 'Bit 165 is cleared.' 10 | call set0%clear(0, 164) 11 | if (set0%none()) write (*, *) 'All bits are cleared.' 12 | end program example_clear 13 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_equality.f90: -------------------------------------------------------------------------------- 1 | program example_equality 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_64) :: set0, set1, set2 5 | call set0%init(33) 6 | call set1%init(33) 7 | call set2%init(33) 8 | call set1%set(0) 9 | call set2%set(32) 10 | if (set0 == set0 .and. set1 == set1 .and. set2 == set2 .and. & 11 | .not. set0 == set1 .and. .not. set0 == set2 .and. .not. & 12 | set1 == set2) then 13 | write (*, *) 'Passed 64 bit equality tests.' 14 | else 15 | error stop 'Failed 64 bit equality tests.' 16 | end if 17 | end program example_equality 18 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_extract.f90: -------------------------------------------------------------------------------- 1 | program example_extract 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0, set1 5 | call set0%init(166) 6 | call set0%set(100, 150) 7 | call extract(set1, set0, 100, 150) 8 | if (set1%bits() == 51) & 9 | write (*, *) 'SET1 has the proper size.' 10 | if (set1%all()) write (*, *) 'SET1 has the proper values.' 11 | end program example_extract 12 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_flip.f90: -------------------------------------------------------------------------------- 1 | program example_flip 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0 5 | call set0%init(166) 6 | if (set0%none()) write (*, *) 'SET0 is properly initialized.' 7 | call set0%flip(165) 8 | if (set0%test(165)) write (*, *) 'Bit 165 is flipped.' 9 | call set0%flip(0, 164) 10 | if (set0%all()) write (*, *) 'All bits are flipped.' 11 | end program example_flip 12 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_from_string.f90: -------------------------------------------------------------------------------- 1 | program example_from_string 2 | use stdlib_bitsets 3 | implicit none 4 | character(*), parameter :: & 5 | bits_all = '111111111111111111111111111111111' 6 | type(bitset_64) :: set0 7 | call set0%from_string(bits_all) 8 | if (bits(set0) /= 33) then 9 | error stop "FROM_STRING failed to interpret "// & 10 | "BITS_ALL's size properly." 11 | else if (.not. set0%all()) then 12 | error stop "FROM_STRING failed to interpret"// & 13 | "BITS_ALL's value properly." 14 | else 15 | write (*, *) "FROM_STRING transferred BITS_ALL properly"// & 16 | " into set0." 17 | end if 18 | end program example_from_string 19 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_ge.f90: -------------------------------------------------------------------------------- 1 | program example_ge 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_64) :: set0, set1, set2 5 | call set0%init(33) 6 | call set1%init(33) 7 | call set2%init(33) 8 | call set1%set(0) 9 | call set2%set(32) 10 | if (set1 >= set0 .and. set2 >= set1 .and. set2 >= set0 .and. & 11 | set0 >= set0 .and. set1 >= set1 .and. set2 >= set2 .and. & 12 | .not. set0 >= set1 .and. .not. set0 >= set2 .and. .not. & 13 | set1 >= set2) then 14 | write (*, *) 'Passed 64 bit greater than or equals tests.' 15 | else 16 | error stop 'Failed 64 bit greater than or equals tests.' 17 | end if 18 | end program example_ge 19 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_gt.f90: -------------------------------------------------------------------------------- 1 | program example_gt 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_64) :: set0, set1, set2 5 | call set0%init(33) 6 | call set1%init(33) 7 | call set2%init(33) 8 | call set1%set(0) 9 | call set2%set(32) 10 | if (set1 > set0 .and. set2 > set1 .and. set2 > set0 .and. & 11 | .not. set0 > set0 .and. .not. set0 > set1 .and. .not. & 12 | set1 > set2) then 13 | write (*, *) 'Passed 64 bit greater than tests.' 14 | else 15 | error stop 'Failed 64 bit greater than tests.' 16 | end if 17 | end program example_gt 18 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_inequality.f90: -------------------------------------------------------------------------------- 1 | program example_inequality 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_64) :: set0, set1, set2 5 | call set0%init(33) 6 | call set1%init(33) 7 | call set2%init(33) 8 | call set1%set(0) 9 | call set2%set(32) 10 | if (set0 /= set1 .and. set0 /= set2 .and. set1 /= set2 .and. & 11 | .not. set0 /= set0 .and. .not. set1 /= set1 .and. .not. & 12 | set2 /= set2) then 13 | write (*, *) 'Passed 64 bit inequality tests.' 14 | else 15 | error stop 'Failed 64 bit inequality tests.' 16 | end if 17 | end program example_inequality 18 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_init.f90: -------------------------------------------------------------------------------- 1 | program example_init 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0 5 | call set0%init(166) 6 | if (set0%bits() == 166) & 7 | write (*, *) 'SET0 has the proper size.' 8 | if (set0%none()) write (*, *) 'SET0 is properly initialized.' 9 | end program example_init 10 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_input.f90: -------------------------------------------------------------------------------- 1 | program example_input 2 | use stdlib_bitsets 3 | implicit none 4 | character(*), parameter :: & 5 | bits_0 = '000000000000000000000000000000000', & 6 | bits_1 = '000000000000000000000000000000001', & 7 | bits_33 = '100000000000000000000000000000000' 8 | integer :: unit 9 | type(bitset_64) :: set0, set1, set2, set3, set4, set5 10 | call set0%from_string(bits_0) 11 | call set1%from_string(bits_1) 12 | call set2%from_string(bits_33) 13 | open (newunit=unit, file='test.bin', status='replace', & 14 | form='unformatted', action='write') 15 | call set2%output(unit) 16 | call set1%output(unit) 17 | call set0%output(unit) 18 | close (unit) 19 | open (newunit=unit, file='test.bin', status='old', & 20 | form='unformatted', action='read') 21 | call set5%input(unit) 22 | call set4%input(unit) 23 | call set3%input(unit) 24 | close (unit) 25 | if (set3 /= set0 .or. set4 /= set1 .or. set5 /= set2) then 26 | error stop 'Transfer to and from units using '// & 27 | ' output and input failed.' 28 | else 29 | write (*, *) 'Transfer to and from units using '// & 30 | 'output and input succeeded.' 31 | end if 32 | end program example_input 33 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_le.f90: -------------------------------------------------------------------------------- 1 | program example_le 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_64) :: set0, set1, set2 5 | call set0%init(33) 6 | call set1%init(33) 7 | call set2%init(33) 8 | call set1%set(0) 9 | call set2%set(32) 10 | if (set0 <= set1 .and. set1 <= set2 .and. set0 <= set2 .and. & 11 | set0 <= set0 .and. set1 <= set1 .and. set2 <= set2 .and. & 12 | .not. set1 <= set0 .and. .not. set2 <= set0 .and. .not. & 13 | set2 <= set1) then 14 | write (*, *) 'Passed 64 bit less than or equal tests.' 15 | else 16 | error stop 'Failed 64 bit less than or equal tests.' 17 | end if 18 | end program example_le 19 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_lt.f90: -------------------------------------------------------------------------------- 1 | program example_lt 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_64) :: set0, set1, set2 5 | call set0%init(33) 6 | call set1%init(33) 7 | call set2%init(33) 8 | call set1%set(0) 9 | call set2%set(32) 10 | if (set0 < set1 .and. set1 < set2 .and. set0 < set2 .and. & 11 | .not. set0 < set0 .and. .not. set2 < set0 .and. .not. & 12 | set2 < set1) then 13 | write (*, *) 'Passed 64 bit less than tests.' 14 | else 15 | error stop 'Failed 64 bit less than tests.' 16 | end if 17 | end program example_lt 18 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_none.f90: -------------------------------------------------------------------------------- 1 | program example_none 2 | use stdlib_bitsets 3 | implicit none 4 | character(*), parameter :: & 5 | bits_0 = '0000000000000000000' 6 | type(bitset_large) :: set0 7 | call set0%from_string(bits_0) 8 | if (set0%none()) then 9 | write (*, *) "FROM_STRING interpreted "// & 10 | "BITS_0's value properly." 11 | end if 12 | call set0%set(5) 13 | if (.not. set0%none()) then 14 | write (*, *) "NONE interpreted SET0's value properly." 15 | end if 16 | end program example_none 17 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_not.f90: -------------------------------------------------------------------------------- 1 | program example_not 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0 5 | call set0%init(155) 6 | if (set0%none()) then 7 | write (*, *) "FROM_STRING interpreted "// & 8 | "BITS_0's value properly." 9 | end if 10 | call set0%not() 11 | if (set0%all()) then 12 | write (*, *) "ALL interpreted SET0's value properly." 13 | end if 14 | end program example_not 15 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_or.f90: -------------------------------------------------------------------------------- 1 | program example_or 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0, set1 5 | call set0%init(166) 6 | call set1%init(166) 7 | call or(set0, set1) ! none none 8 | if (set0%none()) write (*, *) 'First test of OR worked.' 9 | call set0%not() 10 | call or(set0, set1) ! all none 11 | if (set0%all()) write (*, *) 'Second test of OR worked.' 12 | call set0%not() 13 | call set1%not() 14 | call or(set0, set1) ! none all 15 | if (set0%all()) write (*, *) 'Third test of OR worked.' 16 | call set0%not() 17 | call or(set0, set1) ! all all 18 | if (set0%all()) write (*, *) 'Fourth test of OR worked.' 19 | end program example_or 20 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_output.f90: -------------------------------------------------------------------------------- 1 | program example_output 2 | use stdlib_bitsets 3 | implicit none 4 | character(*), parameter :: & 5 | bits_0 = '000000000000000000000000000000000', & 6 | bits_1 = '000000000000000000000000000000001', & 7 | bits_33 = '100000000000000000000000000000000' 8 | integer :: unit 9 | type(bitset_64) :: set0, set1, set2, set3, set4, set5 10 | call set0%from_string(bits_0) 11 | call set1%from_string(bits_1) 12 | call set2%from_string(bits_33) 13 | open (newunit=unit, file='test.bin', status='replace', & 14 | form='unformatted', action='write') 15 | call set2%output(unit) 16 | call set1%output(unit) 17 | call set0%output(unit) 18 | close (unit) 19 | open (newunit=unit, file='test.bin', status='old', & 20 | form='unformatted', action='read') 21 | call set5%input(unit) 22 | call set4%input(unit) 23 | call set3%input(unit) 24 | close (unit) 25 | if (set3 /= set0 .or. set4 /= set1 .or. set5 /= set2) then 26 | error stop 'Transfer to and from units using '// & 27 | ' output and input failed.' 28 | else 29 | write (*, *) 'Transfer to and from units using '// & 30 | 'output and input succeeded.' 31 | end if 32 | end program example_output 33 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_set.f90: -------------------------------------------------------------------------------- 1 | program example_set 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0 5 | call set0%init(166) 6 | if (set0%none()) write (*, *) 'SET0 is properly initialized.' 7 | call set0%set(165) 8 | if (set0%test(165)) write (*, *) 'Bit 165 is set.' 9 | call set0%set(0, 164) 10 | if (set0%all()) write (*, *) 'All bits are set.' 11 | end program example_set 12 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_test.f90: -------------------------------------------------------------------------------- 1 | program example_test 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0 5 | call set0%init(166) 6 | call set0%not() 7 | if (set0%all()) write (*, *) 'SET0 is properly initialized.' 8 | call set0%clear(165) 9 | if (.not. set0%test(165)) write (*, *) 'Bit 165 is cleared.' 10 | call set0%set(165) 11 | if (set0%test(165)) write (*, *) 'Bit 165 is set.' 12 | end program example_test 13 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_to_string.f90: -------------------------------------------------------------------------------- 1 | program example_to_string 2 | use stdlib_bitsets 3 | implicit none 4 | character(*), parameter :: & 5 | bits_all = '111111111111111111111111111111111' 6 | type(bitset_64) :: set0 7 | character(:), allocatable :: new_string 8 | call set0%init(33) 9 | call set0%not() 10 | call set0%to_string(new_string) 11 | if (new_string == bits_all) then 12 | write (*, *) "TO_STRING transferred BITS0 properly"// & 13 | " into NEW_STRING." 14 | end if 15 | end program example_to_string 16 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_value.f90: -------------------------------------------------------------------------------- 1 | program example_value 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0 5 | call set0%init(166) 6 | call set0%not() 7 | if (set0%all()) write (*, *) 'SET0 is properly initialized.' 8 | call set0%clear(165) 9 | if (set0%value(165) == 0) write (*, *) 'Bit 165 is cleared.' 10 | call set0%set(165) 11 | if (set0%value(165) == 1) write (*, *) 'Bit 165 is set.' 12 | end program example_value 13 | -------------------------------------------------------------------------------- /example/bitsets/example_bitsets_xor.f90: -------------------------------------------------------------------------------- 1 | program example_xor 2 | use stdlib_bitsets 3 | implicit none 4 | type(bitset_large) :: set0, set1 5 | call set0%init(166) 6 | call set1%init(166) 7 | call xor(set0, set1) ! none none 8 | if (set0%none()) write (*, *) 'First test of XOR worked.' 9 | call set0%not() 10 | call xor(set0, set1) ! all none 11 | if (set0%all()) write (*, *) 'Second test of XOR worked.' 12 | call set0%not() 13 | call set1%not() 14 | call xor(set0, set1) ! none all 15 | if (set0%all()) write (*, *) 'Third test of XOR worked.' 16 | call set0%not() 17 | call xor(set0, set1) ! all all 18 | if (set0%none()) write (*, *) 'Fourth test of XOR worked.' 19 | end program example_xor 20 | -------------------------------------------------------------------------------- /example/constants/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(constants) 2 | -------------------------------------------------------------------------------- /example/constants/example_constants.f90: -------------------------------------------------------------------------------- 1 | program example_constants 2 | use stdlib_constants, only: c, pi=>PI_dp 3 | use stdlib_codata, only: alpha=>ALPHA_PARTICLE_ELECTRON_MASS_RATIO 4 | use stdlib_codata_type, only : to_real 5 | use stdlib_kinds, only: dp, sp 6 | 7 | ! Use most common physical constants defined as double precision reals 8 | print *, "speed of light in vacuum= ", c 9 | 10 | ! Use of mathematical constants such as PI 11 | print *, "PI as double precision real= ", pi 12 | 13 | ! Use codata_constant type for evaluating the value to the desired precision 14 | print *, "Value of alpha... evaluated to double precision=", alpha%to_real(1.0_dp) 15 | print *, "Uncertainty of alpha... evaluated to double precision=", alpha%to_real(1.0_sp, .true.) 16 | print *, "Value of alpha... evaluated to single precision=", alpha%to_real(1.0_sp) 17 | 18 | ! Convert a codata constant to a real 19 | print *, "Value of the alpha... evaluated to double precision=", to_real(alpha, 1.0_dp) 20 | 21 | 22 | ! Print out codata constant attributes: name, value, uncertainty and unit 23 | call alpha%print() 24 | 25 | end program example_constants 26 | -------------------------------------------------------------------------------- /example/error/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(check1) 2 | set_tests_properties(check1 PROPERTIES WILL_FAIL true) 3 | ADD_EXAMPLE(check2) 4 | set_tests_properties(check2 PROPERTIES WILL_FAIL true) 5 | ADD_EXAMPLE(check3) 6 | ADD_EXAMPLE(check4) 7 | set_tests_properties(check4 PROPERTIES SKIP_RETURN_CODE 77) 8 | ADD_EXAMPLE(error_stop1) 9 | set_tests_properties(error_stop1 PROPERTIES WILL_FAIL true) 10 | ADD_EXAMPLE(error_stop2) 11 | set_tests_properties(error_stop2 PROPERTIES WILL_FAIL true) 12 | ADD_EXAMPLE(error_state1) 13 | ADD_EXAMPLE(error_state2) 14 | -------------------------------------------------------------------------------- /example/error/example_check1.f90: -------------------------------------------------------------------------------- 1 | program example_check1 2 | use stdlib_error, only: check 3 | implicit none 4 | integer :: a = 1 5 | ! If a /= 5, stops the program with exit code 1 and prints 'Check failed.' 6 | call check(a == 5) 7 | end program example_check1 8 | -------------------------------------------------------------------------------- /example/error/example_check2.f90: -------------------------------------------------------------------------------- 1 | program example_check2 2 | use stdlib_error, only: check 3 | implicit none 4 | integer :: a = 1 5 | ! If a /= 5, stops the program with exit code 1 and prints 'a == 5 failed.' 6 | call check(a == 5, msg='a == 5 failed.') 7 | end program example_check2 8 | -------------------------------------------------------------------------------- /example/error/example_check3.f90: -------------------------------------------------------------------------------- 1 | program example_check3 2 | use stdlib_error, only: check 3 | implicit none 4 | integer :: a = 1 5 | ! If a /= 5, prints 'a == 5 failed.', but doesn't stop the program. 6 | call check(a == 5, msg='a == 5 failed.', warn=.true.) 7 | end program example_check3 8 | -------------------------------------------------------------------------------- /example/error/example_check4.f90: -------------------------------------------------------------------------------- 1 | program example_check4 2 | use stdlib_error, only: check 3 | implicit none 4 | integer :: a = 1 5 | ! If a /= 5, stops the program with exit code 77 and prints 'a == 5 failed.' 6 | call check(a == 5, msg='a == 5 failed.', code=77) 7 | end program example_check4 8 | -------------------------------------------------------------------------------- /example/error/example_error_state1.f90: -------------------------------------------------------------------------------- 1 | program example_error_state1 2 | use stdlib_error, only: state_type, STDLIB_VALUE_ERROR, STDLIB_SUCCESS, operator(/=) 3 | implicit none 4 | type(state_type) :: err 5 | 6 | ! To create a state variable, we enter its integer state flag, followed by a list of variables 7 | ! that will be automatically assembled into a formatted error message. No need to provide string formats 8 | err = state_type(STDLIB_VALUE_ERROR,'just an example with scalar ',& 9 | 'integer=',1,'real=',2.0,'complex=',(3.0,1.0),'and array ',[1,2,3],'inputs') 10 | 11 | ! Print flag 12 | print *, err%print() 13 | 14 | ! Check success 15 | print *, 'Check error: ',err%error() 16 | print *, 'Check flag : ',err /= STDLIB_SUCCESS 17 | 18 | end program example_error_state1 19 | -------------------------------------------------------------------------------- /example/error/example_error_stop1.f90: -------------------------------------------------------------------------------- 1 | program example_error_stop1 2 | use stdlib_error, only: error_stop 3 | implicit none 4 | call error_stop("Invalid argument") 5 | end program example_error_stop1 6 | -------------------------------------------------------------------------------- /example/error/example_error_stop2.f90: -------------------------------------------------------------------------------- 1 | program example_error_stop2 2 | use stdlib_error, only: error_stop 3 | implicit none 4 | call error_stop("Invalid argument", code=123) 5 | end program example_error_stop2 6 | -------------------------------------------------------------------------------- /example/hash_procedures/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(fibonacci_hash_64) 2 | ADD_EXAMPLE(fibonacci_hash) 3 | ADD_EXAMPLE(fnv_1a_hash_64) 4 | ADD_EXAMPLE(fnv_1a_hash) 5 | ADD_EXAMPLE(fnv_1_hash_64) 6 | ADD_EXAMPLE(fnv_1_hash) 7 | ADD_EXAMPLE(nmhash32) 8 | ADD_EXAMPLE(nmhash32x) 9 | ADD_EXAMPLE(pengy_hash) 10 | ADD_EXAMPLE(spooky_hash) 11 | ADD_EXAMPLE(universal_mult_hash_64) 12 | ADD_EXAMPLE(universal_mult_hash) 13 | ADD_EXAMPLE(water_hash) 14 | -------------------------------------------------------------------------------- /example/hash_procedures/example_fibonacci_hash.f90: -------------------------------------------------------------------------------- 1 | program example_fibonacci_hash 2 | use stdlib_hash_32bit, only: fibonacci_hash 3 | use iso_fortran_env, only: int32 4 | implicit none 5 | integer, allocatable :: array1(:) 6 | integer(int32) :: hash, source 7 | allocate (array1(0:2**6 - 1)) 8 | array1(:) = 0 9 | source = 42_int32 10 | hash = fibonacci_hash(source, 6) 11 | array1(hash) = source 12 | print *, hash 13 | end program example_fibonacci_hash 14 | -------------------------------------------------------------------------------- /example/hash_procedures/example_fibonacci_hash_64.f90: -------------------------------------------------------------------------------- 1 | program example_fibonacci_hash_64 2 | use stdlib_hash_64bit, only: fibonacci_hash 3 | use iso_fortran_env, only: int64 4 | implicit none 5 | integer, allocatable :: array1(:) 6 | integer(int64) :: hash, source 7 | allocate (array1(0:2**6 - 1)) 8 | array1(:) = 0 9 | source = int(Z'1FFFFFFFF', int64) 10 | hash = fibonacci_hash(source, 6) 11 | array1(hash) = source 12 | print *, hash 13 | end program example_fibonacci_hash_64 14 | -------------------------------------------------------------------------------- /example/hash_procedures/example_fnv_1_hash.f90: -------------------------------------------------------------------------------- 1 | program example_fnv_1_hash 2 | use stdlib_hash_32bit, only: fnv_1_hash 3 | use iso_fortran_env, only: int32 4 | implicit none 5 | integer(int32) :: hash 6 | hash = fnv_1_hash([5, 4, 3, 1, 10, 4, 9]) 7 | print *, hash 8 | end program example_fnv_1_hash 9 | -------------------------------------------------------------------------------- /example/hash_procedures/example_fnv_1_hash_64.f90: -------------------------------------------------------------------------------- 1 | program example_fnv_1_hash_64 2 | use stdlib_hash_64bit, only: fnv_1_hash 3 | use iso_fortran_env, only: int64 4 | implicit none 5 | integer, allocatable :: array1(:) 6 | integer(int64) :: hash 7 | array1 = [5, 4, 3, 1, 10, 4, 9] 8 | hash = fnv_1_hash(array1) 9 | print *, hash 10 | end program example_fnv_1_hash_64 11 | -------------------------------------------------------------------------------- /example/hash_procedures/example_fnv_1a_hash.f90: -------------------------------------------------------------------------------- 1 | program example_fnv_1a_hash 2 | use stdlib_hash_32bit, only: fnv_1a_hash 3 | use iso_fortran_env, only: int32 4 | implicit none 5 | integer(int32) :: hash 6 | hash = fnv_1a_hash([5, 4, 3, 1, 10, 4, 9]) 7 | print *, hash 8 | end program example_fnv_1a_hash 9 | -------------------------------------------------------------------------------- /example/hash_procedures/example_fnv_1a_hash_64.f90: -------------------------------------------------------------------------------- 1 | program example_fnv_1a_hash_64 2 | use stdlib_hash_64bit, only: fnv_1a_hash 3 | use iso_fortran_env, only: int64 4 | implicit none 5 | integer, allocatable :: array1(:) 6 | integer(int64) :: hash 7 | array1 = [5, 4, 3, 1, 10, 4, 9] 8 | hash = fnv_1a_hash(array1) 9 | print *, hash 10 | end program example_fnv_1a_hash_64 11 | -------------------------------------------------------------------------------- /example/hash_procedures/example_nmhash32.f90: -------------------------------------------------------------------------------- 1 | program example_nmhash32 2 | use stdlib_hash_32bit, only: nmhash32, & 3 | new_nmhash32_seed 4 | use iso_fortran_env, only: int32 5 | implicit none 6 | integer(int32) :: hash 7 | integer(int32) :: seed = 42_int32 8 | call new_nmhash32_seed(seed) 9 | hash = nmhash32([5, 4, 3, 1, 10, 4, 9], seed) 10 | print *, seed, hash 11 | end program example_nmhash32 12 | -------------------------------------------------------------------------------- /example/hash_procedures/example_nmhash32x.f90: -------------------------------------------------------------------------------- 1 | program example_nmhash32x 2 | use stdlib_hash_32bit, only: nmhash32x, & 3 | new_nmhash32x_seed 4 | use iso_fortran_env, only: int32 5 | implicit none 6 | integer(int32) :: hash 7 | integer(int32) :: seed = 42_int32 8 | call new_nmhash32x_seed(seed) 9 | hash = nmhash32x([5, 4, 3, 1, 10, 4, 9], seed) 10 | print *, seed, hash 11 | end program example_nmhash32x 12 | -------------------------------------------------------------------------------- /example/hash_procedures/example_pengy_hash.f90: -------------------------------------------------------------------------------- 1 | program example_pengy_hash 2 | use stdlib_hash_64bit, only: new_pengy_hash_seed, pengy_hash 3 | use iso_fortran_env, only: int32, int64 4 | implicit none 5 | integer, allocatable :: key(:) 6 | integer(int64) :: hash 7 | integer(int32) :: seed 8 | key = [0, 1, 2, 3] 9 | seed = 0_int32 10 | call new_pengy_hash_seed(seed) 11 | hash = pengy_hash(key, seed) 12 | print *, seed, hash 13 | end program example_pengy_hash 14 | -------------------------------------------------------------------------------- /example/hash_procedures/example_spooky_hash.f90: -------------------------------------------------------------------------------- 1 | program example_spooky_hash 2 | use stdlib_hash_64bit, only: new_spooky_hash_seed, & 3 | spooky_hash 4 | use iso_fortran_env, only: int64 5 | implicit none 6 | integer, allocatable :: key(:) 7 | integer(int64) :: hash(2), seed(2) 8 | key = [0, 1, 2, 3] 9 | seed = [119_int64, 2_int64**41 - 1] 10 | call new_spooky_hash_seed(seed) 11 | hash = spooky_hash(key, seed) 12 | print *, seed, hash 13 | end program example_spooky_hash 14 | -------------------------------------------------------------------------------- /example/hash_procedures/example_universal_mult_hash.f90: -------------------------------------------------------------------------------- 1 | program example_universal_mult_hash 2 | use stdlib_hash_32bit, only: odd_random_integer, & 3 | universal_mult_hash 4 | use iso_fortran_env, only: int32 5 | implicit none 6 | integer, allocatable :: array1(:) 7 | integer(int32) :: hash, i, seed, source 8 | seed = 0 9 | allocate (array1(0:2**6 - 1)) 10 | do i = 0, 2**6 - 1 11 | array1(i) = i 12 | end do 13 | call odd_random_integer(seed) 14 | source = 42_int32 15 | hash = universal_mult_hash(source, seed, 6) 16 | array1(hash) = source 17 | print *, seed, hash, array1 18 | end program example_universal_mult_hash 19 | -------------------------------------------------------------------------------- /example/hash_procedures/example_universal_mult_hash_64.f90: -------------------------------------------------------------------------------- 1 | program example_universal_mult_hash_64 2 | use stdlib_hash_64bit, only: odd_random_integer, & 3 | universal_mult_hash 4 | use iso_fortran_env, only: int64 5 | implicit none 6 | integer, allocatable :: array1(:) 7 | integer(int64) :: hash, seed, source 8 | seed = 0 9 | allocate (array1(0:2**6 - 1)) 10 | array1 = 0 11 | call odd_random_integer(seed) 12 | source = 42_int64 13 | hash = universal_mult_hash(source, seed, 6) 14 | array1(hash) = source 15 | print *, seed, hash, array1 16 | end program example_universal_mult_hash_64 17 | -------------------------------------------------------------------------------- /example/hash_procedures/example_water_hash.f90: -------------------------------------------------------------------------------- 1 | program example_water_hash 2 | use stdlib_hash_32bit, only: water_hash, & 3 | new_water_hash_seed 4 | use iso_fortran_env, only: int32, int64 5 | implicit none 6 | integer(int32) :: hash 7 | integer(int64) :: seed = 42_int64 8 | call new_water_hash_seed(seed) 9 | hash = water_hash([5, 4, 3, 1, 10, 4, 9], seed) 10 | print *, hash, seed 11 | end program example_water_hash 12 | -------------------------------------------------------------------------------- /example/hashmaps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(hashmaps_calls) 2 | ADD_EXAMPLE(hashmaps_copy_key) 3 | ADD_EXAMPLE(hashmaps_entries) 4 | ADD_EXAMPLE(hashmaps_equal_keys) 5 | ADD_EXAMPLE(hashmaps_fnv_1a_hasher) 6 | ADD_EXAMPLE(hashmaps_fnv_1_hasher) 7 | ADD_EXAMPLE(hashmaps_free_key) 8 | ADD_EXAMPLE(hashmaps_get) 9 | ADD_EXAMPLE(hashmaps_get_all_keys) 10 | ADD_EXAMPLE(hashmaps_get_other_data) 11 | ADD_EXAMPLE(hashmaps_hasher_fun) 12 | ADD_EXAMPLE(hashmaps_init) 13 | ADD_EXAMPLE(hashmaps_key_test) 14 | ADD_EXAMPLE(hashmaps_loading) 15 | ADD_EXAMPLE(hashmaps_map_entry) 16 | ADD_EXAMPLE(hashmaps_num_slots) 17 | ADD_EXAMPLE(hashmaps_probes) 18 | ADD_EXAMPLE(hashmaps_rehash) 19 | ADD_EXAMPLE(hashmaps_remove) 20 | ADD_EXAMPLE(hashmaps_seeded_nmhash32_hasher) 21 | ADD_EXAMPLE(hashmaps_seeded_nmhash32x_hasher) 22 | ADD_EXAMPLE(hashmaps_seeded_water_hasher) 23 | ADD_EXAMPLE(hashmaps_set) 24 | ADD_EXAMPLE(hashmaps_set_other_data) 25 | ADD_EXAMPLE(hashmaps_slots_bits) 26 | ADD_EXAMPLE(hashmaps_total_depth) 27 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_calls.f90: -------------------------------------------------------------------------------- 1 | program example_calls 2 | use stdlib_hashmaps, only: chaining_hashmap_type, int_calls 3 | implicit none 4 | type(chaining_hashmap_type) :: map 5 | integer(int_calls) :: initial_calls 6 | call map%init() 7 | initial_calls = map%calls() 8 | print *, "INITIAL_CALLS = ", initial_calls 9 | end program example_calls 10 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_copy_key.f90: -------------------------------------------------------------------------------- 1 | program example_copy_key 2 | use stdlib_hashmap_wrappers, only: & 3 | copy_key, operator(==), key_type, set 4 | use iso_fortran_env, only: int8 5 | implicit none 6 | integer(int8) :: i, value(15) 7 | type(key_type) :: old_key, new_key 8 | value = [(i, i=1, 15)] 9 | call set(old_key, value) 10 | call copy_key(old_key, new_key) 11 | print *, "old_key == new_key = ", old_key == new_key 12 | end program example_copy_key 13 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_entries.f90: -------------------------------------------------------------------------------- 1 | program example_entries 2 | use stdlib_hashmaps, only: open_hashmap_type, int_index 3 | implicit none 4 | type(open_hashmap_type) :: map 5 | integer(int_index) :: initial_entries 6 | call map%init() 7 | initial_entries = map%entries() 8 | print *, "INITIAL_ENTRIES = ", initial_entries 9 | end program example_entries 10 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_equal_keys.f90: -------------------------------------------------------------------------------- 1 | program example_equal_keys 2 | use stdlib_hashmap_wrappers, only: & 3 | copy_key, operator(==), key_type, set 4 | use iso_fortran_env, only: int8 5 | implicit none 6 | integer(int8) :: i, value(15) 7 | type(key_type) :: old_key, new_key 8 | do i = 1, 15 9 | value(i) = i 10 | end do 11 | call set(old_key, value) 12 | call copy_key(old_key, new_key) 13 | print *, "old_key == new_key = ", old_key == new_key 14 | end program example_equal_keys 15 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_fnv_1_hasher.f90: -------------------------------------------------------------------------------- 1 | program example_fnv_1_hasher 2 | use stdlib_hashmap_wrappers, only: fnv_1_hasher, key_type, set 3 | use iso_fortran_env, only: int8, int32 4 | implicit none 5 | integer(int8), allocatable :: array1(:) 6 | integer(int32) :: hash 7 | type(key_type) :: key 8 | array1 = [5_int8, 4_int8, 3_int8, 1_int8, 10_int8, 4_int8] 9 | call set(key, array1) 10 | hash = fnv_1_hasher(key) 11 | print *, hash 12 | end program example_fnv_1_hasher 13 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_fnv_1a_hasher.f90: -------------------------------------------------------------------------------- 1 | program example_fnv_1a_hasher 2 | use stdlib_hashmap_wrappers, only: & 3 | fnv_1a_hasher, key_type, set 4 | use iso_fortran_env, only: int8, int32 5 | implicit none 6 | integer(int8), allocatable :: array1(:) 7 | integer(int32) :: hash 8 | type(key_type) :: key 9 | array1 = [5_int8, 4_int8, 3_int8, 1_int8, 10_int8, 4_int8] 10 | call set(key, array1) 11 | hash = fnv_1a_hasher(key) 12 | print *, hash 13 | end program example_fnv_1a_hasher 14 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_free_key.f90: -------------------------------------------------------------------------------- 1 | program example_free_key 2 | use stdlib_hashmap_wrappers, only: & 3 | copy_key, free_key, key_type, set 4 | use iso_fortran_env, only: int8 5 | implicit none 6 | integer(int8) :: i, value(15) 7 | type(key_type) :: old_key, new_key 8 | value = [(i, i=1, 15)] 9 | call set(old_key, value) 10 | call copy_key(old_key, new_key) 11 | call free_key(old_key) 12 | end program example_free_key 13 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_get.f90: -------------------------------------------------------------------------------- 1 | program example_get 2 | use stdlib_hashmap_wrappers, only: & 3 | get, key_type, set 4 | use iso_fortran_env, only: int8 5 | implicit none 6 | integer(int8), allocatable :: value(:), result(:) 7 | type(key_type) :: key 8 | integer(int8) :: i 9 | allocate (value(1:15)) 10 | do i = 1, 15 11 | value(i) = i 12 | end do 13 | call set(key, value) 14 | call get(key, result) 15 | print *, 'RESULT == VALUE = ', all(value == result) 16 | end program example_get 17 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_get_all_keys.f90: -------------------------------------------------------------------------------- 1 | program example_hashmaps_get_all_keys 2 | use stdlib_kinds, only: int32 3 | use stdlib_hashmaps, only: chaining_hashmap_type 4 | use stdlib_hashmap_wrappers, only: get, key_type, set 5 | implicit none 6 | type(chaining_hashmap_type) :: map 7 | type(key_type) :: key 8 | 9 | type(key_type), allocatable :: keys(:) 10 | integer(int32) :: i 11 | 12 | character(:), allocatable :: str 13 | 14 | ! adding key-value pairs to the map 15 | call set(key, "initial key") 16 | call map%map_entry(key, "value 1") 17 | 18 | call set(key, "second key") 19 | call map%map_entry(key, "value 2") 20 | 21 | call set(key, "last key") 22 | call map%map_entry(key, "value 3") 23 | 24 | ! getting all the keys in the map 25 | call map%get_all_keys(keys) 26 | 27 | print '("Number of keys in the hashmap = ", I0)', size(keys) 28 | !Number of keys in the hashmap = 3 29 | 30 | do i = 1, size(keys) 31 | call get( keys(i), str ) 32 | print '("Value of key ", I0, " = ", A)', i, str 33 | end do 34 | !Value of key 1 = initial key 35 | !Value of key 2 = second key 36 | !Value of key 3 = last key 37 | 38 | end program example_hashmaps_get_all_keys 39 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_hasher_fun.f90: -------------------------------------------------------------------------------- 1 | program example_hasher_fun 2 | use stdlib_hashmap_wrappers, only: fnv_1a_hasher, hasher_fun, set, key_type 3 | use stdlib_kinds, only: int8, int32 4 | implicit none 5 | procedure(hasher_fun), pointer :: hasher_pointer 6 | integer(int8), allocatable :: array1(:) 7 | integer(int32) :: hash 8 | type(key_type) :: key 9 | hasher_pointer => fnv_1a_hasher 10 | array1 = [5_int8, 4_int8, 3_int8, 1_int8, 10_int8, 4_int8] 11 | call set(key, array1) 12 | hash = hasher_pointer(key) 13 | print *, hash 14 | end program example_hasher_fun 15 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_key_test.f90: -------------------------------------------------------------------------------- 1 | program example_key_test 2 | use stdlib_kinds, only: int8 3 | use stdlib_hashmaps, only: chaining_hashmap_type 4 | use stdlib_hashmap_wrappers, only: key_type, set 5 | implicit none 6 | type(chaining_hashmap_type) :: map 7 | type(key_type) :: key 8 | logical :: present 9 | 10 | call map%init() 11 | call set(key, [0_int8, 1_int8]) 12 | call map%key_test(key, present) 13 | print *, "Initial key of 10 present for empty map = ", present 14 | 15 | end program example_key_test 16 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_loading.f90: -------------------------------------------------------------------------------- 1 | program example_loading 2 | use stdlib_hashmaps, only: open_hashmap_type 3 | implicit none 4 | type(open_hashmap_type) :: map 5 | real :: ratio 6 | call map%init() 7 | ratio = map%loading() 8 | print *, "Initial loading = ", ratio 9 | end program example_loading 10 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_num_slots.f90: -------------------------------------------------------------------------------- 1 | program example_num_slots 2 | use stdlib_hashmaps, only: chaining_hashmap_type, int_index 3 | implicit none 4 | type(chaining_hashmap_type) :: map 5 | integer(int_index) :: initial_slots 6 | call map%init() 7 | initial_slots = map%num_slots() 8 | print *, "Initial slots = ", initial_slots 9 | end program example_num_slots 10 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_probes.f90: -------------------------------------------------------------------------------- 1 | program example_probes 2 | use stdlib_hashmaps, only: chaining_hashmap_type 3 | implicit none 4 | type(chaining_hashmap_type) :: map 5 | integer :: nprobes 6 | call map%init() 7 | nprobes = map%map_probes() 8 | print *, "Initial probes = ", nprobes 9 | end program example_probes 10 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_rehash.f90: -------------------------------------------------------------------------------- 1 | program example_rehash 2 | use stdlib_kinds, only: int8 3 | use stdlib_hashmaps, only: open_hashmap_type 4 | use stdlib_hashmap_wrappers, only: fnv_1a_hasher, & 5 | key_type, set 6 | implicit none 7 | type(open_hashmap_type) :: map 8 | type(key_type) :: key 9 | call map%init(slots_bits=10) 10 | call set(key, [5_int8, 7_int8, 4_int8, 13_int8]) 11 | call map%map_entry(key, 'A value') 12 | call map%rehash(fnv_1a_hasher) 13 | end program example_rehash 14 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_seeded_nmhash32_hasher.f90: -------------------------------------------------------------------------------- 1 | program example_seeded_nmhash32_hasher 2 | use stdlib_hashmap_wrappers, only: & 3 | seeded_nmhash32_hasher, key_type, set 4 | use iso_fortran_env, only: int8, int32 5 | implicit none 6 | integer(int8), allocatable :: array1(:) 7 | integer(int32) :: hash 8 | type(key_type) :: key 9 | array1 = [5_int8, 4_int8, 3_int8, 1_int8, 10_int8, 4_int8] 10 | call set(key, array1) 11 | hash = seeded_nmhash32_hasher(key) 12 | print *, hash 13 | end program example_seeded_nmhash32_hasher 14 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_seeded_nmhash32x_hasher.f90: -------------------------------------------------------------------------------- 1 | program example_seeded_nmhash32x_hasher 2 | use stdlib_kinds, only: int8, int32 3 | use stdlib_hashmap_wrappers, only: & 4 | seeded_nmhash32x_hasher, key_type, set 5 | implicit none 6 | integer(int8), allocatable :: array1(:) 7 | integer(int32) :: hash 8 | type(key_type) :: key 9 | array1 = [5_int8, 4_int8, 3_int8, 1_int8, 10_int8, 4_int8] 10 | call set(key, array1) 11 | hash = seeded_nmhash32x_hasher(key) 12 | print *, hash 13 | end program example_seeded_nmhash32x_hasher 14 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_seeded_water_hasher.f90: -------------------------------------------------------------------------------- 1 | program example_seeded_water_hasher 2 | use stdlib_hashmap_wrappers, only: & 3 | seeded_water_hasher, key_type, set 4 | use iso_fortran_env, only: int8, int32 5 | implicit none 6 | integer(int8), allocatable :: array1(:) 7 | integer(int32) :: hash 8 | type(key_type) :: key 9 | array1 = [5_int8, 4_int8, 3_int8, 1_int8, 10_int8, 4_int8] 10 | call set(key, array1) 11 | hash = seeded_water_hasher(key) 12 | print *, hash 13 | end program example_seeded_water_hasher 14 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_set.f90: -------------------------------------------------------------------------------- 1 | program example_set 2 | use stdlib_hashmap_wrappers, only: & 3 | get, key_type, set 4 | use iso_fortran_env, only: int8 5 | implicit none 6 | integer(int8), allocatable :: value(:), result(:) 7 | type(key_type) :: key 8 | integer(int8) :: i 9 | allocate (value(1:15)) 10 | do i = 1, 15 11 | value(i) = i 12 | end do 13 | call set(key, value) 14 | call get(key, result) 15 | print *, 'RESULT == VALUE = ', all(value == result) 16 | end program example_set 17 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_slots_bits.f90: -------------------------------------------------------------------------------- 1 | program example_slots_bits 2 | use stdlib_hashmaps, only: chaining_hashmap_type 3 | implicit none 4 | type(chaining_hashmap_type) :: map 5 | integer :: bits 6 | call map%init() 7 | bits = map%slots_bits() 8 | print *, "Initial slot bits = ", bits 9 | end program example_slots_bits 10 | -------------------------------------------------------------------------------- /example/hashmaps/example_hashmaps_total_depth.f90: -------------------------------------------------------------------------------- 1 | program example_total_depth 2 | use stdlib_hashmaps, only: chaining_hashmap_type, int_depth 3 | implicit none 4 | type(chaining_hashmap_type) :: map 5 | integer(int_depth) :: initial_depth 6 | call map%init() 7 | initial_depth = map%total_depth() 8 | print *, "Initial total depth = ", initial_depth 9 | end program example_total_depth 10 | -------------------------------------------------------------------------------- /example/intrinsics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(sum) 2 | ADD_EXAMPLE(dot_product) -------------------------------------------------------------------------------- /example/intrinsics/example_dot_product.f90: -------------------------------------------------------------------------------- 1 | program example_dot_product 2 | use stdlib_kinds, only: sp 3 | use stdlib_intrinsics, only: stdlib_dot_product, stdlib_dot_product_kahan 4 | implicit none 5 | 6 | real(sp), allocatable :: x(:), y(:) 7 | real(sp) :: total_prod(3) 8 | 9 | allocate( x(1000), y(1000) ) 10 | call random_number(x) 11 | call random_number(y) 12 | 13 | total_prod(1) = dot_product(x,y) !> compiler intrinsic 14 | total_prod(2) = stdlib_dot_product(x,y) !> chunked summation over inner product 15 | total_prod(3) = stdlib_dot_product_kahan(x,y) !> chunked kahan summation over inner product 16 | print *, total_prod(1:3) 17 | 18 | end program example_dot_product -------------------------------------------------------------------------------- /example/intrinsics/example_sum.f90: -------------------------------------------------------------------------------- 1 | program example_sum 2 | use stdlib_kinds, only: sp 3 | use stdlib_intrinsics, only: stdlib_sum, stdlib_sum_kahan 4 | implicit none 5 | 6 | real(sp), allocatable :: x(:) 7 | real(sp) :: total_sum(3) 8 | 9 | allocate( x(1000) ) 10 | call random_number(x) 11 | 12 | total_sum(1) = sum(x) !> compiler intrinsic 13 | total_sum(2) = stdlib_sum(x) !> chunked summation 14 | total_sum(3) = stdlib_sum_kahan(x)!> chunked kahan summation 15 | print *, total_sum(1:3) 16 | 17 | end program example_sum -------------------------------------------------------------------------------- /example/io/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(fmt_constants) 2 | #ADD_EXAMPLE(get_line) 3 | ADD_EXAMPLE(get_file) 4 | ADD_EXAMPLE(loadnpy) 5 | ADD_EXAMPLE(loadtxt) 6 | ADD_EXAMPLE(open) 7 | ADD_EXAMPLE(savenpy) 8 | ADD_EXAMPLE(savetxt) 9 | -------------------------------------------------------------------------------- /example/io/example.csv: -------------------------------------------------------------------------------- 1 | 1.00000000E+00, 1.00000000E+00 2 | 1.00000000E+00, 1.00000000E+00 3 | 1.00000000E+00, 1.00000000E+00 4 | -------------------------------------------------------------------------------- /example/io/example.dat: -------------------------------------------------------------------------------- 1 | 1.00000000E+00 1.00000000E+00 2 | 1.00000000E+00 1.00000000E+00 3 | 1.00000000E+00 1.00000000E+00 4 | -------------------------------------------------------------------------------- /example/io/example.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fortran-lang/stdlib/30ccd9d46496126a24f240ccfa6f9f9c762219a5/example/io/example.npy -------------------------------------------------------------------------------- /example/io/example_fmt_constants.f90: -------------------------------------------------------------------------------- 1 | program example_fmt_constants 2 | use stdlib_kinds, only: int32, int64, sp, dp 3 | use stdlib_io, only: FMT_INT, FMT_REAL_SP, FMT_REAL_DP, FMT_COMPLEX_SP, FMT_COMPLEX_DP 4 | implicit none 5 | 6 | integer(kind=int32) :: i32 7 | integer(kind=int64) :: i64 8 | real(kind=sp) :: r32 9 | real(kind=dp) :: r64 10 | complex(kind=sp) :: c32 11 | complex(kind=dp) :: c64 12 | 13 | i32 = 100_int32 14 | i64 = 100_int64 15 | r32 = 100.0_sp 16 | r64 = 100.0_dp 17 | c32 = cmplx(100.0_sp, kind=sp) 18 | c64 = cmplx(100.0_dp, kind=dp) 19 | 20 | print "(2("//FMT_INT//",1x))", i32, i64 ! outputs: 100 100 21 | print FMT_REAL_SP, r32 ! outputs: 1.00000000E+02 22 | print FMT_REAL_DP, r64 ! outputs: 1.0000000000000000E+002 23 | print FMT_COMPLEX_SP, c32 ! outputs: 1.00000000E+02 0.00000000E+00 24 | print FMT_COMPLEX_DP, c64 ! outputs: 1.0000000000000000E+002 0.0000000000000000E+000 25 | 26 | end program example_fmt_constants 27 | -------------------------------------------------------------------------------- /example/io/example_get_file.f90: -------------------------------------------------------------------------------- 1 | ! Demonstrate usage of `get_file` 2 | program example_get_file 3 | use stdlib_io, only: get_file 4 | use stdlib_string_type, only: string_type 5 | use stdlib_error, only: state_type 6 | implicit none 7 | 8 | character(*), parameter :: filename = "example.txt" 9 | type(string_type) :: filecontent 10 | type(state_type) :: err 11 | 12 | ! Read a file into a string 13 | call get_file(filename, filecontent, err=err) 14 | 15 | if (err%error()) then 16 | print *, err%print() 17 | else 18 | print *, "Success! File "//filename//" imported." 19 | end if 20 | end program example_get_file 21 | -------------------------------------------------------------------------------- /example/io/example_get_line.f90: -------------------------------------------------------------------------------- 1 | program example_getline 2 | use, intrinsic :: iso_fortran_env, only: input_unit, output_unit 3 | use stdlib_io, only: get_line 4 | implicit none 5 | character(len=:), allocatable :: line 6 | integer :: stat 7 | 8 | call get_line(input_unit, line, stat) 9 | do while (stat == 0) 10 | write (output_unit, '(a)') line 11 | call get_line(input_unit, line, stat) 12 | end do 13 | end program example_getline 14 | -------------------------------------------------------------------------------- /example/io/example_loadnpy.f90: -------------------------------------------------------------------------------- 1 | program example_loadnpy 2 | use stdlib_io_npy, only: load_npy 3 | implicit none 4 | real, allocatable :: x(:, :) 5 | call load_npy('example.npy', x) 6 | end program example_loadnpy 7 | -------------------------------------------------------------------------------- /example/io/example_loadtxt.f90: -------------------------------------------------------------------------------- 1 | program example_loadtxt 2 | use stdlib_io, only: loadtxt 3 | implicit none 4 | real, allocatable :: x(:, :) 5 | call loadtxt('example.dat', x) 6 | 7 | ! Can also use list directed format if the default read fails. 8 | call loadtxt('example.dat', x, fmt='*') 9 | 10 | call loadtxt('example.csv', x, delimiter=',') 11 | 12 | end program example_loadtxt 13 | -------------------------------------------------------------------------------- /example/io/example_open.f90: -------------------------------------------------------------------------------- 1 | program example_open 2 | use stdlib_io, only: open 3 | implicit none 4 | integer :: u 5 | u = open ('example.dat', 'wt') 6 | write (u, '(a)') 'This is an example for open' 7 | close (u) 8 | end program example_open 9 | -------------------------------------------------------------------------------- /example/io/example_savenpy.f90: -------------------------------------------------------------------------------- 1 | program example_savenpy 2 | use stdlib_io_npy, only: save_npy 3 | implicit none 4 | real :: x(3, 2) = 1 5 | call save_npy('example.npy', x) 6 | end program example_savenpy 7 | -------------------------------------------------------------------------------- /example/io/example_savetxt.f90: -------------------------------------------------------------------------------- 1 | program example_savetxt 2 | use stdlib_io, only: savetxt 3 | implicit none 4 | real :: x(3, 2) = 1 5 | call savetxt('example.dat', x) 6 | call savetxt('example.csv', x, delimiter=',') 7 | end program example_savetxt 8 | -------------------------------------------------------------------------------- /example/linalg/example_blas_gemv.f90: -------------------------------------------------------------------------------- 1 | program example_gemv 2 | use stdlib_linalg, only: eye 3 | use stdlib_linalg_blas, only: sp,gemv 4 | implicit none 5 | real(sp) :: A(2, 2), B(2), C(2) 6 | B = [1.0,2.0] 7 | A = eye(2) 8 | 9 | ! Use legacy BLAS interface 10 | call gemv('No transpose',m=size(A,1),n=size(A,2),alpha=1.0,a=A,lda=size(A,1),x=B,incx=1,beta=0.0,y=C,incy=1) 11 | 12 | print *, C ! returns 1.0 2.0 13 | 14 | end program example_gemv 15 | -------------------------------------------------------------------------------- /example/linalg/example_chol.f90: -------------------------------------------------------------------------------- 1 | ! Cholesky factorization: function interface 2 | program example_chol 3 | use stdlib_linalg, only: chol 4 | implicit none 5 | 6 | real, allocatable, dimension(:,:) :: A,L,U 7 | 8 | ! Set real matrix 9 | A = reshape( [ [6, 15, 55], & 10 | [15, 55, 225], & 11 | [55, 225, 979] ], [3,3] ) 12 | 13 | ! Decompose (lower) 14 | L = chol(A, lower=.true.) 15 | 16 | ! Compare decomposition 17 | print *, maxval(abs(A-matmul(L,transpose(L)))) 18 | 19 | ! Decompose (upper) 20 | U = chol(A, lower=.false.) 21 | 22 | ! Compare decomposition 23 | print *, maxval(abs(A-matmul(transpose(U),U))) 24 | 25 | end program example_chol 26 | -------------------------------------------------------------------------------- /example/linalg/example_cholesky.f90: -------------------------------------------------------------------------------- 1 | ! Cholesky factorization: subroutine interface 2 | program example_cholesky 3 | use stdlib_linalg, only: cholesky 4 | implicit none 5 | 6 | real, dimension(3,3) :: A,L,U 7 | 8 | ! Set real matrix 9 | A = reshape( [ [6, 15, 55], & 10 | [15, 55, 225], & 11 | [55, 225, 979] ], [3,3] ) 12 | 13 | ! Decompose (lower) 14 | call cholesky(A, L, lower=.true.) 15 | 16 | ! Compare decomposition 17 | print *, maxval(abs(A-matmul(L,transpose(L)))) 18 | 19 | ! Decompose (upper) 20 | call cholesky(A, U, lower=.false.) 21 | 22 | ! Compare decomposition 23 | print *, maxval(abs(A-matmul(transpose(U),U))) 24 | 25 | end program example_cholesky 26 | -------------------------------------------------------------------------------- /example/linalg/example_cross_product.f90: -------------------------------------------------------------------------------- 1 | program demo_cross_product 2 | use stdlib_linalg, only: cross_product 3 | implicit none 4 | real :: a(3), b(3), c(3) 5 | a = [1., 0., 0.] 6 | b = [0., 1., 0.] 7 | c = cross_product(a, b) 8 | !c = [0., 0., 1.] 9 | end program demo_cross_product 10 | -------------------------------------------------------------------------------- /example/linalg/example_determinant.f90: -------------------------------------------------------------------------------- 1 | program example_determinant 2 | use stdlib_kinds, only: dp 3 | use stdlib_linalg, only: det, linalg_state_type 4 | implicit none 5 | 6 | real(dp) :: d 7 | 8 | ! Compute determinate of a real matrix 9 | d = det(reshape([real(dp)::1,2,3,4],[2,2])) 10 | 11 | print *, d ! a*d-b*c = -2.0 12 | 13 | end program example_determinant 14 | -------------------------------------------------------------------------------- /example/linalg/example_determinant2.f90: -------------------------------------------------------------------------------- 1 | program example_determinant2 2 | use stdlib_kinds, only: dp 3 | use stdlib_linalg, only: operator(.det.) 4 | implicit none 5 | 6 | real(dp) :: d 7 | 8 | ! Compute determinate of a real matrix 9 | d = .det.reshape([real(dp)::1,2,3,4],[2,2]) 10 | 11 | print *, d ! a*d-b*c = -2.0 12 | 13 | end program example_determinant2 14 | -------------------------------------------------------------------------------- /example/linalg/example_diag1.f90: -------------------------------------------------------------------------------- 1 | program example_diag1 2 | use stdlib_linalg, only: diag 3 | implicit none 4 | real, allocatable :: A(:, :) 5 | integer :: i 6 | A = diag([(1, i=1, 10)]) ! creates a 10 by 10 identity matrix 7 | end program example_diag1 8 | -------------------------------------------------------------------------------- /example/linalg/example_diag2.f90: -------------------------------------------------------------------------------- 1 | program example_diag2 2 | use stdlib_linalg, only: diag 3 | implicit none 4 | real, allocatable :: v(:) 5 | real, allocatable :: A(:, :) 6 | v = [1, 2, 3, 4, 5] 7 | A = diag(v) ! creates a 5 by 5 matrix with elements of v on the diagonal 8 | end program example_diag2 9 | -------------------------------------------------------------------------------- /example/linalg/example_diag3.f90: -------------------------------------------------------------------------------- 1 | program example_diag3 2 | use stdlib_linalg, only: diag 3 | implicit none 4 | integer, parameter :: n = 10 5 | real :: c(n), ul(n - 1) 6 | real :: A(n, n) 7 | c = 2 8 | ul = -1 9 | A = diag(ul, -1) + diag(c) + diag(ul, 1) ! Gil Strang's favorite matrix 10 | end program example_diag3 11 | -------------------------------------------------------------------------------- /example/linalg/example_diag4.f90: -------------------------------------------------------------------------------- 1 | program example_diag4 2 | use stdlib_linalg, only: diag 3 | implicit none 4 | integer, parameter :: n = 12 5 | real :: A(n, n) 6 | real :: v(n) 7 | call random_number(A) 8 | v = diag(A) ! v contains diagonal elements of A 9 | end program example_diag4 10 | -------------------------------------------------------------------------------- /example/linalg/example_diag5.f90: -------------------------------------------------------------------------------- 1 | program example_diag5 2 | use stdlib_linalg, only: diag 3 | implicit none 4 | integer, parameter :: n = 3 5 | real :: A(n, n) 6 | real, allocatable :: v(:) 7 | A = reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [n, n]) 8 | v = diag(A, -1) ! v is [2,6] 9 | v = diag(A, 1) ! v is [4,8] 10 | end program example_diag5 11 | -------------------------------------------------------------------------------- /example/linalg/example_eig.f90: -------------------------------------------------------------------------------- 1 | ! Eigendecomposition of a real square matrix 2 | program example_eig 3 | use stdlib_linalg, only: eig 4 | implicit none 5 | 6 | integer :: i 7 | real, allocatable :: A(:,:) 8 | complex, allocatable :: lambda(:),vectors(:,:) 9 | 10 | ! Decomposition of this square matrix 11 | ! NB Fortran is column-major -> transpose input 12 | A = transpose(reshape( [ [2, 2, 4], & 13 | [1, 3, 5], & 14 | [2, 3, 4] ], [3,3] )) 15 | 16 | ! Get eigenvalues and right eigenvectors 17 | allocate(lambda(3),vectors(3,3)) 18 | 19 | call eig(A, lambda, right=vectors) 20 | 21 | do i=1,3 22 | print *, 'eigenvalue ',i,': ',lambda(i) 23 | print *, 'eigenvector ',i,': ',vectors(:,i) 24 | end do 25 | 26 | end program example_eig 27 | -------------------------------------------------------------------------------- /example/linalg/example_eig_generalized.f90: -------------------------------------------------------------------------------- 1 | ! Eigendecomposition of a real square matrix for the generalized eigenproblem 2 | program example_eig_generalized 3 | use stdlib_linalg, only: eig, eye 4 | implicit none 5 | 6 | integer :: i 7 | real, allocatable :: A(:,:), B(:,:) 8 | complex, allocatable :: lambda(:), vectors(:,:) 9 | 10 | ! Matrices for the generalized eigenproblem: A * v = lambda * B * v 11 | ! NB Fortran is column-major -> transpose input 12 | A = transpose(reshape([ [2, 2, 4], & 13 | [1, 3, 5], & 14 | [2, 3, 4] ], [3,3])) 15 | 16 | B = eye(3) 17 | 18 | ! Allocate eigenvalues and right eigenvectors 19 | allocate(lambda(3), vectors(3,3)) 20 | 21 | ! Get eigenvalues and right eigenvectors for the generalized problem 22 | call eig(A, B, lambda, right=vectors) 23 | 24 | do i = 1, 3 25 | print *, 'Eigenvalue ', i, ': ', lambda(i) 26 | print *, 'Eigenvector ', i, ': ', vectors(:,i) 27 | end do 28 | 29 | end program example_eig_generalized 30 | 31 | -------------------------------------------------------------------------------- /example/linalg/example_eigvals.f90: -------------------------------------------------------------------------------- 1 | ! Eigenvalues of a general real / complex matrix 2 | program example_eigvals 3 | use stdlib_linalg, only: eigvals 4 | implicit none 5 | 6 | real, allocatable :: A(:,:),lambda(:) 7 | complex, allocatable :: cA(:,:),clambda(:) 8 | 9 | ! NB Fortran is column-major -> transpose input 10 | A = transpose(reshape( [ [2, 8, 4], & 11 | [1, 3, 5], & 12 | [9, 5,-2] ], [3,3] )) 13 | 14 | ! Note: real symmetric matrix 15 | lambda = eigvals(A) 16 | print *, 'Real matrix eigenvalues: ',lambda 17 | 18 | ! Complex general matrix 19 | cA = cmplx(A, -2*A) 20 | clambda = eigvals(cA) 21 | print *, 'Complex matrix eigenvalues: ',clambda 22 | 23 | end program example_eigvals 24 | -------------------------------------------------------------------------------- /example/linalg/example_eigvals_generalized.f90: -------------------------------------------------------------------------------- 1 | ! Eigenvalues of a general real/complex matrix for the generalized eigenproblem 2 | program example_eigvals_generalized 3 | use stdlib_linalg, only: eigvals, eye 4 | implicit none 5 | 6 | real, allocatable :: A(:,:), B(:,:), lambda(:) 7 | complex, allocatable :: cA(:,:), cB(:,:), clambda(:) 8 | 9 | ! NB Fortran is column-major -> transpose input 10 | A = transpose(reshape([ [2, 8, 4], & 11 | [1, 3, 5], & 12 | [9, 5,-2] ], [3,3])) 13 | 14 | B = eye(3) 15 | 16 | ! Real generalized eigenproblem 17 | lambda = eigvals(A, B) 18 | print *, 'Real generalized matrix eigenvalues: ', lambda 19 | 20 | ! Complex generalized eigenproblem 21 | cA = cmplx(A, -2*A) 22 | cB = cmplx(B, 0.5*B) 23 | clambda = eigvals(cA, cB) 24 | print *, 'Complex generalized matrix eigenvalues: ', clambda 25 | 26 | end program example_eigvals_generalized 27 | -------------------------------------------------------------------------------- /example/linalg/example_eigvalsh.f90: -------------------------------------------------------------------------------- 1 | ! Eigenvalues of a real symmetric / complex hermitian matrix 2 | program example_eigvalsh 3 | use stdlib_linalg, only: eigvalsh 4 | implicit none 5 | 6 | real, allocatable :: A(:,:),lambda(:) 7 | complex, allocatable :: cA(:,:) 8 | 9 | ! Decomposition of this symmetric matrix 10 | ! NB Fortran is column-major -> transpose input 11 | A = transpose(reshape( [ [2, 1, 4], & 12 | [1, 3, 5], & 13 | [4, 5, 4] ], [3,3] )) 14 | 15 | ! Note: real symmetric matrices have real (orthogonal) eigenvalues and eigenvectors 16 | lambda = eigvalsh(A) 17 | print *, 'Symmetric matrix eigenvalues: ',lambda 18 | 19 | ! Complex hermitian matrices have real (orthogonal) eigenvalues and complex eigenvectors 20 | cA = A 21 | lambda = eigvalsh(cA) 22 | print *, 'Hermitian matrix eigenvalues: ',lambda 23 | 24 | end program example_eigvalsh 25 | -------------------------------------------------------------------------------- /example/linalg/example_eye1.f90: -------------------------------------------------------------------------------- 1 | program example_eye1 2 | use stdlib_linalg, only: eye 3 | implicit none 4 | integer :: i(2, 2) 5 | real :: a(3, 3) 6 | real :: b(2, 3) !! Matrix is non-square. 7 | complex :: c(2, 2) 8 | I = eye(2) !! [1,0; 0,1] 9 | A = eye(3) !! [1.0,0.0,0.0; 0.0,1.0,0.0; 0.0,0.0,1.0] 10 | A = eye(3, 3) !! [1.0,0.0,0.0; 0.0,1.0,0.0; 0.0,0.0,1.0] 11 | B = eye(2, 3) !! [1.0,0.0,0.0; 0.0,1.0,0.0] 12 | C = eye(2, 2) !! [(1.0,0.0),(0.0,0.0); (0.0,0.0),(1.0,0.0)] 13 | C = (1.0, 1.0)*eye(2, 2) !! [(1.0,1.0),(0.0,0.0); (0.0,0.0),(1.0,1.0)] 14 | end program example_eye1 15 | -------------------------------------------------------------------------------- /example/linalg/example_eye2.f90: -------------------------------------------------------------------------------- 1 | program example_eye2 2 | use stdlib_linalg, only: eye, diag 3 | implicit none 4 | print *, all(eye(4) == diag([1, 1, 1, 1])) ! prints .true. 5 | end program example_eye2 6 | -------------------------------------------------------------------------------- /example/linalg/example_hermitian.f90: -------------------------------------------------------------------------------- 1 | ! Example program demonstrating the usage of hermitian 2 | program example_hermitian 3 | use stdlib_linalg, only: hermitian 4 | implicit none 5 | 6 | complex, dimension(2, 2) :: A, AT 7 | 8 | ! Define input matrices 9 | A = reshape([(1,2),(3,4),(5,6),(7,8)],[2,2]) 10 | 11 | ! Compute Hermitian matrices 12 | AT = hermitian(A) 13 | 14 | print *, "Original Complex Matrix:" 15 | print *, A 16 | print *, "Hermitian Complex Matrix:" 17 | print *, AT 18 | 19 | end program example_hermitian 20 | -------------------------------------------------------------------------------- /example/linalg/example_inverse_function.f90: -------------------------------------------------------------------------------- 1 | ! Matrix inversion example: function interface 2 | program example_inverse_function 3 | use stdlib_linalg_constants, only: dp 4 | use stdlib_linalg, only: inv,eye 5 | implicit none 6 | 7 | real(dp) :: A(2,2), Am1(2,2) 8 | 9 | ! Input matrix (NB Fortran is column major! input columns then transpose) 10 | A = transpose(reshape( [4, 3, & 11 | 3, 2], [2,2] )) 12 | 13 | ! Invert matrix 14 | Am1 = inv(A) 15 | 16 | print *, ' |',Am1(1,:),'|' ! | -2 3 | 17 | print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 | 18 | 19 | ! Final check 20 | print *, 'CHECK passed? ',matmul(A,Am1)==eye(2) 21 | 22 | end program example_inverse_function 23 | -------------------------------------------------------------------------------- /example/linalg/example_inverse_inplace.f90: -------------------------------------------------------------------------------- 1 | ! Matrix inversion example: in-place inversion 2 | program example_inverse_inplace 3 | use stdlib_linalg_constants, only: dp 4 | use stdlib_linalg, only: invert,eye 5 | implicit none 6 | 7 | real(dp) :: A(2,2), Am1(2,2) 8 | 9 | ! Input matrix (NB Fortran is column major! input columns then transpose) 10 | A = transpose(reshape( [4, 3, & 11 | 3, 2], [2,2] )) 12 | Am1 = A 13 | 14 | ! Invert matrix 15 | call invert(Am1) 16 | 17 | print *, ' |',Am1(1,:),'|' ! | -2 3 | 18 | print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 | 19 | 20 | ! Final check 21 | print *, 'CHECK passed? ',matmul(A,Am1)==eye(2) 22 | 23 | end program example_inverse_inplace 24 | -------------------------------------------------------------------------------- /example/linalg/example_inverse_operator.f90: -------------------------------------------------------------------------------- 1 | ! Matrix inversion example: operator interface 2 | program example_inverse_operator 3 | use stdlib_linalg_constants, only: dp 4 | use stdlib_linalg, only: operator(.inv.),eye 5 | implicit none 6 | 7 | real(dp) :: A(2,2), Am1(2,2) 8 | 9 | ! Input matrix (NB Fortran is column major! input columns then transpose) 10 | A = transpose(reshape( [4, 3, & 11 | 3, 2], [2,2] )) 12 | 13 | ! Invert matrix 14 | Am1 = .inv.A 15 | 16 | print *, ' |',Am1(1,:),'|' ! | -2 3 | 17 | print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 | 18 | 19 | ! Final check 20 | print *, 'CHECK passed? ',matmul(A,Am1)==eye(2) 21 | 22 | end program example_inverse_operator 23 | -------------------------------------------------------------------------------- /example/linalg/example_inverse_subroutine.f90: -------------------------------------------------------------------------------- 1 | ! Matrix inversion example: subroutine interface 2 | program example_inverse_subroutine 3 | use stdlib_linalg_constants, only: dp 4 | use stdlib_linalg, only: invert,eye 5 | implicit none 6 | 7 | real(dp) :: A(2,2), Am1(2,2) 8 | 9 | ! Input matrix (NB Fortran is column major! input columns then transpose) 10 | A = transpose(reshape( [4, 3, & 11 | 3, 2], [2,2] )) 12 | 13 | ! Invert matrix 14 | call invert(A,Am1) 15 | 16 | print *, ' |',Am1(1,:),'|' ! | -2 3 | 17 | print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 | 18 | 19 | ! Final check 20 | print *, 'CHECK passed? ',matmul(A,Am1)==eye(2) 21 | 22 | end program example_inverse_subroutine 23 | -------------------------------------------------------------------------------- /example/linalg/example_is_diagonal.f90: -------------------------------------------------------------------------------- 1 | program example_is_diagonal 2 | use stdlib_linalg, only: is_diagonal 3 | implicit none 4 | real :: A(2, 2), B(2, 2) 5 | logical :: res 6 | A = reshape([1., 0., 0., 4.], shape(A)) 7 | B = reshape([1., 0., 3., 4.], shape(B)) 8 | res = is_diagonal(A) ! returns .true. 9 | res = is_diagonal(B) ! returns .false. 10 | end program example_is_diagonal 11 | -------------------------------------------------------------------------------- /example/linalg/example_is_hermitian.f90: -------------------------------------------------------------------------------- 1 | program example_is_hermitian 2 | use stdlib_linalg, only: is_hermitian 3 | implicit none 4 | complex :: A(2, 2), B(2, 2) 5 | logical :: res 6 | A = reshape([cmplx(1., 0.), cmplx(3., -1.), cmplx(3., 1.), cmplx(4., 0.)], shape(A)) 7 | B = reshape([cmplx(1., 0.), cmplx(3., 1.), cmplx(3., 1.), cmplx(4., 0.)], shape(B)) 8 | res = is_hermitian(A) ! returns .true. 9 | res = is_hermitian(B) ! returns .false. 10 | end program example_is_hermitian 11 | -------------------------------------------------------------------------------- /example/linalg/example_is_hessenberg.f90: -------------------------------------------------------------------------------- 1 | program example_is_hessenberg 2 | use stdlib_linalg, only: is_hessenberg 3 | implicit none 4 | real :: A(3, 3), B(3, 3) 5 | logical :: res 6 | A = reshape([1., 2., 0., 4., 5., 6., 7., 8., 9.], shape(A)) 7 | B = reshape([1., 2., 3., 4., 5., 6., 7., 8., 9.], shape(B)) 8 | res = is_hessenberg(A, 'u') ! returns .true. 9 | res = is_hessenberg(B, 'u') ! returns .false. 10 | end program example_is_hessenberg 11 | -------------------------------------------------------------------------------- /example/linalg/example_is_skew_symmetric.f90: -------------------------------------------------------------------------------- 1 | program example_is_skew_symmetric 2 | use stdlib_linalg, only: is_skew_symmetric 3 | implicit none 4 | real :: A(2, 2), B(2, 2) 5 | logical :: res 6 | A = reshape([0., -3., 3., 0.], shape(A)) 7 | B = reshape([0., 3., 3., 0.], shape(B)) 8 | res = is_skew_symmetric(A) ! returns .true. 9 | res = is_skew_symmetric(B) ! returns .false. 10 | end program example_is_skew_symmetric 11 | -------------------------------------------------------------------------------- /example/linalg/example_is_square.f90: -------------------------------------------------------------------------------- 1 | program example_is_square 2 | use stdlib_linalg, only: is_square 3 | implicit none 4 | real :: A(2, 2), B(3, 2) 5 | logical :: res 6 | A = reshape([1., 2., 3., 4.], shape(A)) 7 | B = reshape([1., 2., 3., 4., 5., 6.], shape(B)) 8 | res = is_square(A) ! returns .true. 9 | res = is_square(B) ! returns .false. 10 | end program example_is_square 11 | -------------------------------------------------------------------------------- /example/linalg/example_is_symmetric.f90: -------------------------------------------------------------------------------- 1 | program example_is_symmetric 2 | use stdlib_linalg, only: is_symmetric 3 | implicit none 4 | real :: A(2, 2), B(2, 2) 5 | logical :: res 6 | A = reshape([1., 3., 3., 4.], shape(A)) 7 | B = reshape([1., 0., 3., 4.], shape(B)) 8 | res = is_symmetric(A) ! returns .true. 9 | res = is_symmetric(B) ! returns .false. 10 | end program example_is_symmetric 11 | -------------------------------------------------------------------------------- /example/linalg/example_is_triangular.f90: -------------------------------------------------------------------------------- 1 | program example_is_triangular 2 | use stdlib_linalg, only: is_triangular 3 | implicit none 4 | real :: A(3, 3), B(3, 3) 5 | logical :: res 6 | A = reshape([1., 0., 0., 4., 5., 0., 7., 8., 9.], shape(A)) 7 | B = reshape([1., 0., 3., 4., 5., 0., 7., 8., 9.], shape(B)) 8 | res = is_triangular(A, 'u') ! returns .true. 9 | res = is_triangular(B, 'u') ! returns .false. 10 | end program example_is_triangular 11 | -------------------------------------------------------------------------------- /example/linalg/example_kronecker_product.f90: -------------------------------------------------------------------------------- 1 | program example_kronecker_product 2 | use stdlib_linalg, only: kronecker_product 3 | implicit none 4 | integer, parameter :: m1 = 1, n1 = 2, m2 = 2, n2 = 3 5 | integer :: i, j 6 | real :: A(m1, n1), B(m2,n2) 7 | real, allocatable :: C(:,:) 8 | 9 | do j = 1, n1 10 | do i = 1, m1 11 | A(i,j) = i*j ! A = [1, 2] 12 | end do 13 | end do 14 | 15 | do j = 1, n2 16 | do i = 1, m2 ! B = [ 1, 2, 3 ] 17 | B(i,j) = i*j ! [ 2, 4, 6 ] 18 | end do 19 | end do 20 | 21 | C = kronecker_product(A, B) 22 | ! C = [ a(1,1) * B(:,:) | a(1,2) * B(:,:) ] 23 | ! or in other words, 24 | ! C = [ 1.00 2.00 3.00 2.00 4.00 6.00 ] 25 | ! [ 2.00 4.00 6.00 4.00 8.00 12.00 ] 26 | end program example_kronecker_product 27 | -------------------------------------------------------------------------------- /example/linalg/example_lapack_getrf.f90: -------------------------------------------------------------------------------- 1 | program example_getrf 2 | use stdlib_linalg, only: eye 3 | use stdlib_linalg_lapack, only: dp,ilp,getrf 4 | implicit none 5 | real(dp) :: A(3, 3) 6 | integer(ilp) :: ipiv(3),info 7 | 8 | A = eye(3) 9 | 10 | ! LAPACK matrix factorization interface (overwrite result) 11 | call getrf(size(A,1),size(A,2),A,size(A,1),ipiv,info) 12 | print *, info ! info==0: Success! 13 | 14 | end program example_getrf 15 | -------------------------------------------------------------------------------- /example/linalg/example_lstsq1.f90: -------------------------------------------------------------------------------- 1 | ! Least-squares solver: functional interface 2 | program example_lstsq1 3 | use stdlib_linalg_constants, only: dp 4 | use stdlib_linalg, only: lstsq 5 | implicit none 6 | 7 | integer, allocatable :: x(:),y(:) 8 | real(dp), allocatable :: A(:,:),b(:),coef(:) 9 | 10 | ! Data set 11 | x = [1, 2, 2] 12 | y = [5, 13, 25] 13 | 14 | ! Fit three points using a parabola, least squares method 15 | ! A = [1 x x**2] 16 | A = reshape([[1,1,1],x,x**2],[3,3]) 17 | b = y 18 | 19 | ! Get coefficients of y = coef(1) + x*coef(2) + x^2*coef(3) 20 | coef = lstsq(A,b) 21 | 22 | print *, 'parabola: ',coef 23 | ! parabola: -0.42857142857141695 1.1428571428571503 4.2857142857142811 24 | 25 | 26 | end program example_lstsq1 27 | -------------------------------------------------------------------------------- /example/linalg/example_mnorm.f90: -------------------------------------------------------------------------------- 1 | program example_mnorm 2 | use stdlib_linalg, only: mnorm 3 | use stdlib_kinds, only: sp 4 | implicit none 5 | real(sp) :: a(3,3), na 6 | real(sp) :: b(3,3,4), nb(4) ! Array of 4 3x3 matrices 7 | 8 | ! Initialize example matrix 9 | a = reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3]) 10 | 11 | ! Compute Euclidean norm of single matrix 12 | na = mnorm(a, 'Euclidean') 13 | print *, "Euclidean norm of matrix a:", na 14 | 15 | ! Initialize array of matrices 16 | b(:,:,1) = a 17 | b(:,:,2) = 2*a 18 | b(:,:,3) = 3*a 19 | b(:,:,4) = 4*a 20 | 21 | ! Compute infinity norm of each 3x3 matrix in b 22 | nb = mnorm(b, 'inf', dim=[1,2]) 23 | 24 | ! 18.0000000 36.0000000 54.0000000 72.0000000 25 | print *, "Infinity norms of matrices in b:", nb 26 | end program example_mnorm 27 | -------------------------------------------------------------------------------- /example/linalg/example_outer_product.f90: -------------------------------------------------------------------------------- 1 | program example_outer_product 2 | use stdlib_linalg, only: outer_product 3 | implicit none 4 | real, allocatable :: A(:, :), u(:), v(:) 5 | u = [1., 2., 3.] 6 | v = [3., 4.] 7 | A = outer_product(u, v) 8 | !A = reshape([3., 6., 9., 4., 8., 12.], [3,2]) 9 | end program example_outer_product 10 | -------------------------------------------------------------------------------- /example/linalg/example_pseudoinverse.f90: -------------------------------------------------------------------------------- 1 | ! Matrix pseudo-inversion example: function, subroutine, and operator interfaces 2 | program example_pseudoinverse 3 | use stdlib_linalg, only: pinv, pseudoinvert, operator(.pinv.), linalg_state_type 4 | implicit none 5 | 6 | real :: A(15,5), Am1(5,15) 7 | type(linalg_state_type) :: state 8 | 9 | ! Generate random matrix A (15x15) 10 | call random_number(A) 11 | 12 | ! Pseudo-inverse: Function interfcae 13 | Am1 = pinv(A, err=state) 14 | print *, 'Max error (function) : ', maxval(abs(A-matmul(A, matmul(Am1,A)))) 15 | 16 | ! User threshold 17 | Am1 = pinv(A, rtol=0.001, err=state) 18 | print *, 'Max error (rtol=0.001): ', maxval(abs(A-matmul(A, matmul(Am1,A)))) 19 | 20 | ! Pseudo-inverse: Subroutine interface 21 | call pseudoinvert(A, Am1, err=state) 22 | 23 | print *, 'Max error (subroutine): ', maxval(abs(A-matmul(A, matmul(Am1,A)))) 24 | 25 | ! Operator interface 26 | Am1 = .pinv.A 27 | 28 | print *, 'Max error (operator) : ', maxval(abs(A-matmul(A, matmul(Am1,A)))) 29 | 30 | end program example_pseudoinverse 31 | -------------------------------------------------------------------------------- /example/linalg/example_qr.f90: -------------------------------------------------------------------------------- 1 | program example_qr 2 | use stdlib_linalg, only: qr 3 | implicit none 4 | real :: A(104, 32), Q(104,32), R(32,32) 5 | 6 | ! Create a random matrix 7 | call random_number(A) 8 | 9 | ! Compute its QR factorization (reduced) 10 | call qr(A,Q,R) 11 | 12 | ! Test factorization: Q*R = A 13 | print *, maxval(abs(matmul(Q,R)-A)) 14 | 15 | end program example_qr 16 | -------------------------------------------------------------------------------- /example/linalg/example_qr_space.f90: -------------------------------------------------------------------------------- 1 | ! QR example with pre-allocated storage 2 | program example_qr_space 3 | use stdlib_linalg_constants, only: ilp 4 | use stdlib_linalg, only: qr, qr_space, linalg_state_type 5 | implicit none 6 | real :: A(104, 32), Q(104,32), R(32,32) 7 | real, allocatable :: work(:) 8 | integer(ilp) :: lwork 9 | type(linalg_state_type) :: err 10 | 11 | ! Create a random matrix 12 | call random_number(A) 13 | 14 | ! Prepare QR workspace 15 | call qr_space(A,lwork) 16 | allocate(work(lwork)) 17 | 18 | ! Compute its QR factorization (reduced) 19 | call qr(A,Q,R,storage=work,err=err) 20 | 21 | ! Test factorization: Q*R = A 22 | print *, maxval(abs(matmul(Q,R)-A)) 23 | print *, err%print() 24 | 25 | end program example_qr_space 26 | -------------------------------------------------------------------------------- /example/linalg/example_schur_complex.f90: -------------------------------------------------------------------------------- 1 | ! This example demonstrates the Schur decomposition for a complex-valued matrix. 2 | program example_schur_complex 3 | use stdlib_linalg, only: schur 4 | use stdlib_linalg_constants, only: dp 5 | implicit none 6 | 7 | integer, parameter :: n = 3 8 | complex(dp), dimension(n,n) :: A, T, Z 9 | 10 | ! Initialize a complex-valued square matrix 11 | A = reshape([ (1, 2), (3,-1), (4, 1), & 12 | (0,-1), (2, 0), (1,-2), & 13 | (2, 3), (1, 1), (0,-1) ], shape=[n,n]) 14 | 15 | ! Compute the Schur decomposition: A = Z T Z^H 16 | call schur(A, T, Z) 17 | 18 | ! Output results 19 | print *, "Original Matrix A:" 20 | print *, A 21 | print *, "Schur Form Matrix T:" 22 | print *, T 23 | print *, "Unitary Matrix Z:" 24 | print *, Z 25 | 26 | ! Test factorization: Z*T*Z^H = A 27 | print *, "Max error in reconstruction:", maxval(abs(matmul(Z, matmul(T, conjg(transpose(Z)))) - A)) 28 | 29 | end program example_schur_complex 30 | 31 | -------------------------------------------------------------------------------- /example/linalg/example_schur_eigvals.f90: -------------------------------------------------------------------------------- 1 | ! This example includes eigenvalue computation in addition to 2 | ! the Schur decomposition for a randomly generated matrix. 3 | program example_schur_eigenvalues 4 | use stdlib_linalg, only: schur 5 | use stdlib_linalg_constants, only: dp 6 | implicit none 7 | 8 | integer, parameter :: n = 5 9 | real(dp), dimension(n,n) :: A, T, Z 10 | complex(dp), dimension(n) :: eigenvalues 11 | 12 | ! Create a random real-valued square matrix 13 | call random_number(A) 14 | 15 | ! Compute the Schur decomposition and eigenvalues 16 | call schur(A, T, Z, eigenvalues) 17 | 18 | ! Output results 19 | print *, "Random Matrix A:" 20 | print *, A 21 | print *, "Schur Form Matrix T:" 22 | print *, T 23 | print *, "Orthogonal Matrix Z:" 24 | print *, Z 25 | print *, "Eigenvalues:" 26 | print *, eigenvalues 27 | 28 | ! Test factorization: Z*T*Z^T = A 29 | print *, "Max error in reconstruction:", maxval(abs(matmul(Z, matmul(T, transpose(Z))) - A)) 30 | 31 | end program example_schur_eigenvalues 32 | 33 | -------------------------------------------------------------------------------- /example/linalg/example_schur_real.f90: -------------------------------------------------------------------------------- 1 | ! This example computes the Schur decomposition of a real-valued square matrix. 2 | program example_schur_real 3 | use stdlib_linalg, only: schur 4 | use stdlib_linalg_constants, only: dp 5 | implicit none 6 | integer, parameter :: n = 3 7 | real(dp), dimension(n,n) :: A, T, Z 8 | 9 | ! Initialize a real-valued square matrix 10 | A = reshape([ 0, 2, 2, & 11 | 0, 1, 2, & 12 | 1, 0, 1], shape=[n,n]) 13 | 14 | ! Compute the Schur decomposition: A = Z T Z^T 15 | call schur(A, T, Z) 16 | 17 | ! Output results 18 | print *, "Original Matrix A:" 19 | print *, A 20 | print *, "Schur Form Matrix T:" 21 | print *, T 22 | print *, "Orthogonal Matrix Z:" 23 | print *, Z 24 | 25 | ! Test factorization: Z*T*Z^T = A 26 | print *, "Max error in reconstruction:", maxval(abs(matmul(Z, matmul(T, transpose(Z))) - A)) 27 | 28 | end program example_schur_real 29 | 30 | -------------------------------------------------------------------------------- /example/linalg/example_solve1.f90: -------------------------------------------------------------------------------- 1 | program example_solve1 2 | use stdlib_linalg_constants, only: sp 3 | use stdlib_linalg, only: solve, linalg_state_type 4 | implicit none 5 | 6 | real(sp), allocatable :: A(:,:),b(:),x(:) 7 | 8 | ! Solve a system of 3 linear equations: 9 | ! 4x + 3y + 2z = 25 10 | ! -2x + 2y + 3z = -10 11 | ! 3x - 5y + 2z = -4 12 | 13 | ! Note: Fortran is column-major! -> transpose 14 | A = transpose(reshape([ 4, 3, 2, & 15 | -2, 2, 3, & 16 | 3,-5, 2], [3,3])) 17 | b = [25,-10,-4] 18 | 19 | ! Get coefficients of y = coef(1) + x*coef(2) + x^2*coef(3) 20 | x = solve(A,b) 21 | 22 | print *, 'solution: ',x 23 | ! 5.0, 3.0, -2.0 24 | 25 | end program example_solve1 26 | 27 | -------------------------------------------------------------------------------- /example/linalg/example_solve2.f90: -------------------------------------------------------------------------------- 1 | program example_solve2 2 | use stdlib_linalg_constants, only: sp 3 | use stdlib_linalg, only: solve, linalg_state_type 4 | implicit none 5 | 6 | complex(sp), allocatable :: A(:,:),b(:),x(:) 7 | 8 | ! Solve a system of 3 complex linear equations: 9 | ! 2x + iy + 2z = (5-i) 10 | ! -ix + (4-3i)y + 6z = i 11 | ! 4x + 3y + z = 1 12 | 13 | ! Note: Fortran is column-major! -> transpose 14 | A = transpose(reshape([(2.0, 0.0),(0.0, 1.0),(2.0,0.0), & 15 | (0.0,-1.0),(4.0,-3.0),(6.0,0.0), & 16 | (4.0, 0.0),(3.0, 0.0),(1.0,0.0)] , [3,3])) 17 | b = [(5.0,-1.0),(0.0,1.0),(1.0,0.0)] 18 | 19 | ! Get coefficients of y = coef(1) + x*coef(2) + x^2*coef(3) 20 | x = solve(A,b) 21 | 22 | print *, 'solution: ',x 23 | ! (1.0947,0.3674) (-1.519,-0.4539) (1.1784,-0.1078) 24 | 25 | end program example_solve2 26 | 27 | -------------------------------------------------------------------------------- /example/linalg/example_solve3.f90: -------------------------------------------------------------------------------- 1 | program example_solve3 2 | use stdlib_linalg_constants, only: sp,ilp 3 | use stdlib_linalg, only: solve_lu, linalg_state_type 4 | implicit none 5 | 6 | integer(ilp) :: test 7 | integer(ilp), allocatable :: pivot(:) 8 | complex(sp), allocatable :: A(:,:),b(:),x(:) 9 | 10 | ! Solve a system of 3 complex linear equations: 11 | ! 2x + iy + 2z = (5-i) 12 | ! -ix + (4-3i)y + 6z = i 13 | ! 4x + 3y + z = 1 14 | 15 | ! Note: Fortran is column-major! -> transpose 16 | A = transpose(reshape([(2.0, 0.0),(0.0, 1.0),(2.0,0.0), & 17 | (0.0,-1.0),(4.0,-3.0),(6.0,0.0), & 18 | (4.0, 0.0),(3.0, 0.0),(1.0,0.0)] , [3,3])) 19 | 20 | ! Pre-allocate x 21 | allocate(b(size(A,2)),pivot(size(A,2))) 22 | allocate(x,mold=b) 23 | 24 | ! Call system many times avoiding reallocation 25 | do test=1,100 26 | b = test*[(5.0,-1.0),(0.0,1.0),(1.0,0.0)] 27 | call solve_lu(A,b,x,pivot) 28 | print "(i3,'-th solution: ',*(1x,f12.6))", test,x 29 | end do 30 | 31 | end program example_solve3 32 | 33 | -------------------------------------------------------------------------------- /example/linalg/example_sparse_spmv.f90: -------------------------------------------------------------------------------- 1 | program example_sparse_spmv 2 | use stdlib_linalg_constants, only: dp 3 | use stdlib_sparse 4 | implicit none 5 | 6 | integer, parameter :: m = 4, n = 2 7 | real(dp) :: A(m,n), x(n) 8 | real(dp) :: y_dense(m), y_coo(m), y_csr(m) 9 | real(dp) :: alpha, beta 10 | type(COO_dp_type) :: COO 11 | type(CSR_dp_type) :: CSR 12 | 13 | call random_number(A) 14 | ! Convert from dense to COO and CSR matrices 15 | call dense2coo( A , COO ) 16 | call coo2csr( COO , CSR ) 17 | 18 | ! Initialize vectors 19 | x = 1._dp 20 | y_dense = 2._dp 21 | y_coo = y_dense 22 | y_csr = y_dense 23 | 24 | ! Perform matrix-vector product 25 | alpha = 3._dp; beta = 2._dp 26 | y_dense = alpha * matmul(A,x) + beta * y_dense 27 | call spmv( COO , x , y_coo , alpha = alpha, beta = beta ) 28 | call spmv( CSR , x , y_csr , alpha = alpha, beta = beta ) 29 | 30 | print *, 'dense :', y_dense 31 | print *, 'coo :', y_coo 32 | print *, 'csr :', y_csr 33 | 34 | end program example_sparse_spmv -------------------------------------------------------------------------------- /example/linalg/example_state1.f90: -------------------------------------------------------------------------------- 1 | program example_state1 2 | use stdlib_linalg_state, only: linalg_state_type, LINALG_SUCCESS, LINALG_VALUE_ERROR, & 3 | operator(/=) 4 | implicit none 5 | type(linalg_state_type) :: err 6 | 7 | ! To create a state variable, we enter its integer state flag, followed by a list of variables 8 | ! that will be automatically assembled into a formatted error message. No need to provide string formats 9 | err = linalg_state_type(LINALG_VALUE_ERROR,'just an example with scalar ',& 10 | 'integer=',1,'real=',2.0,'complex=',(3.0,1.0),'and array ',[1,2,3],'inputs') 11 | 12 | ! Print flag 13 | print *, err%print() 14 | 15 | ! Check success 16 | print *, 'Check error: ',err%error() 17 | print *, 'Check flag : ',err /= LINALG_SUCCESS 18 | 19 | 20 | end program example_state1 21 | -------------------------------------------------------------------------------- /example/linalg/example_svd.f90: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fortran-lang/stdlib/30ccd9d46496126a24f240ccfa6f9f9c762219a5/example/linalg/example_svd.f90 -------------------------------------------------------------------------------- /example/linalg/example_svdvals.f90: -------------------------------------------------------------------------------- 1 | ! Singular Values 2 | program example_svdvals 3 | use stdlib_linalg_constants, only: dp 4 | use stdlib_linalg, only: svdvals 5 | implicit none 6 | 7 | real(dp), allocatable :: A(:,:),s(:) 8 | character(*), parameter :: fmt="(a,*(1x,f12.8))" 9 | 10 | ! We want to find the singular values of matrix: 11 | ! 12 | ! A = [ 3 2 2] 13 | ! [ 2 3 -2] 14 | ! 15 | A = transpose(reshape([ 3, 2, 2, & 16 | 2, 3,-2], [3,2])) 17 | 18 | ! Get singular values 19 | s = svdvals(A) 20 | 21 | ! Singular values: [5, 3] 22 | print fmt, ' ' 23 | print fmt, 'S = ',s 24 | print fmt, ' ' 25 | 26 | end program example_svdvals 27 | -------------------------------------------------------------------------------- /example/linalg/example_trace.f90: -------------------------------------------------------------------------------- 1 | program example_trace 2 | use stdlib_linalg, only: trace 3 | implicit none 4 | real :: A(3, 3) 5 | A = reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3]) 6 | print *, trace(A) ! 1 + 5 + 9 7 | end program example_trace 8 | -------------------------------------------------------------------------------- /example/logger/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(add_log_unit) 2 | ADD_EXAMPLE(configure) 3 | ADD_EXAMPLE(global_logger) 4 | ADD_EXAMPLE(log_io_error) 5 | set_tests_properties(log_io_error PROPERTIES WILL_FAIL true) 6 | ADD_EXAMPLE(log_text_error) 7 | set_tests_properties(log_text_error PROPERTIES WILL_FAIL true) 8 | -------------------------------------------------------------------------------- /example/logger/dummy.txt: -------------------------------------------------------------------------------- 1 | a word 2 | it should fail with the presence of this .$/ 3 | -------------------------------------------------------------------------------- /example/logger/example_add_log_unit.f90: -------------------------------------------------------------------------------- 1 | program example_add_log_unit 2 | use stdlib_logger, only: global_logger, read_only_error 3 | implicit none 4 | 5 | character(256) :: iomsg 6 | integer :: iostat, unit, stat 7 | 8 | open (newunit=unit, file='error_log.txt', & 9 | form='formatted', status='replace', & 10 | position='rewind', & 11 | action='write', iostat=iostat, iomsg=iomsg) 12 | 13 | call global_logger%add_log_unit(unit, stat) 14 | 15 | select case (stat) 16 | case (read_only_error) 17 | error stop 'Unable to write to "error_log.txt".' 18 | end select 19 | 20 | end program example_add_log_unit 21 | -------------------------------------------------------------------------------- /example/logger/example_configure.f90: -------------------------------------------------------------------------------- 1 | program example_configure 2 | use stdlib_logger, only: global => global_logger 3 | implicit none 4 | 5 | call global%configure(indent=.false., max_width=72) 6 | 7 | end program example_configure 8 | -------------------------------------------------------------------------------- /example/logger/example_global_logger.f90: -------------------------------------------------------------------------------- 1 | program example_global_logger 2 | use stdlib_logger, global => global_logger 3 | implicit none 4 | 5 | integer :: unit, stat 6 | 7 | call global%add_log_file('error_log.txt', unit, & 8 | position='asis', stat=stat) 9 | if (stat /= success) then 10 | error stop 'Unable to open "error_log.txt".' 11 | end if 12 | 13 | end program example_global_logger 14 | -------------------------------------------------------------------------------- /example/logger/example_log_io_error.f90: -------------------------------------------------------------------------------- 1 | program example_log_io_error 2 | use stdlib_logger, global => global_logger 3 | implicit none 4 | 5 | character(*), parameter :: filename = 'nodummy.txt' 6 | integer :: iostat, lun 7 | character(128) :: iomsg 8 | character(*), parameter :: message = & 9 | 'Failure in opening "nodummy.txt".' 10 | 11 | open (newunit=lun, file=filename, form='formatted', & 12 | status='old', iostat=iostat, iomsg=iomsg) 13 | if (iostat /= 0) then 14 | call global%log_io_error(message, & 15 | procedure='EXAMPLE', & 16 | iostat=iostat, & 17 | iomsg=iomsg) 18 | error stop 'Error on opening a file' 19 | end if 20 | 21 | end program example_log_io_error 22 | -------------------------------------------------------------------------------- /example/logger/example_log_text_error.f90: -------------------------------------------------------------------------------- 1 | program example_log_text_error 2 | use stdlib_logger 3 | implicit none 4 | 5 | character(*), parameter :: filename = 'dummy.txt' 6 | integer :: col_no, line_no, lun, status 7 | character(128) :: line 8 | character(*), parameter :: message = 'Bad text found.' 9 | 10 | open (newunit=lun, file=filename, status='old', & 11 | form='formatted') 12 | line_no = 0 13 | do 14 | read (lun, fmt='(a)', end=900) line 15 | line_no = line_no + 1 16 | call check_line(line, status, col_no) 17 | if (status /= 0) then 18 | call global_logger%log_text_error(line, & 19 | col_no, message, filename, line_no) 20 | error stop 'Error in reading '//filename 21 | end if 22 | end do 23 | 900 continue 24 | 25 | contains 26 | 27 | subroutine check_line(line, status, col_no) 28 | character(*), intent(in) :: line 29 | integer, intent(inout) :: status 30 | integer, intent(inout) :: col_no 31 | ! scan the line for forbidden characters 32 | col_no = scan(line, ".$/") 33 | ! col_no > 0 means there is a forbidden character 34 | status = col_no 35 | end subroutine 36 | 37 | end program example_log_text_error 38 | -------------------------------------------------------------------------------- /example/math/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(clip_integer) 2 | ADD_EXAMPLE(clip_real) 3 | ADD_EXAMPLE(diff) 4 | ADD_EXAMPLE(gcd) 5 | ADD_EXAMPLE(linspace_complex) 6 | ADD_EXAMPLE(linspace_int16) 7 | ADD_EXAMPLE(logspace_complex) 8 | ADD_EXAMPLE(logspace_int) 9 | ADD_EXAMPLE(logspace_rstart_cbase) 10 | ADD_EXAMPLE(math_all_close) 11 | ADD_EXAMPLE(math_arange) 12 | ADD_EXAMPLE(math_argd) 13 | ADD_EXAMPLE(math_arg) 14 | ADD_EXAMPLE(math_argpi) 15 | ADD_EXAMPLE(math_deg2rad) 16 | ADD_EXAMPLE(math_rad2deg) 17 | ADD_EXAMPLE(math_is_close) 18 | ADD_EXAMPLE(math_swap) 19 | ADD_EXAMPLE(meshgrid) 20 | -------------------------------------------------------------------------------- /example/math/example_clip_integer.f90: -------------------------------------------------------------------------------- 1 | program example_clip_integer 2 | use stdlib_math, only: clip 3 | use stdlib_kinds, only: int32 4 | implicit none 5 | integer(int32) :: x 6 | integer(int32) :: xmin 7 | integer(int32) :: xmax 8 | integer(int32) :: clipped_value 9 | 10 | xmin = -5_int32 11 | xmax = 5_int32 12 | x = 12_int32 13 | 14 | clipped_value = clip(x, xmin, xmax) 15 | ! clipped_value <- 5 16 | end program example_clip_integer 17 | -------------------------------------------------------------------------------- /example/math/example_clip_real.f90: -------------------------------------------------------------------------------- 1 | program example_clip_real 2 | use stdlib_math, only: clip 3 | use stdlib_kinds, only: sp 4 | implicit none 5 | real(sp) :: x 6 | real(sp) :: xmin 7 | real(sp) :: xmax 8 | real(sp) :: clipped_value 9 | 10 | xmin = -5.769_sp 11 | xmax = 3.025_sp 12 | x = 3.025_sp 13 | 14 | clipped_value = clip(x, xmin, xmax) 15 | ! clipped_value <- 3.02500010 16 | end program example_clip_real 17 | -------------------------------------------------------------------------------- /example/math/example_diff.f90: -------------------------------------------------------------------------------- 1 | program example_diff 2 | 3 | use stdlib_math, only: diff 4 | implicit none 5 | 6 | integer :: i(7) = [1, 1, 2, 3, 5, 8, 13] 7 | real :: x(6) = [0, 5, 15, 30, 50, 75] 8 | integer :: A(3, 3) = reshape([1, 7, 17, 3, 11, 19, 5, 13, 23], [3, 3]) 9 | integer :: Y(3, 2) 10 | 11 | print *, diff(i) ! [0, 1, 1, 2, 3, 5] 12 | print *, diff(x, 2) ! [5.0, 5.0, 5.0, 5.0] 13 | 14 | Y = diff(A, n=1, dim=2) 15 | print *, Y(1, :) ! [2, 2] 16 | print *, Y(2, :) ! [4, 2] 17 | print *, Y(3, :) ! [2, 4] 18 | 19 | print *, diff(i, prepend=[0]) ! [1, 0, 1, 1, 2, 3, 5] 20 | print *, diff(i, append=[21]) ! [0, 1, 1, 2, 3, 5, 8] 21 | 22 | end program example_diff 23 | -------------------------------------------------------------------------------- /example/math/example_gcd.f90: -------------------------------------------------------------------------------- 1 | program example_gcd 2 | use stdlib_math, only: gcd 3 | implicit none 4 | integer :: a, b, c 5 | 6 | a = 48 7 | b = 18 8 | c = gcd(a, b) ! returns 6 9 | end program example_gcd 10 | -------------------------------------------------------------------------------- /example/math/example_linspace_complex.f90: -------------------------------------------------------------------------------- 1 | program example_linspace_complex 2 | use stdlib_math, only: linspace 3 | use stdlib_kinds, only: dp 4 | implicit none 5 | 6 | complex(dp) :: start = cmplx(10.0_dp, 5.0_dp, kind=dp) 7 | complex(dp) :: end = cmplx(-10.0_dp, 15.0_dp, kind=dp) 8 | 9 | complex(dp) :: z(11) 10 | 11 | z = linspace(start, end, 11) 12 | end program example_linspace_complex 13 | -------------------------------------------------------------------------------- /example/math/example_linspace_int16.f90: -------------------------------------------------------------------------------- 1 | program example_linspace_int16 2 | use stdlib_math, only: linspace 3 | use stdlib_kinds, only: int16, dp 4 | implicit none 5 | 6 | integer(int16) :: start = 10_int16 7 | integer(int16) :: end = 23_int16 8 | 9 | real(dp) :: r(15) 10 | 11 | r = linspace(start, end, 15) 12 | end program example_linspace_int16 13 | -------------------------------------------------------------------------------- /example/math/example_logspace_complex.f90: -------------------------------------------------------------------------------- 1 | program example_logspace_complex 2 | use stdlib_math, only: logspace 3 | use stdlib_kinds, only: dp 4 | implicit none 5 | 6 | complex(dp) :: start = (10.0_dp, 5.0_dp) 7 | complex(dp) :: end = (-10.0_dp, 15.0_dp) 8 | 9 | complex(dp) :: z(11) ! Complex values raised to complex powers results in complex values 10 | 11 | z = logspace(start, end, 11) 12 | end program example_logspace_complex 13 | -------------------------------------------------------------------------------- /example/math/example_logspace_int.f90: -------------------------------------------------------------------------------- 1 | program example_logspace_int 2 | use stdlib_math, only: logspace 3 | use stdlib_kinds, only: dp 4 | implicit none 5 | 6 | integer, parameter :: start = 10 7 | integer, parameter :: end = 23 8 | integer, parameter :: n = 15 9 | 10 | real(dp) :: r(n) ! Integer values raised to real powers results in real values 11 | 12 | r = logspace(start, end, n) 13 | end program example_logspace_int 14 | -------------------------------------------------------------------------------- /example/math/example_logspace_rstart_cbase.f90: -------------------------------------------------------------------------------- 1 | program example_logspace_rstart_cbase 2 | use stdlib_math, only: logspace 3 | use stdlib_kinds, only: dp 4 | implicit none 5 | 6 | real(dp) :: start = 0.0_dp 7 | real(dp) :: end = 3.0_dp 8 | integer, parameter :: n = 4 9 | complex(dp) :: base = (0.0_dp, 1.0_dp) 10 | 11 | complex(dp) :: z(n) ! complex values raised to real powers result in complex values 12 | 13 | z = logspace(start, end, n, base) 14 | 15 | end program example_logspace_rstart_cbase 16 | -------------------------------------------------------------------------------- /example/math/example_math_all_close.f90: -------------------------------------------------------------------------------- 1 | program example_math_all_close 2 | 3 | use stdlib_math, only: all_close 4 | implicit none 5 | real :: y, NAN 6 | complex :: z(4, 4) 7 | 8 | y = -3 9 | NAN = sqrt(y) 10 | z = (1.0, 1.0) 11 | 12 | print *, all_close(z + cmplx(1.0e-11, 1.0e-11), z) ! T 13 | print *, NAN, all_close([NAN], [NAN]), all_close([NAN], [NAN], equal_nan=.true.) 14 | ! NAN, F, T 15 | 16 | end program example_math_all_close 17 | -------------------------------------------------------------------------------- /example/math/example_math_arange.f90: -------------------------------------------------------------------------------- 1 | program example_math_arange 2 | use stdlib_math, only: arange 3 | implicit none 4 | 5 | print *, arange(3) ! [1,2,3] 6 | print *, arange(-1) ! [1,0,-1] 7 | print *, arange(0, 2) ! [0,1,2] 8 | print *, arange(1, -1) ! [1,0,-1] 9 | print *, arange(0, 2, 2) ! [0,2] 10 | 11 | print *, arange(3.0) ! [1.0,2.0,3.0] 12 | print *, arange(0.0, 5.0) ! [0.0,1.0,2.0,3.0,4.0,5.0] 13 | print *, arange(0.0, 6.0, 2.5) ! [0.0,2.5,5.0] 14 | 15 | print *, (1.0, 1.0)*arange(3) ! [(1.0,1.0),(2.0,2.0),[3.0,3.0]] 16 | 17 | print *, arange(0.0, 2.0, -2.0) ! [0.0,2.0]. Not recommended: `step` argument is negative! 18 | print *, arange(0.0, 2.0, 0.0) ! [0.0,1.0,2.0]. Not recommended: `step` argument is zero! 19 | 20 | end program example_math_arange 21 | -------------------------------------------------------------------------------- /example/math/example_math_arg.f90: -------------------------------------------------------------------------------- 1 | program example_math_arg 2 | use stdlib_math, only: arg 3 | implicit none 4 | print *, arg((0.0, 0.0)) ! 0.0 5 | print *, arg((3.0, 4.0)) ! 0.927 6 | print *, arg(2.0*exp((0.0, 0.5))) ! 0.5 7 | print *, arg([(0.0, 1.0), (1.0, 0.0), (0.0, -1.0), (-1.0, 0.0)]) ! [π/2, 0.0, -π/2, π] 8 | end program example_math_arg 9 | -------------------------------------------------------------------------------- /example/math/example_math_argd.f90: -------------------------------------------------------------------------------- 1 | program example_math_argd 2 | use stdlib_math, only: argd 3 | implicit none 4 | print *, argd((0.0, 0.0)) ! 0.0° 5 | print *, argd((3.0, 4.0)) ! 53.1° 6 | print *, argd(2.0*exp((0.0, 0.5))) ! 28.64° 7 | print *, argd([(0.0, 1.0), (1.0, 0.0), (0.0, -1.0), (-1.0, 0.0)]) ! [90°, 0°, -90°, 180°] 8 | end program example_math_argd 9 | -------------------------------------------------------------------------------- /example/math/example_math_argpi.f90: -------------------------------------------------------------------------------- 1 | program example_math_argpi 2 | use stdlib_math, only: argpi 3 | implicit none 4 | print *, argpi((0.0, 0.0)) ! 0.0 5 | print *, argpi((3.0, 4.0)) ! 0.295 6 | print *, argpi(2.0*exp((0.0, 0.5))) ! 0.159 7 | print *, argpi([(0.0, 1.0), (1.0, 0.0), (0.0, -1.0), (-1.0, 0.0)]) ! [0.5, 0.0, -0.5, 1.0] 8 | end program example_math_argpi 9 | -------------------------------------------------------------------------------- /example/math/example_math_deg2rad.f90: -------------------------------------------------------------------------------- 1 | program example_math_deg2rad 2 | use stdlib_math, only: deg2rad 3 | implicit none 4 | print *, deg2rad(0.0) ! 0.0 5 | print *, deg2rad(90.0) ! 1.57508 6 | print *, deg2rad(-180.0) ! -3.1416 7 | 8 | end program example_math_deg2rad 9 | -------------------------------------------------------------------------------- /example/math/example_math_is_close.f90: -------------------------------------------------------------------------------- 1 | program example_math_is_close 2 | 3 | use stdlib_math, only: is_close 4 | implicit none 5 | real :: x(2) = [1, 2], y, NAN 6 | 7 | y = -3 8 | NAN = sqrt(y) 9 | 10 | print *, is_close(x, [real :: 1, 2.1]) ! [T, F] 11 | print *, is_close(2.0, 2.1, abs_tol=0.1) ! T 12 | print *, NAN, is_close(2.0, NAN), is_close(2.0, NAN, equal_nan=.true.) ! NAN, F, F 13 | print *, is_close(NAN, NAN), is_close(NAN, NAN, equal_nan=.true.) ! F, T 14 | 15 | end program example_math_is_close 16 | -------------------------------------------------------------------------------- /example/math/example_math_rad2deg.f90: -------------------------------------------------------------------------------- 1 | program example_math_rad2deg 2 | use stdlib_math, only: rad2deg 3 | use stdlib_constants, only: PI_sp 4 | implicit none 5 | print *, rad2deg(0.0) ! 0.0 6 | print *, rad2deg(PI_sp / 2.0) ! 90.0 7 | print *, rad2deg(-PI_sp) ! -3.1416 8 | 9 | end program example_math_rad2deg 10 | -------------------------------------------------------------------------------- /example/math/example_math_swap.f90: -------------------------------------------------------------------------------- 1 | program example_math_swap 2 | use stdlib_math, only: swap 3 | implicit none 4 | 5 | block 6 | integer :: x, y 7 | x = 9 8 | y = 18 9 | call swap(x,y) 10 | end block 11 | 12 | block 13 | real :: x, y 14 | x = 4.0 15 | y = 8.0 16 | call swap(x,y) 17 | end block 18 | 19 | block 20 | real :: x(3), y(3) 21 | x = [1.0,2.0,3.0] 22 | y = [4.0,5.0,6.0] 23 | call swap(x,y) 24 | end block 25 | 26 | block 27 | character(4) :: x 28 | character(6) :: y 29 | x = 'abcd' 30 | y = 'efghij' 31 | call swap(x,y) ! x=efgh, y=abcd 32 | 33 | x = 'abcd' 34 | y = 'efghij' 35 | call swap(x,y(1:4)) ! x=efgh, y=abcdij 36 | end block 37 | 38 | block 39 | use stdlib_string_type 40 | type(string_type) :: x, y 41 | x = 'abcde' 42 | y = 'fghij' 43 | call swap(x,y) 44 | end block 45 | 46 | block 47 | use stdlib_bitsets 48 | type(bitset_64) :: x, y 49 | call x%from_string('0000') 50 | call y%from_string('1111') 51 | call swap(x,y) 52 | end block 53 | 54 | end program example_math_swap -------------------------------------------------------------------------------- /example/math/example_meshgrid.f90: -------------------------------------------------------------------------------- 1 | program example_meshgrid 2 | 3 | use stdlib_math, only: meshgrid, linspace, stdlib_meshgrid_ij 4 | use stdlib_kinds, only: sp 5 | 6 | implicit none 7 | 8 | integer, parameter :: nx = 3, ny = 2 9 | real(sp) :: x(nx), y(ny), & 10 | xm_cart(ny, nx), ym_cart(ny, nx), & 11 | xm_mat(nx, ny), ym_mat(nx, ny) 12 | 13 | x = linspace(0_sp, 1_sp, nx) 14 | y = linspace(0_sp, 1_sp, ny) 15 | 16 | call meshgrid(x, y, xm_cart, ym_cart) 17 | print *, "xm_cart = " 18 | call print_2d_array(xm_cart) 19 | print *, "ym_cart = " 20 | call print_2d_array(ym_cart) 21 | 22 | call meshgrid(x, y, xm_mat, ym_mat, indexing=stdlib_meshgrid_ij) 23 | print *, "xm_mat = " 24 | call print_2d_array(xm_mat) 25 | print *, "ym_mat = " 26 | call print_2d_array(ym_mat) 27 | 28 | contains 29 | subroutine print_2d_array(array) 30 | real(sp), intent(in) :: array(:, :) 31 | integer :: i 32 | 33 | do i = 1, size(array, dim=1) 34 | print *, array(i, :) 35 | end do 36 | end subroutine 37 | end program example_meshgrid 38 | -------------------------------------------------------------------------------- /example/optval/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(optval) 2 | -------------------------------------------------------------------------------- /example/optval/example_optval.f90: -------------------------------------------------------------------------------- 1 | program example_optval 2 | use stdlib_optval, only: optval 3 | implicit none 4 | print *, root(64.0) 5 | ! 8.0 6 | print *, root(64.0, 3) 7 | ! 4.0 8 | contains 9 | real function root(x, n) 10 | real, intent(in) :: x 11 | integer, intent(in), optional :: n 12 | root = x**(1.0/optval(n, 2)) 13 | end function root 14 | end program example_optval 15 | -------------------------------------------------------------------------------- /example/quadrature/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(gauss_legendre) 2 | ADD_EXAMPLE(gauss_legendre_lobatto) 3 | ADD_EXAMPLE(simps) 4 | ADD_EXAMPLE(simps_weights) 5 | ADD_EXAMPLE(trapz) 6 | ADD_EXAMPLE(trapz_weights) 7 | -------------------------------------------------------------------------------- /example/quadrature/example_gauss_legendre.f90: -------------------------------------------------------------------------------- 1 | program example_gauss_legendre 2 | use iso_fortran_env, dp => real64 3 | use stdlib_quadrature, only: gauss_legendre 4 | implicit none 5 | 6 | integer, parameter :: N = 6 7 | real(dp), dimension(N) :: x, w 8 | call gauss_legendre(x, w) 9 | print *, "integral of x**2 from -1 to 1 is", sum(x**2*w) 10 | end program example_gauss_legendre 11 | -------------------------------------------------------------------------------- /example/quadrature/example_gauss_legendre_lobatto.f90: -------------------------------------------------------------------------------- 1 | program example_gauss_legendre_lobatto 2 | use iso_fortran_env, dp => real64 3 | use stdlib_quadrature, only: gauss_legendre_lobatto 4 | implicit none 5 | 6 | integer, parameter :: N = 6 7 | real(dp), dimension(N) :: x, w 8 | call gauss_legendre_lobatto(x, w) 9 | print *, "integral of x**2 from -1 to 1 is", sum(x**2*w) 10 | end program example_gauss_legendre_lobatto 11 | -------------------------------------------------------------------------------- /example/quadrature/example_simps.f90: -------------------------------------------------------------------------------- 1 | program example_simps 2 | use stdlib_quadrature, only: simps 3 | implicit none 4 | real, parameter :: x(5) = [0., 1., 2., 3., 4.] 5 | real :: y(5) = 3.*x**2 6 | print *, simps(y, x) 7 | ! 64.0 8 | print *, simps(y, 0.5) 9 | ! 32.0 10 | end program example_simps 11 | -------------------------------------------------------------------------------- /example/quadrature/example_simps_weights.f90: -------------------------------------------------------------------------------- 1 | program example_simps_weights 2 | use stdlib_quadrature, only: simps_weights 3 | implicit none 4 | real, parameter :: x(5) = [0., 1., 2., 3., 4.] 5 | real :: y(5) = 3.*x**2 6 | real :: w(5) 7 | w = simps_weights(x) 8 | print *, sum(w*y) 9 | ! 64.0 10 | end program example_simps_weights 11 | -------------------------------------------------------------------------------- /example/quadrature/example_trapz.f90: -------------------------------------------------------------------------------- 1 | program example_trapz 2 | use stdlib_quadrature, only: trapz 3 | implicit none 4 | real, parameter :: x(5) = [0., 1., 2., 3., 4.] 5 | real :: y(5) = x**2 6 | print *, trapz(y, x) 7 | ! 22.0 8 | print *, trapz(y, 0.5) 9 | ! 11.0 10 | end program example_trapz 11 | -------------------------------------------------------------------------------- /example/quadrature/example_trapz_weights.f90: -------------------------------------------------------------------------------- 1 | program example_trapz_weights 2 | use stdlib_quadrature, only: trapz_weights 3 | implicit none 4 | real, parameter :: x(5) = [0., 1., 2., 3., 4.] 5 | real :: y(5) = x**2 6 | real :: w(5) 7 | w = trapz_weights(x) 8 | print *, sum(w*y) 9 | ! 22.0 10 | end program example_trapz_weights 11 | 12 | -------------------------------------------------------------------------------- /example/random/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(dist_rand) 2 | ADD_EXAMPLE(random_seed) 3 | -------------------------------------------------------------------------------- /example/random/example_dist_rand.f90: -------------------------------------------------------------------------------- 1 | program example_dist_rand 2 | use stdlib_kinds, only: int8, int16, int32, int64 3 | use stdlib_random, only: dist_rand, random_seed 4 | implicit none 5 | integer :: put, get 6 | 7 | put = 135792468 8 | call random_seed(put, get) ! set and get current value of seed 9 | print *, dist_rand(1_int8) ! random integer in [-2^7, 2^7 - 1] 10 | ! -90 11 | print *, dist_rand(1_int16) ! random integer in [-2^15, 2^15 - 1] 12 | ! -32725 13 | print *, dist_rand(1_int32) ! random integer in [-2^31, 2^31 - 1] 14 | ! -1601563881 15 | print *, dist_rand(1_int64) ! random integer in [-2^63, 2^63 - 1] 16 | ! 180977695517992208 17 | end program example_dist_rand 18 | -------------------------------------------------------------------------------- /example/random/example_random_seed.f90: -------------------------------------------------------------------------------- 1 | program example_random_seed 2 | use stdlib_random, only: random_seed 3 | implicit none 4 | integer :: seed_put, seed_get 5 | 6 | seed_put = 1234567 7 | call random_seed(seed_put, seed_get) ! set and get current value of seed 8 | end program example_random_seed 9 | -------------------------------------------------------------------------------- /example/selection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(arg_select) 2 | ADD_EXAMPLE(select) 3 | -------------------------------------------------------------------------------- /example/selection/example_arg_select.f90: -------------------------------------------------------------------------------- 1 | program example_arg_select 2 | use stdlib_selection, only: arg_select 3 | implicit none 4 | 5 | real, allocatable :: array(:) 6 | integer, allocatable :: indx(:) 7 | integer :: kth_smallest 8 | integer :: k 9 | 10 | array = [3., 2., 7., 4., 5., 1., 4., -1.] 11 | indx = [(k, k=1, size(array))] 12 | 13 | k = 2 14 | call arg_select(array, indx, k, kth_smallest) 15 | print *, array(kth_smallest) ! print 1.0 16 | 17 | k = 7 18 | ! Due to the previous call to arg_select, we know for sure this is in an 19 | ! index >= 2 20 | call arg_select(array, indx, k, kth_smallest, left=2) 21 | print *, array(kth_smallest) ! print 5.0 22 | 23 | k = 6 24 | ! Due to the previous two calls to arg_select, we know for sure this is in 25 | ! an index >= 2 and <= 7 26 | call arg_select(array, indx, k, kth_smallest, left=2, right=7) 27 | print *, array(kth_smallest) ! print 4.0 28 | 29 | end program example_arg_select 30 | -------------------------------------------------------------------------------- /example/selection/example_select.f90: -------------------------------------------------------------------------------- 1 | program example_select 2 | use stdlib_selection, only: select 3 | implicit none 4 | 5 | real, allocatable :: array(:) 6 | real :: kth_smallest 7 | integer :: k 8 | 9 | array = [3., 2., 7., 4., 5., 1., 4., -1.] 10 | 11 | k = 2 12 | call select(array, k, kth_smallest) 13 | print *, kth_smallest ! print 1.0 14 | 15 | k = 7 16 | ! Due to the previous call to select, we know for sure this is in an 17 | ! index >= 2 18 | call select(array, k, kth_smallest, left=2) 19 | print *, kth_smallest ! print 5.0 20 | 21 | k = 6 22 | ! Due to the previous two calls to select, we know for sure this is in 23 | ! an index >= 2 and <= 7 24 | call select(array, k, kth_smallest, left=2, right=7) 25 | print *, kth_smallest ! print 4.0 26 | 27 | end program example_select 28 | -------------------------------------------------------------------------------- /example/sorting/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(ord_sort) 2 | ADD_EXAMPLE(sort) 3 | ADD_EXAMPLE(sort_index) 4 | ADD_EXAMPLE(radix_sort) 5 | ADD_EXAMPLE(sort_bitset) 6 | -------------------------------------------------------------------------------- /example/sorting/example_ord_sort.f90: -------------------------------------------------------------------------------- 1 | program example_ord_sort 2 | use stdlib_sorting, only: ord_sort 3 | implicit none 4 | integer, allocatable :: array1(:), work(:) 5 | 6 | array1 = [5, 4, 3, 1, 10, 4, 9] 7 | allocate (work, mold=array1) 8 | call ord_sort(array1, work) 9 | print *, array1 !print [1, 3, 4, 4, 5, 9, 10] 10 | end program example_ord_sort 11 | -------------------------------------------------------------------------------- /example/sorting/example_radix_sort.f90: -------------------------------------------------------------------------------- 1 | program example_radix_sort 2 | use iso_fortran_env, only: int8, int16, dp => real64 3 | use stdlib_sorting, only: radix_sort 4 | implicit none 5 | integer(int8), allocatable :: arri8(:) 6 | integer(int16), allocatable :: arri16(:) 7 | real(dp) :: x 8 | real(dp), allocatable :: arrf64(:) 9 | 10 | arri8 = [-128, 127, 0, -1, 1] 11 | call radix_sort(arri8) 12 | print *, arri8 13 | 14 | arri16 = [-32767, 32767, 0, 0, -3, 2, -3] 15 | call radix_sort(arri16, reverse=.true.) 16 | print *, arri16 17 | 18 | allocate (arrf64(10)) 19 | x = 0.0_dp ! divide zero will arise compile error 20 | arrf64 = [1.0_dp/x, 0.0_dp, 0.0_dp/x, -1.0_dp/x, -0.0_dp, 1.0_dp, -1.0_dp, 3.45_dp, -3.14_dp, 3.44_dp] 21 | call radix_sort(arrf64) 22 | print *, arrf64 23 | ! Expected output: 24 | ! nan, -inf, -3.14, -1.0, -0.0, 0.0, 1.0, 3.44, 3.45, inf 25 | ! Note: the position of nan is undefined 26 | end program example_radix_sort 27 | -------------------------------------------------------------------------------- /example/sorting/example_sort.f90: -------------------------------------------------------------------------------- 1 | program example_sort 2 | use stdlib_sorting, only: sort 3 | implicit none 4 | integer, allocatable :: array(:) 5 | 6 | array = [5, 4, 3, 1, 10, 4, 9] 7 | call sort(array) 8 | print *, array !print [1, 3, 4, 4, 5, 9, 10] 9 | end program example_sort 10 | -------------------------------------------------------------------------------- /example/sorting/example_sort_index.f90: -------------------------------------------------------------------------------- 1 | program example_sort_index 2 | use stdlib_sorting, only: sort_index 3 | implicit none 4 | integer, allocatable :: array(:) 5 | integer, allocatable :: index(:) 6 | 7 | array = [5, 4, 3, 1, 10, 4, 9] 8 | allocate(index, mold=array) 9 | 10 | call sort_index(array, index) 11 | 12 | print *, array !print [1, 3, 4, 4, 5, 9, 10] 13 | print *, index !print [4, 3, 2, 6, 1, 7, 5] 14 | 15 | end program example_sort_index 16 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(elu) 2 | ADD_EXAMPLE(gaussian) 3 | ADD_EXAMPLE(gelu) 4 | ADD_EXAMPLE(leaky_relu) 5 | ADD_EXAMPLE(relu) 6 | ADD_EXAMPLE(selu) 7 | ADD_EXAMPLE(silu) 8 | ADD_EXAMPLE(softmax) 9 | ADD_EXAMPLE(logsoftmax) 10 | ADD_EXAMPLE(softplus) 11 | ADD_EXAMPLE(step) 12 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/example_elu.f90: -------------------------------------------------------------------------------- 1 | program example_elu 2 | use stdlib_kinds, only: sp 3 | use stdlib_math, only: linspace 4 | use stdlib_specialfunctions, only: elu 5 | implicit none 6 | integer, parameter :: n = 10 7 | real(sp) :: x(n), y(n) 8 | 9 | x = linspace(-2._sp, 2._sp, n) 10 | y = elu( x , 1.0 ) 11 | print *, y 12 | end program example_elu 13 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/example_gaussian.f90: -------------------------------------------------------------------------------- 1 | program example_gaussian 2 | use stdlib_kinds, only: sp 3 | use stdlib_math, only: linspace 4 | use stdlib_specialfunctions, only: gaussian 5 | implicit none 6 | integer, parameter :: n = 10 7 | real(sp) :: x(n), y(n) 8 | 9 | x = linspace(-2._sp, 2._sp, n) 10 | y = gaussian( x ) 11 | print *, y 12 | end program example_gaussian 13 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/example_gelu.f90: -------------------------------------------------------------------------------- 1 | program example_gelu 2 | use stdlib_kinds, only: sp 3 | use stdlib_math, only: linspace 4 | use stdlib_specialfunctions, only: gelu 5 | implicit none 6 | integer, parameter :: n = 10 7 | real(sp) :: x(n), y(n) 8 | 9 | x = linspace(-2._sp, 2._sp, n) 10 | y = gelu( x ) 11 | print *, y 12 | end program example_gelu 13 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/example_leaky_relu.f90: -------------------------------------------------------------------------------- 1 | program example_gelu 2 | use stdlib_kinds, only: sp 3 | use stdlib_math, only: linspace 4 | use stdlib_specialfunctions, only: leaky_relu 5 | implicit none 6 | integer, parameter :: n = 10 7 | real(sp) :: x(n), y(n) 8 | 9 | x = linspace(-2._sp, 2._sp, n) 10 | y = leaky_relu( x , 0.1_sp ) 11 | print *, y 12 | end program example_gelu 13 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/example_logsoftmax.f90: -------------------------------------------------------------------------------- 1 | program example_logsoftmax 2 | use stdlib_kinds, only: sp 3 | use stdlib_math, only: linspace 4 | use stdlib_specialfunctions, only: logsoftmax 5 | implicit none 6 | integer, parameter :: n = 10 7 | real(sp) :: x(n), y(n) 8 | 9 | x = linspace(-2._sp, 2._sp, n) 10 | y = logsoftmax( x ) 11 | print *, y 12 | end program example_logsoftmax 13 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/example_relu.f90: -------------------------------------------------------------------------------- 1 | program example_relu 2 | use stdlib_kinds, only: sp 3 | use stdlib_math, only: linspace 4 | use stdlib_specialfunctions, only: relu 5 | implicit none 6 | integer, parameter :: n = 10 7 | real(sp) :: x(n), y(n) 8 | 9 | x = linspace(-2._sp, 2._sp, n) 10 | y = relu( x ) 11 | print *, y 12 | end program example_relu 13 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/example_selu.f90: -------------------------------------------------------------------------------- 1 | program example_selu 2 | use stdlib_kinds, only: sp 3 | use stdlib_math, only: linspace 4 | use stdlib_specialfunctions, only: selu 5 | implicit none 6 | integer, parameter :: n = 10 7 | real(sp) :: x(n), y(n) 8 | 9 | x = linspace(-2._sp, 2._sp, n) 10 | y = selu( x ) 11 | print *, y 12 | end program example_selu 13 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/example_silu.f90: -------------------------------------------------------------------------------- 1 | program example_silu 2 | use stdlib_kinds, only: sp 3 | use stdlib_math, only: linspace 4 | use stdlib_specialfunctions, only: silu 5 | implicit none 6 | integer, parameter :: n = 10 7 | real(sp) :: x(n), y(n) 8 | 9 | x = linspace(-2._sp, 2._sp, n) 10 | y = silu( x ) 11 | print *, y 12 | end program example_silu 13 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/example_softmax.f90: -------------------------------------------------------------------------------- 1 | program example_softmax 2 | use stdlib_kinds, only: sp 3 | use stdlib_math, only: linspace 4 | use stdlib_specialfunctions, only: softmax 5 | implicit none 6 | integer, parameter :: n = 10 7 | real(sp) :: x(n), y(n) 8 | 9 | x = linspace(-2._sp, 2._sp, n) 10 | y = softmax( x ) 11 | print *, y 12 | end program example_softmax 13 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/example_softplus.f90: -------------------------------------------------------------------------------- 1 | program example_softplus 2 | use stdlib_kinds, only: sp 3 | use stdlib_math, only: linspace 4 | use stdlib_specialfunctions, only: softplus 5 | implicit none 6 | integer, parameter :: n = 10 7 | real(sp) :: x(n), y(n) 8 | 9 | x = linspace(-2._sp, 2._sp, n) 10 | y = softplus( x ) 11 | print *, y 12 | end program example_softplus 13 | -------------------------------------------------------------------------------- /example/specialfunctions_activations/example_step.f90: -------------------------------------------------------------------------------- 1 | program example_step 2 | use stdlib_kinds, only: sp 3 | use stdlib_math, only: linspace 4 | use stdlib_specialfunctions, only: step 5 | implicit none 6 | integer, parameter :: n = 10 7 | real(sp) :: x(n), y(n) 8 | 9 | x = linspace(-2._sp, 2._sp, n) 10 | y = step( x ) 11 | print *, y 12 | end program example_step 13 | -------------------------------------------------------------------------------- /example/specialfunctions_gamma/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(gamma) 2 | ADD_EXAMPLE(gamma_p) 3 | ADD_EXAMPLE(gamma_q) 4 | ADD_EXAMPLE(ligamma) 5 | ADD_EXAMPLE(log_factorial) 6 | ADD_EXAMPLE(log_gamma) 7 | ADD_EXAMPLE(uigamma) 8 | -------------------------------------------------------------------------------- /example/specialfunctions_gamma/example_gamma.f90: -------------------------------------------------------------------------------- 1 | program example_gamma 2 | use stdlib_kinds, only: sp, dp, int64 3 | use stdlib_specialfunctions_gamma, only: gamma 4 | implicit none 5 | 6 | integer :: i 7 | integer(int64) :: n 8 | real :: x 9 | real(dp) :: y 10 | complex(sp) :: z 11 | 12 | i = 10 13 | n = 15_int64 14 | x = 2.5 15 | y = 4.3_dp 16 | z = (2.3, 0.6) 17 | 18 | print *, gamma(i) !integer gives exact result 19 | ! 362880 20 | 21 | print *, gamma(n) 22 | ! 87178291200 23 | 24 | print *, gamma(x) ! intrinsic function call 25 | ! 1.32934034 26 | 27 | print *, gamma(y) ! intrinsic function call 28 | ! 8.8553433604540341 29 | 30 | print *, gamma(z) 31 | ! (0.988054395, 0.383354813) 32 | 33 | end program example_gamma 34 | -------------------------------------------------------------------------------- /example/specialfunctions_gamma/example_gamma_p.f90: -------------------------------------------------------------------------------- 1 | program example_gamma_p 2 | use stdlib_specialfunctions_gamma, only: rgp => regularized_gamma_p 3 | implicit none 4 | 5 | print *, rgp(3.0, 5.0) 6 | 7 | ! 0.875347972 8 | end program example_gamma_p 9 | -------------------------------------------------------------------------------- /example/specialfunctions_gamma/example_gamma_q.f90: -------------------------------------------------------------------------------- 1 | program example_gamma_q 2 | use stdlib_specialfunctions_gamma, only: rgq => regularized_gamma_q 3 | implicit none 4 | 5 | print *, rgq(3.0, 5.0) 6 | 7 | ! 0.124652028 8 | end program example_gamma_q 9 | -------------------------------------------------------------------------------- /example/specialfunctions_gamma/example_ligamma.f90: -------------------------------------------------------------------------------- 1 | program example_ligamma 2 | use stdlib_specialfunctions_gamma, only: lig => lower_incomplete_gamma 3 | implicit none 4 | integer :: p 5 | real :: p1 6 | 7 | p = 3 8 | p1 = 2.3 9 | print *, lig(p, -5.0) 10 | 11 | ! -2521.02417 12 | 13 | print *, lig(p1, 5.0) 14 | 15 | ! 1.09715652 16 | end program example_ligamma 17 | -------------------------------------------------------------------------------- /example/specialfunctions_gamma/example_log_factorial.f90: -------------------------------------------------------------------------------- 1 | program example_log_factorial 2 | use stdlib_kinds, only: int64 3 | use stdlib_specialfunctions_gamma, only: lf => log_factorial 4 | implicit none 5 | integer :: n 6 | 7 | n = 10 8 | print *, lf(n) 9 | 10 | ! 15.1044130 11 | 12 | print *, lf(35_int64) 13 | 14 | ! 92.1361771 15 | end program example_log_factorial 16 | -------------------------------------------------------------------------------- /example/specialfunctions_gamma/example_log_gamma.f90: -------------------------------------------------------------------------------- 1 | program example_log_gamma 2 | use stdlib_kinds, only: sp, dp 3 | use stdlib_specialfunctions_gamma, only: log_gamma 4 | implicit none 5 | 6 | integer :: i 7 | real :: x 8 | real(dp) :: y 9 | complex(sp) :: z 10 | 11 | i = 10 12 | x = 8.76 13 | y = x 14 | z = (5.345, -3.467) 15 | 16 | print *, log_gamma(i) !default single precision output 17 | !12.8018274 18 | 19 | print *, log_gamma(x) !intrinsic function call 20 | 21 | !10.0942659 22 | 23 | print *, log_gamma(y) !intrinsic function call 24 | 25 | !10.094265528673880 26 | 27 | print *, log_gamma(z) !same kind as input 28 | 29 | !(2.56165648, -5.73382425) 30 | 31 | end program example_log_gamma 32 | -------------------------------------------------------------------------------- /example/specialfunctions_gamma/example_uigamma.f90: -------------------------------------------------------------------------------- 1 | program example_uigamma 2 | use stdlib_specialfunctions_gamma, only: uig => upper_incomplete_gamma 3 | implicit none 4 | 5 | print *, uig(3, -5.0) 6 | 7 | !2523.02295 8 | 9 | print *, uig(2.3, 5.0) 10 | 11 | !6.95552528E-02 12 | end program example_uigamma 13 | -------------------------------------------------------------------------------- /example/stats/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(corr) 2 | ADD_EXAMPLE(cov) 3 | ADD_EXAMPLE(mean) 4 | ADD_EXAMPLE(median) 5 | ADD_EXAMPLE(moment) 6 | ADD_EXAMPLE(var) 7 | -------------------------------------------------------------------------------- /example/stats/example_corr.f90: -------------------------------------------------------------------------------- 1 | program example_corr 2 | use stdlib_stats, only: corr 3 | implicit none 4 | real :: x(1:6) = [1., 2., 3., 4., 5., 6.] 5 | real :: y(1:2, 1:3) = reshape([-1., 40., -3., 4., 10., 6.], [2, 3]) 6 | print *, corr(x, 1) !returns 1. 7 | print *, corr(y, 2) !returns reshape([ 1., -.32480, -.32480, 1. ], [ 2, 3]) 8 | end program example_corr 9 | -------------------------------------------------------------------------------- /example/stats/example_cov.f90: -------------------------------------------------------------------------------- 1 | program example_cov 2 | use stdlib_stats, only: cov 3 | implicit none 4 | real :: x(1:6) = [1., 2., 3., 4., 5., 6.] 5 | real :: y(1:2, 1:3) = reshape([1., 2., 3., 4., 5., 6.], [2, 3]) 6 | print *, cov(x, 1) !returns 3.5 7 | print *, cov(x, 1, corrected=.false.) !returns 2.9167 8 | print *, cov(y, 1) !returns a square matrix of size 3 with all elements equal to 0.5 9 | end program example_cov 10 | -------------------------------------------------------------------------------- /example/stats/example_mean.f90: -------------------------------------------------------------------------------- 1 | program example_mean 2 | use stdlib_stats, only: mean 3 | implicit none 4 | real :: x(1:6) = [1., 2., 3., 4., 5., 6.] 5 | real :: y(1:2, 1:3) = reshape([1., 2., 3., 4., 5., 6.], [2, 3]) 6 | print *, mean(x) !returns 3.5 7 | print *, mean(y) !returns 3.5 8 | print *, mean(y, 1) !returns [ 1.5, 3.5, 5.5 ] 9 | print *, mean(y, 1, y > 3.) !returns [ NaN, 4.0, 5.5 ] 10 | end program example_mean 11 | -------------------------------------------------------------------------------- /example/stats/example_median.f90: -------------------------------------------------------------------------------- 1 | program example_median 2 | use stdlib_stats, only: median 3 | implicit none 4 | real :: x(1:6) = [1., 2., 3., 4., 5., 6.] 5 | real :: y(1:2, 1:3) = reshape([1., 2., 3., 4., 5., 6.], [2, 3]) 6 | print *, median(x) !returns 3.5 7 | print *, median(y) !returns 3.5 8 | print *, median(y, 1) !returns [ 1.5, 3.5, 5.5 ] 9 | print *, median(y, 1, y > 3.) !returns [ NaN, 4.0, 5.5 ] 10 | end program example_median 11 | -------------------------------------------------------------------------------- /example/stats/example_moment.f90: -------------------------------------------------------------------------------- 1 | program example_moment 2 | use stdlib_stats, only: moment 3 | implicit none 4 | real :: x(1:6) = [1., 2., 3., 4., 5., 6.] 5 | real :: y(1:2, 1:3) = reshape([1., 2., 3., 4., 5., 6.], [2, 3]) 6 | print *, moment(x, 2) !returns 2.9167 7 | print *, moment(y, 2) !returns 2.9167 8 | print *, moment(y, 2, 1) !returns [0.25, 0.25, 0.25] 9 | print *, moment(y, 2, 1, mask=(y > 3.)) !returns [NaN, 0., 0.25] 10 | print *, moment(x, 2, center=0.) !returns 15.1667 11 | print *, moment(y, 1, 1, center=0.) !returns [1.5, 3.5, 5.5] 12 | end program example_moment 13 | -------------------------------------------------------------------------------- /example/stats/example_var.f90: -------------------------------------------------------------------------------- 1 | program example_var 2 | use stdlib_stats, only: var 3 | implicit none 4 | real :: x(1:6) = [1., 2., 3., 4., 5., 6.] 5 | real :: y(1:2, 1:3) = reshape([1., 2., 3., 4., 5., 6.], [2, 3]) 6 | print *, var(x) !returns 3.5 7 | print *, var(x, corrected=.false.) !returns 2.9167 8 | print *, var(y) !returns 3.5 9 | print *, var(y, 1) !returns [0.5, 0.5, 0.5] 10 | print *, var(y, 1, y > 3.) !returns [NaN, NaN, 0.5] 11 | print *, var(y, 1, y > 3., corrected=.false.) !returns [NaN, 0., 0.25] 12 | end program example_var 13 | -------------------------------------------------------------------------------- /example/stats_distribution_exponential/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(exponential_cdf) 2 | ADD_EXAMPLE(exponential_pdf) 3 | ADD_EXAMPLE(exponential_rvs) 4 | -------------------------------------------------------------------------------- /example/stats_distribution_normal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(normal_pdf) 2 | ADD_EXAMPLE(normal_rvs) 3 | ADD_EXAMPLE(normal_cdf) 4 | -------------------------------------------------------------------------------- /example/stats_distribution_uniform/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(shuffle) 2 | ADD_EXAMPLE(uniform_cdf) 3 | ADD_EXAMPLE(uniform_pdf) 4 | ADD_EXAMPLE(uniform_rvs) 5 | -------------------------------------------------------------------------------- /example/stats_distribution_uniform/example_shuffle.f90: -------------------------------------------------------------------------------- 1 | program example_shuffle 2 | use stdlib_random, only: random_seed 3 | use stdlib_stats_distribution_uniform, only: shuffle 4 | implicit none 5 | integer :: seed_put, seed_get, i 6 | real :: x(10) 7 | integer :: n(10) 8 | complex :: z(10) 9 | 10 | do i = 1, 10 11 | n(i) = i 12 | x(i) = real(i) 13 | z(i) = cmplx(real(i), real(i)) 14 | end do 15 | seed_put = 32165498 16 | call random_seed(seed_put, seed_get) ! set and get current value of seed 17 | print *, shuffle(n) ! get randomized n 18 | 19 | !10 6 9 2 8 1 3 5 7 4 20 | 21 | print *, shuffle(x) ! get randomized x 22 | 23 | !5.0 10.0 9.0 4.0 3.0 8.0 2.0 1.0 7.0 6.0 24 | 25 | print *, shuffle(z) ! get randomized z 26 | 27 | !(8.0, 8.0) (7.0, 7.0) (4.0, 4.0) (1.0, 1.0) (5.0, 5.0) 28 | !(9.0, 9.0) (6.0, 6.0) (3.0, 3.0) (2.0, 2.0) (10.0, 10.0) 29 | 30 | end program example_shuffle 31 | -------------------------------------------------------------------------------- /example/string_type/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(adjustl) 2 | ADD_EXAMPLE(adjustr) 3 | ADD_EXAMPLE(char) 4 | ADD_EXAMPLE(char_position) 5 | ADD_EXAMPLE(char_range) 6 | ADD_EXAMPLE(constructor_character) 7 | ADD_EXAMPLE(constructor_empty) 8 | ADD_EXAMPLE(constructor_integer) 9 | ADD_EXAMPLE(constructor_logical) 10 | ADD_EXAMPLE(constructor_scalar) 11 | ADD_EXAMPLE(cont) 12 | ADD_EXAMPLE(eq) 13 | ADD_EXAMPLE(fread) 14 | ADD_EXAMPLE(fwrite) 15 | ADD_EXAMPLE(ge) 16 | ADD_EXAMPLE(gt) 17 | ADD_EXAMPLE(iachar) 18 | ADD_EXAMPLE(ichar) 19 | ADD_EXAMPLE(index) 20 | ADD_EXAMPLE(le) 21 | ADD_EXAMPLE(len) 22 | ADD_EXAMPLE(len_trim) 23 | ADD_EXAMPLE(lge) 24 | ADD_EXAMPLE(lgt) 25 | ADD_EXAMPLE(lle) 26 | ADD_EXAMPLE(llt) 27 | ADD_EXAMPLE(lt) 28 | ADD_EXAMPLE(move) 29 | ADD_EXAMPLE(ne) 30 | ADD_EXAMPLE(repeat) 31 | ADD_EXAMPLE(reverse) 32 | ADD_EXAMPLE(scan) 33 | ADD_EXAMPLE(to_lower) 34 | ADD_EXAMPLE(to_sentence) 35 | ADD_EXAMPLE(to_title) 36 | ADD_EXAMPLE(to_upper) 37 | ADD_EXAMPLE(trim) 38 | ADD_EXAMPLE(uread) 39 | ADD_EXAMPLE(uwrite) 40 | ADD_EXAMPLE(verify) 41 | -------------------------------------------------------------------------------- /example/string_type/example_adjustl.f90: -------------------------------------------------------------------------------- 1 | program example_adjustl 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | 6 | string = " Whitespace" 7 | string = adjustl(string) 8 | ! char(string) == "Whitespace " 9 | end program example_adjustl 10 | -------------------------------------------------------------------------------- /example/string_type/example_adjustr.f90: -------------------------------------------------------------------------------- 1 | program example_adjustr 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | 6 | string = "Whitespace " 7 | string = adjustr(string) 8 | ! char(string) == " Whitespace" 9 | end program example_adjustr 10 | -------------------------------------------------------------------------------- /example/string_type/example_char.f90: -------------------------------------------------------------------------------- 1 | program example_char 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | character(len=:), allocatable :: dlc 6 | 7 | string = "Character sequence" 8 | dlc = char(string) 9 | ! dlc == "Character sequence" 10 | end program example_char 11 | -------------------------------------------------------------------------------- /example/string_type/example_char_position.f90: -------------------------------------------------------------------------------- 1 | program example_char_position 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | character(len=:), allocatable :: dlc 6 | character(len=1), allocatable :: chars(:) 7 | 8 | string = "Character sequence" 9 | dlc = char(string, 3) 10 | ! dlc == "a" 11 | chars = char(string, [3, 5, 8, 12, 14, 15, 18]) 12 | ! chars == ["a", "a", "e", "e", "u", "e", "e"] 13 | end program example_char_position 14 | -------------------------------------------------------------------------------- /example/string_type/example_char_range.f90: -------------------------------------------------------------------------------- 1 | program example_char_range 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | character(len=:), allocatable :: dlc 6 | 7 | string = "Fortran" 8 | dlc = char(string, 1, 4) 9 | ! dlc == "Fort" 10 | end program example_char_range 11 | -------------------------------------------------------------------------------- /example/string_type/example_constructor_character.f90: -------------------------------------------------------------------------------- 1 | program example_constructor_character 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | ! len(string) == 0 6 | string = "Sequence" 7 | ! len(string) == 8 8 | end program example_constructor_character 9 | -------------------------------------------------------------------------------- /example/string_type/example_constructor_empty.f90: -------------------------------------------------------------------------------- 1 | program example_constructor_empty 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | string = string_type() 6 | ! len(string) == 0 7 | end program example_constructor_empty 8 | -------------------------------------------------------------------------------- /example/string_type/example_constructor_integer.f90: -------------------------------------------------------------------------------- 1 | program example_constructor_integer 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | string = string_type(42) 6 | ! len(string) == 2 7 | string = string_type(-289) 8 | ! len(string) == 4 9 | end program example_constructor_integer 10 | -------------------------------------------------------------------------------- /example/string_type/example_constructor_logical.f90: -------------------------------------------------------------------------------- 1 | program example_constructor_logical 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | string = string_type(.true.) 6 | ! len(string) == 1 7 | string = string_type(.false.) 8 | ! len(string) == 1 9 | end program example_constructor_logical 10 | -------------------------------------------------------------------------------- /example/string_type/example_constructor_scalar.f90: -------------------------------------------------------------------------------- 1 | program example_constructor_scalar 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | string = string_type("Sequence") 6 | ! len(string) == 8 7 | string = string_type(" S p a c e d ") 8 | ! len(string) == 13 9 | end program example_constructor_scalar 10 | -------------------------------------------------------------------------------- /example/string_type/example_cont.f90: -------------------------------------------------------------------------------- 1 | program example_cont 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | 6 | string = "Hello, " 7 | string = string//"World!" 8 | ! len(string) == 13 9 | end program example_cont 10 | -------------------------------------------------------------------------------- /example/string_type/example_eq.f90: -------------------------------------------------------------------------------- 1 | program example_eq 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | logical :: res 6 | 7 | string = "bcd" 8 | res = string == "abc" 9 | ! res .eqv. .false. 10 | 11 | res = string == "bcd" 12 | ! res .eqv. .true. 13 | 14 | res = string == "cde" 15 | ! res .eqv. .false. 16 | end program example_eq 17 | -------------------------------------------------------------------------------- /example/string_type/example_fread.f90: -------------------------------------------------------------------------------- 1 | program example_fread 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | integer :: io 6 | string = "Important saved value" 7 | 8 | open (newunit=io, form="formatted", status="scratch") 9 | write (io, *) string 10 | write (io, *) 11 | 12 | rewind (io) 13 | 14 | read (io, *) string 15 | close (io) 16 | end program example_fread 17 | -------------------------------------------------------------------------------- /example/string_type/example_fwrite.f90: -------------------------------------------------------------------------------- 1 | program example_fwrite 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | integer :: io 6 | string = "Important saved value" 7 | 8 | open (newunit=io, form="formatted", status="scratch") 9 | write (io, *) string 10 | write (io, *) 11 | 12 | rewind (io) 13 | 14 | read (io, *) string 15 | close (io) 16 | end program example_fwrite 17 | -------------------------------------------------------------------------------- /example/string_type/example_ge.f90: -------------------------------------------------------------------------------- 1 | program example_ge 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | logical :: res 6 | 7 | string = "bcd" 8 | res = string >= "abc" 9 | ! res .eqv. .true. 10 | 11 | res = string >= "bcd" 12 | ! res .eqv. .true. 13 | 14 | res = string >= "cde" 15 | ! res .eqv. .false. 16 | end program example_ge 17 | -------------------------------------------------------------------------------- /example/string_type/example_gt.f90: -------------------------------------------------------------------------------- 1 | program example_gt 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | logical :: res 6 | 7 | string = "bcd" 8 | res = string > "abc" 9 | ! res .eqv. .true. 10 | 11 | res = string > "bcd" 12 | ! res .eqv. .false. 13 | 14 | res = string > "cde" 15 | ! res .eqv. .false. 16 | end program example_gt 17 | -------------------------------------------------------------------------------- /example/string_type/example_iachar.f90: -------------------------------------------------------------------------------- 1 | program example_iachar 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | integer :: code 6 | 7 | string = "Fortran" 8 | code = iachar(string) 9 | end program example_iachar 10 | -------------------------------------------------------------------------------- /example/string_type/example_ichar.f90: -------------------------------------------------------------------------------- 1 | program example_ichar 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | integer :: code 6 | 7 | string = "Fortran" 8 | code = ichar(string) 9 | end program example_ichar 10 | -------------------------------------------------------------------------------- /example/string_type/example_index.f90: -------------------------------------------------------------------------------- 1 | program example_index 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | integer :: pos 6 | 7 | string = "Search this string for this expression" 8 | pos = index(string, "this") 9 | ! pos == 8 10 | 11 | pos = index(string, "this", back=.true.) 12 | ! pos == 24 13 | 14 | pos = index(string, "This") 15 | ! pos == 0 16 | end program example_index 17 | -------------------------------------------------------------------------------- /example/string_type/example_le.f90: -------------------------------------------------------------------------------- 1 | program example_le 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | logical :: res 6 | 7 | string = "bcd" 8 | res = string <= "abc" 9 | ! res .eqv. .false. 10 | 11 | res = string <= "bcd" 12 | ! res .eqv. .true. 13 | 14 | res = string <= "cde" 15 | ! res .eqv. .true. 16 | end program example_le 17 | -------------------------------------------------------------------------------- /example/string_type/example_len.f90: -------------------------------------------------------------------------------- 1 | program example_len 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | integer :: length 6 | 7 | string = "Some longer sentence for this example." 8 | length = len(string) 9 | ! length == 38 10 | 11 | string = "Whitespace " 12 | length = len(string) 13 | ! length == 38 14 | end program example_len 15 | -------------------------------------------------------------------------------- /example/string_type/example_len_trim.f90: -------------------------------------------------------------------------------- 1 | program example_len_trim 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | integer :: length 6 | 7 | string = "Some longer sentence for this example." 8 | length = len_trim(string) 9 | ! length == 38 10 | 11 | string = "Whitespace " 12 | length = len_trim(string) 13 | ! length == 10 14 | end program example_len_trim 15 | -------------------------------------------------------------------------------- /example/string_type/example_lge.f90: -------------------------------------------------------------------------------- 1 | program example_lge 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | logical :: res 6 | 7 | string = "bcd" 8 | res = lge(string, "abc") 9 | ! res .eqv. .true. 10 | 11 | res = lge(string, "bcd") 12 | ! res .eqv. .true. 13 | 14 | res = lge(string, "cde") 15 | ! res .eqv. .false. 16 | end program example_lge 17 | -------------------------------------------------------------------------------- /example/string_type/example_lgt.f90: -------------------------------------------------------------------------------- 1 | program example_lgt 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | logical :: res 6 | 7 | string = "bcd" 8 | res = lgt(string, "abc") 9 | ! res .eqv. .true. 10 | 11 | res = lgt(string, "bcd") 12 | ! res .eqv. .false. 13 | 14 | res = lgt(string, "cde") 15 | ! res .eqv. .false. 16 | end program example_lgt 17 | -------------------------------------------------------------------------------- /example/string_type/example_lle.f90: -------------------------------------------------------------------------------- 1 | program example_lle 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | logical :: res 6 | 7 | string = "bcd" 8 | res = lle(string, "abc") 9 | ! res .eqv. .false. 10 | 11 | res = lle(string, "bcd") 12 | ! res .eqv. .true. 13 | 14 | res = lle(string, "cde") 15 | ! res .eqv. .true. 16 | end program example_lle 17 | -------------------------------------------------------------------------------- /example/string_type/example_llt.f90: -------------------------------------------------------------------------------- 1 | program example_llt 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | logical :: res 6 | 7 | string = "bcd" 8 | res = llt(string, "abc") 9 | ! res .eqv. .false. 10 | 11 | res = llt(string, "bcd") 12 | ! res .eqv. .false. 13 | 14 | res = llt(string, "cde") 15 | ! res .eqv. .true. 16 | end program example_llt 17 | -------------------------------------------------------------------------------- /example/string_type/example_lt.f90: -------------------------------------------------------------------------------- 1 | program example_lt 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | logical :: res 6 | 7 | string = "bcd" 8 | res = string < "abc" 9 | ! res .eqv. .false. 10 | 11 | res = string < "bcd" 12 | ! res .eqv. .false. 13 | 14 | res = string < "cde" 15 | ! res .eqv. .true. 16 | end program example_lt 17 | -------------------------------------------------------------------------------- /example/string_type/example_move.f90: -------------------------------------------------------------------------------- 1 | program example_move 2 | use stdlib_string_type, only: string_type, assignment(=), move 3 | implicit none 4 | type(string_type) :: from_string 5 | character(len=:), allocatable :: from_char, to_char 6 | 7 | from_string = "move this string" 8 | from_char = "move this char" 9 | ! from_string <-- "move this string" 10 | ! from_char <-- "move this char" 11 | ! to_char <-- (unallocated) 12 | 13 | call move(from_string, to_char) 14 | ! from_string <-- "" 15 | ! to_char <-- "move this string" 16 | 17 | call move(from_char, to_char) 18 | ! from_char <-- (unallocated) 19 | ! to_string <-- "move this char" 20 | 21 | end program example_move 22 | -------------------------------------------------------------------------------- /example/string_type/example_ne.f90: -------------------------------------------------------------------------------- 1 | program example_ne 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | logical :: res 6 | 7 | string = "bcd" 8 | res = string /= "abc" 9 | ! res .eqv. .true. 10 | 11 | res = string /= "bcd" 12 | ! res .eqv. .false. 13 | 14 | res = string /= "cde" 15 | ! res .eqv. .true. 16 | end program example_ne 17 | -------------------------------------------------------------------------------- /example/string_type/example_repeat.f90: -------------------------------------------------------------------------------- 1 | program example_repeat 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | 6 | string = "What? " 7 | string = repeat(string, 3) 8 | ! string == "What? What? What? " 9 | end program example_repeat 10 | -------------------------------------------------------------------------------- /example/string_type/example_reverse.f90: -------------------------------------------------------------------------------- 1 | program example_reverse 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string, reverse_string 5 | 6 | string = "Reverse This String" 7 | ! string <-- "Reverse This String" 8 | 9 | reverse_string = reverse(string) 10 | ! string <-- "Reverse This String" 11 | ! reverse_string <-- "gnirtS sihT esreveR" 12 | end program example_reverse 13 | -------------------------------------------------------------------------------- /example/string_type/example_scan.f90: -------------------------------------------------------------------------------- 1 | program example_scan 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | integer :: pos 6 | 7 | string = "fortran" 8 | pos = scan(string, "ao") 9 | ! pos == 2 10 | 11 | pos = scan(string, "ao", .true.) 12 | ! pos == 6 13 | 14 | pos = scan(string, "c++") 15 | ! pos == 0 16 | end program example_scan 17 | -------------------------------------------------------------------------------- /example/string_type/example_to_lower.f90: -------------------------------------------------------------------------------- 1 | program example_to_lower 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string, lowercase_string 5 | 6 | string = "Lowercase This String" 7 | ! string <-- "Lowercase This String" 8 | 9 | lowercase_string = to_lower(string) 10 | ! string <-- "Lowercase This String" 11 | ! lowercase_string <-- "lowercase this string" 12 | end program example_to_lower 13 | -------------------------------------------------------------------------------- /example/string_type/example_to_sentence.f90: -------------------------------------------------------------------------------- 1 | program example_to_sentence 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string, sentencecase_string 5 | 6 | string = "sentencecase this string." 7 | ! string <-- "sentencecase this string." 8 | 9 | sentencecase_string = to_sentence(string) 10 | ! string <-- "sentencecase this string." 11 | ! sentencecase_string <-- "Sentencecase this string." 12 | end program example_to_sentence 13 | -------------------------------------------------------------------------------- /example/string_type/example_to_title.f90: -------------------------------------------------------------------------------- 1 | program example_to_title 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string, titlecase_string 5 | 6 | string = "titlecase this string." 7 | ! string <-- "titlecase this string." 8 | 9 | titlecase_string = to_title(string) 10 | ! string <-- "titlecase this string." 11 | ! titlecase_string <-- "Titlecase This String." 12 | end program example_to_title 13 | -------------------------------------------------------------------------------- /example/string_type/example_to_upper.f90: -------------------------------------------------------------------------------- 1 | program example_to_upper 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string, uppercase_string 5 | 6 | string = "Uppercase This String" 7 | ! string <-- "Uppercase This String" 8 | 9 | uppercase_string = to_upper(string) 10 | ! string <-- "Uppercase This String" 11 | ! uppercase_string <-- "UPPERCASE THIS STRING" 12 | end program example_to_upper 13 | -------------------------------------------------------------------------------- /example/string_type/example_trim.f90: -------------------------------------------------------------------------------- 1 | program example_trim 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | 6 | string = "Whitespace " 7 | string = trim(string) 8 | ! len(string) == 10 9 | end program example_trim 10 | -------------------------------------------------------------------------------- /example/string_type/example_uread.f90: -------------------------------------------------------------------------------- 1 | program example_uread 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | integer :: io 6 | string = "Important saved value" 7 | 8 | open (newunit=io, form="unformatted", status="scratch") 9 | write (io) string 10 | 11 | rewind (io) 12 | 13 | read (io) string 14 | close (io) 15 | end program example_uread 16 | -------------------------------------------------------------------------------- /example/string_type/example_uwrite.f90: -------------------------------------------------------------------------------- 1 | program example_uwrite 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | integer :: io 6 | string = "Important saved value" 7 | 8 | open (newunit=io, form="unformatted", status="scratch") 9 | write (io) string 10 | 11 | rewind (io) 12 | 13 | read (io) string 14 | close (io) 15 | end program example_uwrite 16 | -------------------------------------------------------------------------------- /example/string_type/example_verify.f90: -------------------------------------------------------------------------------- 1 | program example_verify 2 | use stdlib_string_type 3 | implicit none 4 | type(string_type) :: string 5 | integer :: pos 6 | 7 | string = "fortran" 8 | pos = verify(string, "ao") 9 | ! pos == 1 10 | 11 | pos = verify(string, "fo") 12 | ! pos == 3 13 | 14 | pos = verify(string, "c++") 15 | ! pos == 1 16 | 17 | pos = verify(string, "c++", back=.true.) 18 | ! pos == 7 19 | 20 | pos = verify(string, string) 21 | ! pos == 0 22 | end program example_verify 23 | -------------------------------------------------------------------------------- /example/stringlist_type/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(stringlist_type_clear) 2 | ADD_EXAMPLE(stringlist_type_concatenate_operator) 3 | ADD_EXAMPLE(stringlist_type_constructor) 4 | ADD_EXAMPLE(stringlist_type_equality_operator) 5 | ADD_EXAMPLE(stringlist_type_fidx_bidx) 6 | ADD_EXAMPLE(stringlist_type_get) 7 | ADD_EXAMPLE(stringlist_type_inequality_operator) 8 | ADD_EXAMPLE(stringlist_type_insert_at) 9 | ADD_EXAMPLE(stringlist_type_len) 10 | -------------------------------------------------------------------------------- /example/stringlist_type/example_stringlist_type_clear.f90: -------------------------------------------------------------------------------- 1 | program example_clear 2 | use stdlib_stringlist_type, only: stringlist_type, fidx 3 | implicit none 4 | 5 | type(stringlist_type) :: stringlist 6 | 7 | !> inserting 2 elements to the stringlist 8 | call stringlist%insert_at(fidx(1), "Element No. one") 9 | call stringlist%insert_at(fidx(1), "Element No. two") 10 | ! stringlist <-- {"Element No. two", "Element No. one"} 11 | 12 | call stringlist%clear() 13 | ! stringlist <-- { } (empty stringlist) 14 | 15 | !> inserting 1 element to the stringlist 16 | call stringlist%insert_at(fidx(1), "Element No. one") 17 | ! stringlist <-- {"Element No. one"} 18 | 19 | end program example_clear 20 | -------------------------------------------------------------------------------- /example/stringlist_type/example_stringlist_type_constructor.f90: -------------------------------------------------------------------------------- 1 | program example_constructor 2 | use stdlib_stringlist_type, only: stringlist_type 3 | use stdlib_string_type, only: string_type 4 | implicit none 5 | 6 | type(stringlist_type) :: stringlist 7 | 8 | stringlist = stringlist_type() 9 | ! stringlist <-- { } (empty stringlist) 10 | 11 | stringlist = stringlist_type(["#1", "#2", "#3"]) 12 | ! stringlist <-- {"#1", "#2", "#3"} 13 | 14 | stringlist = stringlist_type([string_type("#1"), string_type("#2")]) 15 | ! stringlist <-- {"#1", "#2"} 16 | 17 | end program example_constructor 18 | -------------------------------------------------------------------------------- /example/stringlist_type/example_stringlist_type_equality_operator.f90: -------------------------------------------------------------------------------- 1 | program example_equality_operator 2 | use stdlib_stringlist_type, only: stringlist_type, fidx, list_head, operator(==) 3 | use stdlib_string_type, only: string_type 4 | implicit none 5 | 6 | type(stringlist_type) :: stringlist 7 | type(string_type), allocatable :: stringarray(:) 8 | logical :: res 9 | 10 | !> inserting 4 elements to the stringlist 11 | call stringlist%insert_at(fidx(1), "#1") 12 | call stringlist%insert_at(list_head, "#2") 13 | call stringlist%insert_at(fidx(1), "#3") 14 | call stringlist%insert_at(list_head, "#4") 15 | ! stringlist <-- {"#4", "#3", "#2", "#1"} 16 | 17 | !> creating an array of 4 string_type elements 18 | stringarray = [string_type("#4"), string_type("#3"), string_type("#2"), string_type("#1")] 19 | 20 | res = (stringarray == stringlist) 21 | ! res <-- .true. 22 | 23 | res = (stringlist == ["#4", "#3", "#2", "#1"]) 24 | ! res <-- .true. 25 | 26 | print'(a)', stringlist == ["#4", "#3", "#1"] 27 | ! .false. 28 | 29 | end program example_equality_operator 30 | -------------------------------------------------------------------------------- /example/stringlist_type/example_stringlist_type_fidx_bidx.f90: -------------------------------------------------------------------------------- 1 | program example_fidx_bidx 2 | use stdlib_stringlist_type, only: stringlist_index_type, fidx, bidx 3 | implicit none 4 | 5 | type(stringlist_index_type) :: index 6 | 7 | index = fidx(1) 8 | ! forward index 1 9 | 10 | index = bidx(3) 11 | ! backward index 3 12 | 13 | end program example_fidx_bidx 14 | -------------------------------------------------------------------------------- /example/stringlist_type/example_stringlist_type_get.f90: -------------------------------------------------------------------------------- 1 | program example_get 2 | use stdlib_stringlist_type, only: stringlist_type, fidx, bidx 3 | use stdlib_string_type, only: string_type 4 | implicit none 5 | 6 | type(stringlist_type) :: stringlist 7 | type(string_type) :: output 8 | 9 | !> inserting 4 elements to the stringlist 10 | call stringlist%insert_at(fidx(1), "Element No. one") 11 | call stringlist%insert_at(fidx(1), "Element No. two") 12 | call stringlist%insert_at(fidx(1), "Element No. three") 13 | call stringlist%insert_at(fidx(1), "Element No. four") 14 | ! stringlist <-- {"Element No. four", "Element No. three", "Element No. two", "Element No. one"} 15 | 16 | output = stringlist%get(fidx(1)) 17 | ! output <-- "Element No. four" 18 | 19 | output = stringlist%get(bidx(1)) 20 | ! output <-- "Element No. one" 21 | 22 | !> accessing out of bounds index 23 | output = stringlist%get(bidx(5)) 24 | ! output <-- "" 25 | output = stringlist%get(fidx(0)) 26 | ! output <-- "" 27 | 28 | end program example_get 29 | -------------------------------------------------------------------------------- /example/stringlist_type/example_stringlist_type_inequality_operator.f90: -------------------------------------------------------------------------------- 1 | program example_inequality_operator 2 | use stdlib_stringlist_type, only: stringlist_type, bidx, list_tail, operator(/=) 3 | use stdlib_string_type, only: string_type 4 | implicit none 5 | 6 | type(stringlist_type) :: stringlist 7 | type(string_type), allocatable :: stringarray(:) 8 | logical :: res 9 | 10 | !> inserting 4 elements to the stringlist 11 | call stringlist%insert_at(bidx(1), "#1") 12 | call stringlist%insert_at(list_tail, "#2") 13 | call stringlist%insert_at(bidx(1), "#3") 14 | call stringlist%insert_at(list_tail, "#4") 15 | ! stringlist <-- {"#1", "#2", "#3", "#4"} 16 | 17 | !> creating an array of 4 string_type elements 18 | stringarray = [string_type("#1"), string_type("#2"), string_type("#3"), string_type("#4")] 19 | 20 | res = (stringarray /= stringlist) 21 | ! res <-- .false. 22 | 23 | res = (stringlist /= ["#111", "#222", "#333", "#444"]) 24 | ! res <-- .true. 25 | 26 | print'(a)', stringlist /= ["#4", "#3", "#1"] 27 | ! .true. 28 | 29 | end program example_inequality_operator 30 | -------------------------------------------------------------------------------- /example/stringlist_type/example_stringlist_type_insert_at.f90: -------------------------------------------------------------------------------- 1 | program example_insert_at 2 | use stdlib_stringlist_type, only: stringlist_type, stringlist_index_type, fidx, bidx 3 | use stdlib_string_type, only: string_type 4 | implicit none 5 | 6 | type(stringlist_type) :: stringlist 7 | type(stringlist_index_type) :: index 8 | 9 | index = fidx(1) 10 | call stringlist%insert_at(index, "Element No. one") 11 | ! stringlist <-- {"Element No. one"} 12 | 13 | index = bidx(1) 14 | call stringlist%insert_at(index, string_type("Element No. two")) 15 | ! stringlist <-- {"Element No. one", "Element No. two"} 16 | 17 | call stringlist%insert_at(fidx(2), string_type("Element No. three")) 18 | ! stringlist <-- {"Element No. one", "Element No. three", "Element No. two"} 19 | 20 | call stringlist%insert_at(bidx(1), "Element No. four") 21 | ! stringlist <-- {"Element No. one", "Element No. three", "Element No. two", "Element No. four"} 22 | 23 | end program example_insert_at 24 | -------------------------------------------------------------------------------- /example/stringlist_type/example_stringlist_type_len.f90: -------------------------------------------------------------------------------- 1 | program example_len 2 | use stdlib_stringlist_type, only: stringlist_type, bidx 3 | implicit none 4 | 5 | type(stringlist_type) :: stringlist 6 | integer :: output 7 | 8 | output = stringlist%len() 9 | ! output <-- 0 10 | 11 | !> inserting 2 elements to the stringlist 12 | call stringlist%insert_at(bidx(1), "Element No. one") 13 | call stringlist%insert_at(bidx(1), "Element No. two") 14 | ! stringlist <-- {"Element No. one", "Element No. two"} 15 | 16 | print'(a)', stringlist%len() 17 | ! 2 18 | 19 | end program example_len 20 | -------------------------------------------------------------------------------- /example/strings/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(chomp) 2 | ADD_EXAMPLE(count) 3 | ADD_EXAMPLE(ends_with) 4 | ADD_EXAMPLE(find) 5 | ADD_EXAMPLE(join) 6 | ADD_EXAMPLE(padl) 7 | ADD_EXAMPLE(padr) 8 | ADD_EXAMPLE(replace_all) 9 | ADD_EXAMPLE(slice) 10 | ADD_EXAMPLE(starts_with) 11 | ADD_EXAMPLE(strip) 12 | ADD_EXAMPLE(to_string) 13 | ADD_EXAMPLE(to_c_char) 14 | ADD_EXAMPLE(zfill) 15 | ADD_EXAMPLE(string_to_number) 16 | ADD_EXAMPLE(stream_of_strings_to_numbers) 17 | -------------------------------------------------------------------------------- /example/strings/example_chomp.f90: -------------------------------------------------------------------------------- 1 | program example_chomp 2 | use stdlib_ascii, only: TAB, VT, LF, CR, FF 3 | use stdlib_strings, only: chomp 4 | implicit none 5 | print'(a)', chomp(" hello ") ! " hello" 6 | print'(a)', chomp(TAB//"goodbye"//CR//LF) ! "\tgoodbye" 7 | print'(a)', chomp(" "//TAB//LF//VT//FF//CR) ! "" 8 | print'(a)', chomp(" ! ")//"!" ! " !!" 9 | print'(a)', chomp("Hello") ! "Hello" 10 | print'(a)', chomp("hello", ["l", "o"]) ! "he" 11 | print'(a)', chomp("hello", set=["l", "o"]) ! "he" 12 | print'(a)', chomp("hello", "lo") ! "hel" 13 | print'(a)', chomp("hello", substring="lo") ! "hel" 14 | end program example_chomp 15 | -------------------------------------------------------------------------------- /example/strings/example_count.f90: -------------------------------------------------------------------------------- 1 | program example_count 2 | use stdlib_string_type, only: string_type, assignment(=) 3 | use stdlib_strings, only: count 4 | implicit none 5 | type(string_type) :: string 6 | 7 | string = "How much wood would a woodchuck chuck if a woodchuck could chuck wood?" 8 | 9 | print *, count(string, "wood") ! 4 10 | print *, count(string, ["would", "chuck", "could"]) ! [1, 4, 1] 11 | print *, count("a long queueueueue", "ueu", [.false., .true.]) ! [2, 4] 12 | 13 | end program example_count 14 | -------------------------------------------------------------------------------- /example/strings/example_ends_with.f90: -------------------------------------------------------------------------------- 1 | program example_ends_with 2 | use stdlib_strings, only: ends_with 3 | implicit none 4 | print'(l1)', ends_with("pattern", "ern") ! T 5 | print'(l1)', ends_with("pattern", "pat") ! F 6 | end program example_ends_with 7 | -------------------------------------------------------------------------------- /example/strings/example_find.f90: -------------------------------------------------------------------------------- 1 | program example_find 2 | use stdlib_string_type, only: string_type, assignment(=) 3 | use stdlib_strings, only: find 4 | implicit none 5 | type(string_type) :: string 6 | 7 | string = "needle in the character-stack" 8 | 9 | print *, find(string, "needle") ! 1 10 | print *, find(string, ["a", "c"], [3, 2]) ! [27, 20] 11 | print *, find("qwqwqwq", "qwq", 3, [.false., .true.]) ! [0, 5] 12 | 13 | end program example_find 14 | -------------------------------------------------------------------------------- /example/strings/example_join.f90: -------------------------------------------------------------------------------- 1 | program example_join 2 | use stdlib_strings, only: join 3 | implicit none 4 | 5 | character(len=:), allocatable :: line 6 | character(*), parameter :: words(3) = [character(7) :: "Hello", "World", "Fortran"] 7 | 8 | ! Default separator (space) 9 | line = join(words) 10 | print *, "'" // line // "'" !! 'Hello World Fortran' 11 | 12 | ! Custom separator 13 | line = join(words, "_") 14 | print *, "'" // line // "'" !! 'Hello_World_Fortran' 15 | 16 | ! Custom 2-character separator 17 | line = join(words, ", ") 18 | print *, "'" // line // "'" !! 'Hello, World, Fortran' 19 | 20 | end program example_join 21 | -------------------------------------------------------------------------------- /example/strings/example_padl.f90: -------------------------------------------------------------------------------- 1 | program example_padl 2 | use stdlib_string_type, only: string_type, assignment(=), write (formatted) 3 | use stdlib_strings, only: padl 4 | implicit none 5 | type(string_type) :: string 6 | 7 | string = "left pad this string" 8 | ! string <-- "left pad this string" 9 | 10 | print '(dt)', padl(string, 25, "$") ! "$$$$$left pad this string" 11 | 12 | string = padl(string, 25) 13 | ! string <-- " left pad this string" 14 | 15 | end program example_padl 16 | -------------------------------------------------------------------------------- /example/strings/example_padr.f90: -------------------------------------------------------------------------------- 1 | program example_padr 2 | use stdlib_string_type, only: string_type, assignment(=), write (formatted) 3 | use stdlib_strings, only: padr 4 | implicit none 5 | type(string_type) :: string 6 | 7 | string = "right pad this string" 8 | ! string <-- "right pad this string" 9 | 10 | print '(dt)', padr(string, 25, "$") ! "right pad this string$$$$" 11 | 12 | string = padr(string, 25) 13 | ! string <-- "right pad this string " 14 | 15 | end program example_padr 16 | -------------------------------------------------------------------------------- /example/strings/example_replace_all.f90: -------------------------------------------------------------------------------- 1 | program example_replace_all 2 | use stdlib_string_type, only: string_type, assignment(=), write (formatted) 3 | use stdlib_strings, only: replace_all 4 | implicit none 5 | type(string_type) :: string 6 | 7 | string = "hurdles here, hurdles there, hurdles everywhere" 8 | ! string <-- "hurdles here, hurdles there, hurdles everywhere" 9 | 10 | print'(dt)', replace_all(string, "hurdles", "learn from") 11 | ! "learn from here, learn from there, learn from everywhere" 12 | 13 | string = replace_all(string, "hurdles", "technology") 14 | ! string <-- "technology here, technology there, technology everywhere" 15 | 16 | end program example_replace_all 17 | -------------------------------------------------------------------------------- /example/strings/example_slice.f90: -------------------------------------------------------------------------------- 1 | program example_slice 2 | use stdlib_string_type 3 | use stdlib_strings, only: slice 4 | implicit none 5 | type(string_type) :: string 6 | character(len=10) :: chars 7 | 8 | string = "abcdefghij" 9 | ! string <-- "abcdefghij" 10 | 11 | chars = "abcdefghij" 12 | ! chars <-- "abcdefghij" 13 | 14 | print'(a)', slice("abcdefghij", 2, 6, 2) ! "bdf" 15 | print'(a)', slice(chars, 2, 6, 2) ! "bdf" 16 | 17 | string = slice(string, 2, 6, 2) 18 | ! string <-- "bdf" 19 | 20 | end program example_slice 21 | -------------------------------------------------------------------------------- /example/strings/example_starts_with.f90: -------------------------------------------------------------------------------- 1 | program example_starts_with 2 | use stdlib_strings, only: starts_with 3 | implicit none 4 | print'(l1)', starts_with("pattern", "pat") ! T 5 | print'(l1)', starts_with("pattern", "ern") ! F 6 | end program example_starts_with 7 | -------------------------------------------------------------------------------- /example/strings/example_stream_of_strings_to_numbers.f90: -------------------------------------------------------------------------------- 1 | program example_stream_of_strings_to_numbers 2 | use stdlib_kinds, only: dp 3 | use stdlib_str2num, only: to_num_from_stream 4 | implicit none 5 | character(:), allocatable, target :: chain 6 | character(len=:), pointer :: cptr 7 | real(dp), allocatable :: r(:), p(:) 8 | integer :: i 9 | 10 | chain = " 1.234 1.E1 1e0 0.1234E0 12.21e+001 -34.5E1" 11 | allocate( r(6), p(6) ) 12 | !> Example for streamline conversion using `to_num_from_stream` 13 | cptr => chain 14 | do i =1, 6 15 | r(i) = to_num_from_stream( cptr , r(i) ) !> the pointer is shifted within the function 16 | end do 17 | read(chain,*) p 18 | print *, "Reading with to_num_from_stream" 19 | print *, r 20 | print *, "Reading with formatted read" 21 | print *, p 22 | 23 | end program example_stream_of_strings_to_numbers 24 | -------------------------------------------------------------------------------- /example/strings/example_string_to_number.f90: -------------------------------------------------------------------------------- 1 | program example_string_to_number 2 | use stdlib_kinds, only: dp 3 | use stdlib_str2num, only: to_num 4 | implicit none 5 | character(:), allocatable :: txt 6 | real(dp) :: x 7 | 8 | txt = ' 8.8541878128e−12 ' 9 | x = to_num( txt , x ) 10 | end program example_string_to_number -------------------------------------------------------------------------------- /example/strings/example_strip.f90: -------------------------------------------------------------------------------- 1 | program example_strip 2 | use stdlib_ascii, only: TAB, VT, LF, CR, FF 3 | use stdlib_strings, only: strip 4 | implicit none 5 | print'(a)', strip(" hello ") ! "hello" 6 | print'(a)', strip(TAB//"goodbye"//CR//LF) ! "goodbye" 7 | print'(a)', strip(" "//TAB//LF//VT//FF//CR) ! "" 8 | print'(a)', strip(" ! ")//"!" ! "!!" 9 | print'(a)', strip("Hello") ! "Hello" 10 | end program example_strip 11 | -------------------------------------------------------------------------------- /example/strings/example_to_c_char.f90: -------------------------------------------------------------------------------- 1 | program example_to_c_char 2 | use stdlib_strings, only: to_c_char 3 | use stdlib_string_type, only: string_type 4 | use stdlib_kinds, only: c_char 5 | implicit none 6 | 7 | character(kind=c_char), allocatable :: cstr(:),cstr2(:) 8 | character(*), parameter :: hello = "Hello, World!" 9 | 10 | ! Convert character array 11 | cstr = to_c_char(hello) 12 | 13 | ! Convert string type 14 | cstr2 = to_c_char(string_type(hello)) 15 | 16 | if (size(cstr)/=size(cstr2) .or. .not.all(cstr==cstr2)) then 17 | error stop 'String conversion error' 18 | end if 19 | 20 | end program example_to_c_char 21 | -------------------------------------------------------------------------------- /example/strings/example_zfill.f90: -------------------------------------------------------------------------------- 1 | program example_zfill 2 | use stdlib_string_type, only: string_type, assignment(=), write (formatted) 3 | use stdlib_strings, only: zfill 4 | implicit none 5 | type(string_type) :: string 6 | 7 | string = "left pad this string with zeros" 8 | ! string <-- "left pad this string with zeros" 9 | 10 | print '(dt)', zfill(string, 36) ! "00000left pad this string with zeros" 11 | 12 | string = zfill(string, 36) 13 | ! string <-- "00000left pad this string with zeros" 14 | 15 | end program example_zfill 16 | -------------------------------------------------------------------------------- /example/system/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(get_runtime_os) 2 | ADD_EXAMPLE(delete_file) 3 | ADD_EXAMPLE(is_directory) 4 | ADD_EXAMPLE(null_device) 5 | ADD_EXAMPLE(os_type) 6 | ADD_EXAMPLE(process_1) 7 | ADD_EXAMPLE(process_2) 8 | ADD_EXAMPLE(process_3) 9 | ADD_EXAMPLE(process_4) 10 | ADD_EXAMPLE(process_5) 11 | ADD_EXAMPLE(process_6) 12 | ADD_EXAMPLE(process_7) 13 | ADD_EXAMPLE(sleep) 14 | -------------------------------------------------------------------------------- /example/system/example_delete_file.f90: -------------------------------------------------------------------------------- 1 | ! Demonstrate usage of `delete_file` 2 | program example_delete_file 3 | use stdlib_system, only: delete_file 4 | use stdlib_error, only: state_type 5 | implicit none 6 | 7 | type(state_type) :: err 8 | character(*), parameter :: filename = "example.txt" 9 | 10 | ! Delete a file with error handling 11 | call delete_file(filename, err) 12 | 13 | if (err%error()) then 14 | print *, err%print() 15 | else 16 | print *, "File "//filename//" deleted successfully." 17 | end if 18 | end program example_delete_file 19 | -------------------------------------------------------------------------------- /example/system/example_get_runtime_os.f90: -------------------------------------------------------------------------------- 1 | ! Demonstrate usage of (non-cached) runtime OS query 2 | program example_get_runtime_os 3 | use stdlib_system, only: OS_NAME, get_runtime_os 4 | implicit none 5 | 6 | ! Runtime OS detection (full inspection) 7 | print *, "Runtime OS Type: ", OS_NAME(get_runtime_os()) 8 | 9 | end program example_get_runtime_os 10 | -------------------------------------------------------------------------------- /example/system/example_is_directory.f90: -------------------------------------------------------------------------------- 1 | ! Demonstrate usage of `is_directory` 2 | program example_is_directory 3 | use stdlib_system, only: is_directory 4 | implicit none 5 | ! Test a directory path 6 | if (is_directory("/path/to/check")) then 7 | print *, "The specified path is a directory." 8 | else 9 | print *, "The specified path is not a directory." 10 | end if 11 | end program example_is_directory 12 | -------------------------------------------------------------------------------- /example/system/example_null_device.f90: -------------------------------------------------------------------------------- 1 | ! Showcase usage of the null device 2 | program example_null_device 3 | use stdlib_system, only: null_device 4 | use iso_fortran_env, only: output_unit 5 | implicit none 6 | integer :: unit 7 | logical :: screen_output = .false. 8 | 9 | if (screen_output) then 10 | unit = output_unit 11 | else 12 | ! Write to the null device if no screen output is wanted 13 | open(newunit=unit,file=null_device()) 14 | endif 15 | 16 | write(unit,*) "Hello, world!" 17 | 18 | if (.not.screen_output) close(unit) 19 | 20 | end program example_null_device 21 | -------------------------------------------------------------------------------- /example/system/example_os_type.f90: -------------------------------------------------------------------------------- 1 | ! Demonstrate OS detection 2 | program example_os_type 3 | use stdlib_system, only: OS_TYPE, OS_NAME 4 | implicit none 5 | 6 | integer :: current_os 7 | 8 | ! Cached OS detection 9 | current_os = OS_TYPE() 10 | print *, "Current OS Type: ", OS_NAME(current_os) 11 | 12 | end program example_os_type 13 | -------------------------------------------------------------------------------- /example/system/example_process_1.f90: -------------------------------------------------------------------------------- 1 | ! Process example 1: Run a Command Synchronously and Capture Output 2 | program run_sync 3 | use stdlib_system, only: run, is_completed, is_windows, process_type 4 | implicit none 5 | 6 | type(process_type) :: p 7 | logical :: completed 8 | 9 | ! Run a synchronous process to list directory contents 10 | if (is_windows()) then 11 | p = run("dir", want_stdout=.true.) 12 | else 13 | p = run("ls -l", want_stdout=.true.) 14 | end if 15 | 16 | ! Check if the process is completed (should be true since wait=.true.) 17 | if (is_completed(p)) then 18 | print *, "Process completed successfully. The current directory: " 19 | print *, p%stdout 20 | else 21 | print *, "Process is still running (unexpected)." 22 | end if 23 | 24 | end program run_sync 25 | -------------------------------------------------------------------------------- /example/system/example_process_2.f90: -------------------------------------------------------------------------------- 1 | ! Process example 2: Run an Asynchronous Command and check its status 2 | program run_async 3 | use stdlib_system, only: process_type, runasync, is_running, wait 4 | implicit none 5 | 6 | type(process_type) :: p 7 | 8 | ! Run an asynchronous process to sleep for 1 second 9 | p = runasync("sleep 1") 10 | 11 | ! Check if the process is running 12 | if (is_running(p)) then 13 | print *, "Process is running." 14 | else 15 | print *, "Process has already completed." 16 | end if 17 | 18 | ! Wait for the process to complete 19 | call wait(p, max_wait_time = 5.0) 20 | print *, "Process has now completed." 21 | end program run_async 22 | -------------------------------------------------------------------------------- /example/system/example_process_3.f90: -------------------------------------------------------------------------------- 1 | ! Process example 3: Run with many arguments, and check runtime 2 | program run_with_args 3 | use stdlib_system, only: process_type, run, elapsed, wait 4 | implicit none 5 | 6 | type(process_type) :: p 7 | character(len=15), allocatable :: args(:) 8 | 9 | ! Define arguments for the `echo` command 10 | allocate(args(2)) 11 | args(1) = "echo" 12 | args(2) = "Hello, Fortran!" 13 | 14 | ! Run the command with arguments (synchronous) 15 | p = run(args) 16 | 17 | ! Print the runtime of the process 18 | print *, "Process runtime:", elapsed(p), "seconds." 19 | 20 | ! Clean up 21 | deallocate(args) 22 | end program run_with_args 23 | -------------------------------------------------------------------------------- /example/system/example_process_4.f90: -------------------------------------------------------------------------------- 1 | ! Process example 4: Kill a running process 2 | program example_process_kill 3 | use stdlib_system, only: process_type, runasync, is_running, kill, elapsed, is_windows, sleep 4 | implicit none 5 | type(process_type) :: process 6 | logical :: running, success 7 | 8 | print *, "Starting a long-running process..." 9 | if (is_windows()) then 10 | process = runasync("ping -n 10 127.0.0.1") 11 | else 12 | process = runasync("ping -c 10 127.0.0.1") 13 | endif 14 | 15 | ! Verify the process is running 16 | running = is_running(process) 17 | print *, "Process running:", running 18 | 19 | ! Wait a bit before killing the process 20 | call sleep(millisec=250) 21 | 22 | print *, "Killing the process..." 23 | call kill(process, success) 24 | 25 | if (success) then 26 | print *, "Process killed successfully." 27 | else 28 | print *, "Failed to kill the process." 29 | endif 30 | 31 | ! Verify the process is no longer running 32 | running = is_running(process) 33 | print *, "Process running after kill:", running 34 | 35 | end program example_process_kill 36 | -------------------------------------------------------------------------------- /example/system/example_process_5.f90: -------------------------------------------------------------------------------- 1 | ! Process example 5: Object-oriented interface 2 | program example_process_5 3 | use stdlib_system, only: process_type, runasync, is_windows, sleep, update 4 | implicit none 5 | type(process_type) :: process 6 | 7 | if (is_windows()) then 8 | process = runasync("ping -n 10 127.0.0.1") 9 | else 10 | process = runasync("ping -c 10 127.0.0.1") 11 | endif 12 | 13 | ! Verify the process is running 14 | do while (process%is_running()) 15 | 16 | ! Update process state 17 | call update(process) 18 | 19 | ! Wait a bit before killing the process 20 | call sleep(millisec=1500) 21 | 22 | print *, "Process has been running for ",process%elapsed()," seconds..." 23 | 24 | end do 25 | 26 | print *, "Process ",process%pid()," completed in ",process%elapsed()," seconds." 27 | 28 | end program example_process_5 29 | -------------------------------------------------------------------------------- /example/system/example_process_7.f90: -------------------------------------------------------------------------------- 1 | ! Process example 7: Usage of `kill` 2 | program example_process_7 3 | use stdlib_system, only: process_type, runasync, kill 4 | implicit none 5 | 6 | type(process_type) :: p 7 | logical :: success 8 | 9 | ! Start a process asynchronously 10 | p = runasync("sleep 10") 11 | 12 | ! Attempt to kill the process 13 | call kill(p, success) 14 | 15 | if (success) then 16 | print *, "Process successfully killed." 17 | else 18 | print *, "Failed to kill the process." 19 | end if 20 | 21 | end program example_process_7 22 | -------------------------------------------------------------------------------- /example/system/example_sleep.f90: -------------------------------------------------------------------------------- 1 | ! Usage of `sleep` 2 | program example_sleep 3 | use stdlib_system, only: sleep 4 | implicit none 5 | 6 | print *, "Starting sleep..." 7 | 8 | ! Sleep for 500 milliseconds 9 | call sleep(500) 10 | 11 | print *, "Finished sleeping!" 12 | 13 | end program example_sleep 14 | -------------------------------------------------------------------------------- /example/version/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXAMPLE(version) 2 | -------------------------------------------------------------------------------- /example/version/example_version.f90: -------------------------------------------------------------------------------- 1 | program example_version 2 | use stdlib_version, only: get_stdlib_version 3 | implicit none 4 | character(len=:), allocatable :: version 5 | call get_stdlib_version(string=version) 6 | print '(a)', version 7 | end program example_version 8 | -------------------------------------------------------------------------------- /fpm.toml: -------------------------------------------------------------------------------- 1 | name = "stdlib" 2 | version = "VERSION" 3 | license = "MIT" 4 | author = "stdlib contributors" 5 | maintainer = "@fortran-lang/stdlib" 6 | copyright = "2019-2024 stdlib contributors" 7 | 8 | [install] 9 | library = true 10 | 11 | [dev-dependencies] 12 | test-drive.git = "https://github.com/fortran-lang/test-drive" 13 | test-drive.tag = "v0.4.0" 14 | 15 | [preprocess] 16 | [preprocess.cpp] 17 | suffixes = [".F90", ".f90"] 18 | macros = ["MAXRANK=7"] 19 | -------------------------------------------------------------------------------- /src/blas/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #### 2 | 3 | set(dir "${CMAKE_CURRENT_SOURCE_DIR}") 4 | 5 | list(APPEND fppFiles 6 | blas/stdlib_blas_constants.fypp 7 | blas/stdlib_blas.fypp 8 | blas/stdlib_blas_level1.fypp 9 | blas/stdlib_blas_level2_ban.fypp 10 | blas/stdlib_blas_level2_gen.fypp 11 | blas/stdlib_blas_level2_pac.fypp 12 | blas/stdlib_blas_level2_sym.fypp 13 | blas/stdlib_blas_level2_tri.fypp 14 | blas/stdlib_blas_level3_gen.fypp 15 | blas/stdlib_blas_level3_sym.fypp 16 | blas/stdlib_blas_level3_tri.fypp 17 | blas/stdlib_linalg_blas_aux.fypp 18 | ) 19 | 20 | set(fppFiles "${fppFiles}" PARENT_SCOPE) 21 | -------------------------------------------------------------------------------- /src/f08estop.f90: -------------------------------------------------------------------------------- 1 | submodule (stdlib_error) f08estop 2 | 3 | implicit none 4 | 5 | contains 6 | 7 | module procedure error_stop 8 | ! Aborts the program with nonzero exit code 9 | ! this is a fallback for Fortran 2008 error stop (e.g. Intel 19.1/2020 compiler) 10 | ! 11 | ! The "stop " statement generally has return code 0. 12 | ! To allow non-zero return code termination with character message, 13 | ! error_stop() uses the statement "error stop", which by default 14 | ! has exit code 1 and prints the message to stderr. 15 | ! An optional integer return code "code" may be specified. 16 | ! 17 | ! Example 18 | ! ------- 19 | ! 20 | ! call error_stop("Invalid argument") 21 | 22 | write(stderr,*) msg 23 | 24 | if(present(code)) then 25 | select case (code) 26 | case (1) 27 | error stop 1 28 | case (2) 29 | error stop 2 30 | case (77) 31 | error stop 77 32 | case default 33 | write(stderr,*) 'ERROR: code ',code,' was specified.' 34 | error stop 35 | end select 36 | else 37 | error stop 38 | endif 39 | end procedure 40 | 41 | end submodule f08estop 42 | -------------------------------------------------------------------------------- /src/f18estop.f90: -------------------------------------------------------------------------------- 1 | submodule (stdlib_error) f18estop 2 | 3 | implicit none 4 | 5 | contains 6 | 7 | module procedure error_stop 8 | ! Aborts the program with nonzero exit code 9 | ! 10 | ! The "stop " statement generally has return code 0. 11 | ! To allow non-zero return code termination with character message, 12 | ! error_stop() uses the statement "error stop", which by default 13 | ! has exit code 1 and prints the message to stderr. 14 | ! An optional integer return code "code" may be specified. 15 | ! 16 | ! Example 17 | ! ------- 18 | ! 19 | ! call error_stop("Invalid argument") 20 | 21 | if(present(code)) then 22 | write(stderr,*) msg 23 | error stop code 24 | else 25 | error stop msg 26 | endif 27 | end procedure 28 | 29 | end submodule f18estop 30 | -------------------------------------------------------------------------------- /src/stdlib_kinds.fypp: -------------------------------------------------------------------------------- 1 | #:include "common.fypp" 2 | !> Version: experimental 3 | !> 4 | !> The specification of this module is available [here](../page/specs/stdlib_kinds.html). 5 | module stdlib_kinds 6 | use iso_fortran_env, only: int8, int16, int32, int64 7 | use iso_c_binding, only: c_bool, c_char 8 | implicit none 9 | private 10 | public :: sp, dp, xdp, qp, int8, int16, int32, int64, lk, c_bool, c_char 11 | 12 | !> Single precision real numbers 13 | integer, parameter :: sp = selected_real_kind(6) 14 | 15 | !> Double precision real numbers 16 | integer, parameter :: dp = selected_real_kind(15) 17 | 18 | !> Extended double precision real numbers 19 | integer, parameter :: xdp = #{if WITH_XDP}#selected_real_kind(18)#{else}#-1#{endif}# 20 | 21 | !> Quadruple precision real numbers 22 | integer, parameter :: qp = #{if WITH_QP}#selected_real_kind(33)#{else}#-1#{endif}# 23 | 24 | !> Default logical kind parameter 25 | integer, parameter :: lk = kind(.true.) 26 | 27 | end module stdlib_kinds 28 | -------------------------------------------------------------------------------- /src/stdlib_linalg_cross_product.fypp: -------------------------------------------------------------------------------- 1 | #:include "common.fypp" 2 | #:set RCI_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES + INT_KINDS_TYPES 3 | submodule (stdlib_linalg) stdlib_linalg_cross_product 4 | 5 | implicit none 6 | 7 | contains 8 | 9 | #:for k1, t1 in RCI_KINDS_TYPES 10 | pure module function cross_product_${t1[0]}$${k1}$(a, b) result(res) 11 | ${t1}$, intent(in) :: a(3), b(3) 12 | ${t1}$ :: res(3) 13 | 14 | res(1) = a(2) * b(3) - a(3) * b(2) 15 | res(2) = a(3) * b(1) - a(1) * b(3) 16 | res(3) = a(1) * b(2) - a(2) * b(1) 17 | 18 | end function cross_product_${t1[0]}$${k1}$ 19 | #:endfor 20 | 21 | end submodule 22 | -------------------------------------------------------------------------------- /src/stdlib_linalg_kronecker.fypp: -------------------------------------------------------------------------------- 1 | #:include "common.fypp" 2 | #:set RCI_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES + INT_KINDS_TYPES 3 | submodule (stdlib_linalg) stdlib_linalg_kronecker 4 | 5 | implicit none 6 | 7 | contains 8 | 9 | #:for k1, t1 in RCI_KINDS_TYPES 10 | pure module function kronecker_product_${t1[0]}$${k1}$(A, B) result(C) 11 | ${t1}$, intent(in) :: A(:,:), B(:,:) 12 | ${t1}$ :: C(size(A,dim=1)*size(B,dim=1),size(A,dim=2)*size(B,dim=2)) 13 | integer :: m1, n1, maxM1, maxN1, maxM2, maxN2 14 | 15 | maxM1 = size(A, dim=1) 16 | maxN1 = size(A, dim=2) 17 | maxM2 = size(B, dim=1) 18 | maxN2 = size(B, dim=2) 19 | 20 | 21 | do n1 = 1, maxN1 22 | do m1 = 1, maxM1 23 | ! We use the Wikipedia convention for ordering of the matrix elements 24 | ! https://en.wikipedia.org/wiki/Kronecker_product 25 | C((m1-1)*maxM2+1:m1*maxM2, (n1-1)*maxN2+1:n1*maxN2) = A(m1, n1) * B(:,:) 26 | end do 27 | end do 28 | end function kronecker_product_${t1[0]}$${k1}$ 29 | #:endfor 30 | end submodule stdlib_linalg_kronecker 31 | -------------------------------------------------------------------------------- /src/stdlib_linalg_outer_product.fypp: -------------------------------------------------------------------------------- 1 | #:include "common.fypp" 2 | #:set RCI_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES + INT_KINDS_TYPES 3 | submodule (stdlib_linalg) stdlib_linalg_outer_product 4 | 5 | implicit none 6 | 7 | contains 8 | 9 | #:for k1, t1 in RCI_KINDS_TYPES 10 | pure module function outer_product_${t1[0]}$${k1}$(u, v) result(res) 11 | ${t1}$, intent(in) :: u(:), v(:) 12 | ${t1}$ :: res(size(u),size(v)) 13 | integer :: col 14 | do col = 1, size(v) 15 | res(:,col) = v(col) * u 16 | end do 17 | end function outer_product_${t1[0]}$${k1}$ 18 | #:endfor 19 | 20 | end submodule 21 | -------------------------------------------------------------------------------- /src/stdlib_math_all_close.fypp: -------------------------------------------------------------------------------- 1 | #:include "common.fypp" 2 | #:set RANKS = range(1, MAXRANK + 1) 3 | #:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES 4 | 5 | submodule (stdlib_math) stdlib_math_all_close 6 | 7 | implicit none 8 | 9 | contains 10 | 11 | #:for k1, t1 in RC_KINDS_TYPES 12 | #:for r1 in RANKS 13 | logical pure module function all_close_${r1}$_${t1[0]}$${k1}$(a, b, rel_tol, abs_tol, equal_nan) result(close) 14 | 15 | ${t1}$, intent(in) :: a${ranksuffix(r1)}$, b${ranksuffix(r1)}$ 16 | real(${k1}$), intent(in), optional :: rel_tol, abs_tol 17 | logical, intent(in), optional :: equal_nan 18 | 19 | close = all(is_close(a, b, rel_tol, abs_tol, equal_nan)) 20 | 21 | end function all_close_${r1}$_${t1[0]}$${k1}$ 22 | #:endfor 23 | #:endfor 24 | 25 | end submodule stdlib_math_all_close -------------------------------------------------------------------------------- /src/stdlib_sparse.f90: -------------------------------------------------------------------------------- 1 | !! public API 2 | module stdlib_sparse 3 | use stdlib_sparse_kinds 4 | use stdlib_sparse_conversion 5 | use stdlib_sparse_spmv 6 | end module stdlib_sparse -------------------------------------------------------------------------------- /test/array/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADDTEST(logicalloc) 2 | -------------------------------------------------------------------------------- /test/ascii/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADDTEST(ascii) 2 | -------------------------------------------------------------------------------- /test/bitsets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADDTEST(stdlib_bitset_64) 2 | ADDTEST(stdlib_bitset_large) 3 | 4 | -------------------------------------------------------------------------------- /test/constants/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADDTEST(constants) 2 | -------------------------------------------------------------------------------- /test/hash_functions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #ADDTEST(hash_functions) 2 | 3 | enable_language(CXX) 4 | enable_language(C) 5 | 6 | ADDTEST(hash_functions) 7 | target_sources( 8 | test_hash_functions 9 | PRIVATE 10 | nmhash.c 11 | pengyhash.c 12 | SpookyV2.cpp 13 | SpookyV2Test.cpp 14 | waterhash.c 15 | generate_hash_arrays.cpp 16 | ) 17 | 18 | if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel") 19 | 20 | # Set the C++ standard to prevent icpc breakage 21 | set(CMAKE_CXX_STANDARD 11) 22 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 23 | set(CMAKE_CXX_EXTENSIONS OFF) 24 | 25 | set_target_properties(test_hash_functions PROPERTIES LINKER_LANGUAGE Fortran) 26 | endif() 27 | 28 | if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 10.0) 29 | target_compile_options( 30 | test_hash_functions 31 | PRIVATE 32 | $<$:-fno-range-check> 33 | ) 34 | endif() 35 | 36 | -------------------------------------------------------------------------------- /test/hash_functions/README.md: -------------------------------------------------------------------------------- 1 | The hash_functions directory contains code to validate the Fortran hash functions against the original C/C++ codes. It consists of one executable `test_hash_functions` that: 2 | 3 | * creates a file containing 2048 random 8 bit integers using the subroutine 4 | `generate_key_array`. 5 | 6 | * reads the file generated by the subroutine `generate_key_array` and uses its contents to generate 2049 hashes for each C/C++ hash algorithm and outputs files containing the hashes. 7 | 8 | * reads the file generated by the subroutine `generate_key_array` and uses its contents to generate 2049 hashes for each Fortran hash algorithm and compares the result with the corresponding outputs of C/C++ hash algorithms. 9 | -------------------------------------------------------------------------------- /test/hash_functions/nmhash.c: -------------------------------------------------------------------------------- 1 | #include "nmhash.h" 2 | int32_t nmhash32_test ( const void * key, size_t len, uint32_t seed ) { 3 | return NMHASH32 (key, (const size_t) len, seed); 4 | } 5 | 6 | int32_t nmhash32x_test ( const void * key, size_t len, uint32_t seed ) { 7 | return NMHASH32X (key, (const size_t) len, seed); 8 | } 9 | -------------------------------------------------------------------------------- /test/hash_functions/pengyhash.c: -------------------------------------------------------------------------------- 1 | /* pengyhash v0.2 */ 2 | 3 | #include "pengyhash.h" 4 | 5 | uint64_t pengyhash(const void *p, size_t size, uint32_t seed) 6 | { 7 | uint64_t b[4] = { 0 }; 8 | uint64_t s[4] = { 0, 0, 0, size }; 9 | int i; 10 | 11 | for(; size >= 32; size -= 32, p = (const char*)p + 32) { 12 | memcpy(b, p, 32); 13 | 14 | s[1] = (s[0] += s[1] + b[3]) + (s[1] << 14 | s[1] >> 50); 15 | s[3] = (s[2] += s[3] + b[2]) + (s[3] << 23 | s[3] >> 41); 16 | s[3] = (s[0] += s[3] + b[1]) ^ (s[3] << 16 | s[3] >> 48); 17 | s[1] = (s[2] += s[1] + b[0]) ^ (s[1] << 40 | s[1] >> 24); 18 | } 19 | 20 | memcpy(b, p, size); 21 | 22 | for(i = 0; i < 6; i++) { 23 | s[1] = (s[0] += s[1] + b[3]) + (s[1] << 14 | s[1] >> 50) + seed; 24 | s[3] = (s[2] += s[3] + b[2]) + (s[3] << 23 | s[3] >> 41); 25 | s[3] = (s[0] += s[3] + b[1]) ^ (s[3] << 16 | s[3] >> 48); 26 | s[1] = (s[2] += s[1] + b[0]) ^ (s[1] << 40 | s[1] >> 24); 27 | } 28 | 29 | return s[0] + s[1] + s[2] + s[3]; 30 | } 31 | -------------------------------------------------------------------------------- /test/hash_functions/pengyhash.h: -------------------------------------------------------------------------------- 1 | #ifndef _PENGYHASH_H 2 | #define _PENGYHASH_H 3 | 4 | #include 5 | #include 6 | 7 | uint64_t pengyhash(const void *p, size_t size, uint32_t seed); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /test/hash_functions/waterhash.c: -------------------------------------------------------------------------------- 1 | #include "waterhash.h" 2 | 3 | int32_t waterhash_test ( const void * key, uint32_t len, uint64_t seed ) { 4 | return waterhash (key, len, seed); 5 | } 6 | 7 | -------------------------------------------------------------------------------- /test/hash_functions_perf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADDTEST(32_bit_hash_performance) 2 | ADDTEST(64_bit_hash_performance) 3 | 4 | if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 10.0) 5 | target_compile_options( 6 | test_64_bit_hash_performance 7 | PRIVATE 8 | $<$:-fno-range-check> 9 | ) 10 | endif() 11 | -------------------------------------------------------------------------------- /test/hashmaps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ### Pre-process: .fpp -> .f90 via Fypp 2 | 3 | # Create a list of the files to be preprocessed 4 | set(fppFiles 5 | test_maps.fypp 6 | ) 7 | 8 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 9 | 10 | ADDTEST(chaining_maps) 11 | ADDTEST(open_maps) 12 | ADDTEST(maps) 13 | 14 | -------------------------------------------------------------------------------- /test/hashmaps/Makefile.manual: -------------------------------------------------------------------------------- 1 | PROGS_SRC = test_chaining_maps.f90 \ 2 | test_open_maps.f90 3 | 4 | 5 | include ../Makefile.manual.test.mk 6 | -------------------------------------------------------------------------------- /test/intrinsics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( 2 | fppFiles 3 | "test_intrinsics.fypp" 4 | ) 5 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 6 | 7 | ADDTEST(intrinsics) 8 | -------------------------------------------------------------------------------- /test/io/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( 2 | fppFiles 3 | "test_loadtxt_qp.fypp" 4 | "test_savetxt_qp.fypp" 5 | ) 6 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 7 | 8 | ADDTEST(loadtxt) 9 | ADDTEST(savetxt) 10 | 11 | ADDTEST(loadtxt_qp) 12 | ADDTEST(savetxt_qp) 13 | set_tests_properties(loadtxt_qp PROPERTIES LABELS quadruple_precision) 14 | set_tests_properties(savetxt_qp PROPERTIES LABELS quadruple_precision) 15 | 16 | ADDTEST(get_line) 17 | ADDTEST(npy) 18 | ADDTEST(open) 19 | ADDTEST(parse_mode) 20 | -------------------------------------------------------------------------------- /test/linalg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( 2 | fppFiles 3 | "test_linalg.fypp" 4 | "test_linalg_eigenvalues.fypp" 5 | "test_linalg_solve.fypp" 6 | "test_linalg_inverse.fypp" 7 | "test_linalg_pseudoinverse.fypp" 8 | "test_linalg_lstsq.fypp" 9 | "test_linalg_norm.fypp" 10 | "test_linalg_mnorm.fypp" 11 | "test_linalg_determinant.fypp" 12 | "test_linalg_qr.fypp" 13 | "test_linalg_schur.fypp" 14 | "test_linalg_svd.fypp" 15 | "test_linalg_matrix_property_checks.fypp" 16 | "test_linalg_sparse.fypp" 17 | "test_linalg_cholesky.fypp" 18 | ) 19 | 20 | # Preprocessed files to contain preprocessor directives -> .F90 21 | set( 22 | cppFiles 23 | "test_blas_lapack.fypp" 24 | ) 25 | 26 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 27 | fypp_f90pp("${fyppFlags}" "${cppFiles}" outPreprocFiles) 28 | 29 | ADDTEST(linalg) 30 | ADDTEST(linalg_cholesky) 31 | ADDTEST(linalg_determinant) 32 | ADDTEST(linalg_eigenvalues) 33 | ADDTEST(linalg_matrix_property_checks) 34 | ADDTEST(linalg_inverse) 35 | ADDTEST(linalg_pseudoinverse) 36 | ADDTEST(linalg_norm) 37 | ADDTEST(linalg_mnorm) 38 | ADDTEST(linalg_solve) 39 | ADDTEST(linalg_lstsq) 40 | ADDTEST(linalg_qr) 41 | ADDTEST(linalg_schur) 42 | ADDTEST(linalg_svd) 43 | ADDTEST(linalg_sparse) 44 | ADDTESTPP(blas_lapack) 45 | -------------------------------------------------------------------------------- /test/logger/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADDTEST(stdlib_logger) 2 | -------------------------------------------------------------------------------- /test/math/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( 2 | fppFiles 3 | "test_stdlib_math.fypp" 4 | "test_meshgrid.fypp" 5 | ) 6 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 7 | 8 | ADDTEST(stdlib_math) 9 | ADDTEST(linspace) 10 | ADDTEST(logspace) 11 | ADDTEST(meshgrid) 12 | -------------------------------------------------------------------------------- /test/optval/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( 2 | fppFiles 3 | "test_optval.fypp" 4 | ) 5 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 6 | 7 | ADDTEST(optval) 8 | # prevent false positive (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95446) 9 | if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU) 10 | set_source_files_properties("test_optval.f90" PROPERTIES COMPILE_FLAGS "-Wno-error=pedantic") 11 | endif() 12 | -------------------------------------------------------------------------------- /test/quadrature/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( 2 | fppFiles 3 | "test_simps.fypp" 4 | "test_trapz.fypp" 5 | ) 6 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 7 | 8 | ADDTEST(trapz) 9 | ADDTEST(simps) 10 | ADDTEST(gauss) 11 | -------------------------------------------------------------------------------- /test/selection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ### Pre-process: .fpp -> .f90 via Fypp 2 | 3 | # Create a list of the files to be preprocessed 4 | set( 5 | fppFiles 6 | test_selection.fypp 7 | ) 8 | 9 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 10 | 11 | ADDTEST(selection) 12 | -------------------------------------------------------------------------------- /test/sorting/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( 2 | fppFiles 3 | "test_sorting.fypp" 4 | ) 5 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 6 | 7 | ADDTEST(sorting) 8 | -------------------------------------------------------------------------------- /test/specialfunctions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ### Pre-process: .fpp -> .f90 via Fypp 2 | 3 | # Create a list of the files to be preprocessed 4 | set(fppFiles 5 | test_specialfunctions_activations.fypp 6 | test_specialfunctions_gamma.fypp 7 | ) 8 | 9 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 10 | 11 | ADDTEST(specialfunctions_gamma) 12 | ADDTEST(specialfunctions_activations) -------------------------------------------------------------------------------- /test/specialfunctions/Makefile.manual: -------------------------------------------------------------------------------- 1 | SRCFYPP = \ 2 | test_specialfunctions_gamma.fypp 3 | 4 | SRCGEN = $(SRCFYPP:.fypp=.f90) 5 | 6 | $(SRCGEN): %.f90: %.fypp ../../common.fypp 7 | fypp -I../.. $(FYPPFLAGS) $< $@ 8 | 9 | include ../Makefile.manual.test.mk 10 | -------------------------------------------------------------------------------- /test/stats/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #### Pre-process: .fpp -> .f90 via Fypp 2 | 3 | # Create a list of the files to be preprocessed 4 | set(fppFiles 5 | test_mean.fypp 6 | test_mean_f03.fypp 7 | test_median.fypp 8 | test_distribution_uniform.fypp 9 | test_distribution_normal.fypp 10 | test_distribution_exponential.fypp 11 | ) 12 | 13 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 14 | 15 | ADDTEST(corr) 16 | ADDTEST(cov) 17 | ADDTEST(mean) 18 | ADDTEST(median) 19 | ADDTEST(moment) 20 | ADDTEST(rawmoment) 21 | ADDTEST(var) 22 | ADDTEST(varn) 23 | ADDTEST(random) 24 | ADDTEST(distribution_uniform) 25 | ADDTEST(distribution_normal) 26 | ADDTEST(distribution_exponential) 27 | 28 | if(DEFINED CMAKE_MAXIMUM_RANK) 29 | if(${CMAKE_MAXIMUM_RANK} GREATER 7) 30 | ADDTEST(mean_f03) 31 | endif() 32 | elseif(f03rank) 33 | ADDTEST(mean_f03) 34 | endif() 35 | -------------------------------------------------------------------------------- /test/string/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #### Pre-process: .fpp -> .f90 via Fypp 2 | 3 | # Create a list of the files to be preprocessed 4 | set(fppFiles 5 | test_string_assignment.fypp 6 | test_string_to_number.fypp 7 | ) 8 | 9 | fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) 10 | 11 | ADDTEST(string_assignment) 12 | ADDTEST(string_operator) 13 | ADDTEST(string_intrinsic) 14 | ADDTEST(string_match) 15 | ADDTEST(string_derivedtype_io) 16 | ADDTEST(string_functions) 17 | ADDTEST(string_strip_chomp) 18 | ADDTEST(string_to_number) 19 | ADDTEST(string_to_string) 20 | -------------------------------------------------------------------------------- /test/stringlist/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADDTEST(insert_at) 2 | ADDTEST(append_prepend) 3 | -------------------------------------------------------------------------------- /test/system/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADDTEST(filesystem) 2 | ADDTEST(os) 3 | ADDTEST(sleep) 4 | ADDTEST(subprocess) 5 | -------------------------------------------------------------------------------- /test/terminal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADDTEST(colors) 2 | --------------------------------------------------------------------------------