Giter VIP home page Giter VIP logo

Comments (7)

zbeekman avatar zbeekman commented on June 25, 2024

Or use the new impure elemental... If compiler support exists. Alternatively, do something creative with pointers to allow a state full error stack to be passed around and the check it when the function returns.

from datetime-fortran.

milancurcic avatar milancurcic commented on June 25, 2024

@zbeekman Did not know about this feature. Is it F2008?

from datetime-fortran.

szaghi avatar szaghi commented on June 25, 2024

@milancurcic
Alternatively, provide a basic class encapsulating errors handling that will be the parent ancestor of all classes: all pure procedures will remain pure and exception handling vould be done outside the pure procedure. I have not tried this approach, but I found suggestions on that on clf-google-group.

@zbeekman can you elaborate more on both elemental impure procedures and pointers aproach? πŸ™

Datetime rocks! My toy project that exploits it is not abbandoned...

from datetime-fortran.

zbeekman avatar zbeekman commented on June 25, 2024

impure elemental
From MCR:

Elemental procedures as defined in Fortran 95 and 2003 are required to be pure, a condition
which aids parallel evaluation. While this is advantageous for performance, it does prevent
other possibilities where one wishes to perform impure processing elementally on arrays
of arbitrary rank. In such cases, one was forced to provide a separate function for each
permutation of conformant ranks; for a procedure with two arguments, that was 22 separate
procedures (8 cases where both arguments had the same rank, 7 where the first was scalar andthe second was an array, and 7 where the first was an an array and the second was scalar). With
the increase of maximum rank to 15, this increases to 16+15+15 = 46 separate procedures.
The impure prefix on the procedure heading allows one to define an impure elemental
procedure, which processes array argument elements one by one in array element order. An
example is shown in Figure 20.9. This example is impure in three ways: it counts the number
of overflows in the global variable overflow_count, it logs each overflow on the external
unit error_unit, and it terminates the program with stop when too many errors have been
encountered.

Code example not included due to licensing concerns....

Only the requirements relating to β€˜purity’ (lack of side-effects) are lifted: the elemental
requirements remain, that is:
β€’ all dummy arguments of an elemental procedure must be scalar non-coarray dummy
data objects and must not have the pointer or allocatable attribute;
β€’ all dummy arguments of an elemental procedure must have specified intent;
β€’ the result variable of an elemental function must be scalar, must not have the pointer
or allocatable attribute, and must not have a type parameter that is defined by an
expression that is not a constant expression;
β€’ in a reference to an elemental procedure, all actual arguments must be conformable;
and
β€’ in a reference to an elemental procedure, actual arguments corresponding to intent out
and inout dummy arguments must either all be arrays or all be scalar.

comment about pointer
Pointer arguments with intent(in) can be used to allow pure functions to have arguments that are effectively intent(inout) because intent attached to a pointer only refers to the pointer association, the value of the data it is pointing to can change.

In the end, though, using an error handling class with an error stack is the way to go, IMO.

from datetime-fortran.

milancurcic avatar milancurcic commented on June 25, 2024

@zbeekman Thank you for the summary. At first I felt embarrassed that I missed this in my MRC, but then I realized it's described in the green (new) book which I don't own yet. I still own the blue book (95/2003). :)

Anyhow, these are great recommendations. I like the idea of an extensible parent class with error handling methods as a most general and re-usable approach. I will take some time to digest this information.

from datetime-fortran.

zbeekman avatar zbeekman commented on June 25, 2024

Get the green one! (Or see when they're going to publish their next book... maybe Fortran 2015 will be covered)

from datetime-fortran.

milancurcic avatar milancurcic commented on June 25, 2024

@zbeekman I skipped the green book and got the red book last year. :)

from datetime-fortran.

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.