Coder Social home page Coder Social logo

Comments (4)

q-posev avatar q-posev commented on August 11, 2024

The best solution is to check that the total number of elements in user-provided array is consistent with the size of array in the file

from trexio.

scemama avatar scemama commented on August 11, 2024

You can't do it without passing the size of the array as a parameter to the function. I agree that it would be good to do it, but I am sure that the users will complain that it is redundant because we already have set nucleus_num.
Maybe we should provide both variants : one safe where you pass the dimensions as an additional parameter (an array of dimensions), and an unsafe variant which is what we have now.

from trexio.

scemama avatar scemama commented on August 11, 2024

In the Fortran interface it should be possible to do that:

  interface                                                                                                                                                                                   
     integer function trexio_write_nucleus_coord_s (trex_file, dset, dim) bind(C)                                                                                                             
       use, intrinsic :: iso_c_binding                                                                                                                                                        
       integer(8), intent(in), value :: trex_file                                                                                                                                             
       real(8), intent(in) :: dset(*)                                                                                                                                                         
       integer(4), intent(in) :: dim(2)                                                                                                                                                       
     end function trexio_write_nucleus_coord_s                                                                                                                                                
  end interface                                                                                                                                                                               
                                                                                                                                                                                              
  integer function trexio_write_nucleus_coord (trex_file, dset)                                                                                                                               
    use, intrinsic :: iso_c_binding                                                                                                                                                           
    integer(8), intent(in), value :: trex_file                                                                                                                                                
    real(8), intent(in) :: dset(:,:)                                                                                                                                                          
                                                                                                                                                                                              
    call trexio_write_nucleus_coord_s(trex_file, dset, shape(dset))                                                                                                                           
  end function trexio_write_nucleus_coord 

So that the fortran has only the "unsafe" API, but it calls the safe C routines. The real unsafe nature will only be present in C.

from trexio.

q-posev avatar q-posev commented on August 11, 2024

@scemama I agree that this is not really user-friendly and unfortunately we cannot evaluate the number of elements when a pointer to an array is passed to a C function. For the Fortran and Python interfaces it is doable.

from trexio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.