Comments (7)
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.
@zbeekman Did not know about this feature. Is it F2008?
from datetime-fortran.
@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.
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.
@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.
Get the green one! (Or see when they're going to publish their next book... maybe Fortran 2015 will be covered)
from datetime-fortran.
@zbeekman I skipped the green book and got the red book last year. :)
from datetime-fortran.
Related Issues (20)
- Document building with cmake and autotools HOT 1
- Define output (write) methods for datetime and timedelta instances HOT 1
- strptime does not handle errors HOT 1
- Cannot set seconds or others of timedelta HOT 3
- strptime does not zero tm struct before calling c_strptime HOT 1
- Error invoking datetime constructor with ifort-17.0.5 HOT 10
- Very strange (possibly compiler) bug with date2num HOT 3
- incorrect literal with REAL64 kind HOT 8
- add support for mingw HOT 1
- Can't build tests on win-ifort. Fails on linker with strptime HOT 4
- "undefined reference" when using datetime-fortran HOT 7
- Building with autotools (not all libs are copied) HOT 9
- Dealing with huge timedelta values HOT 5
- Generic procedure including a sub-class of TimeDelta HOT 3
- Bug in function now() HOT 2
- Strptime Undefined Reference Error HOT 7
- Hour comparison in num2date is incorrect HOT 2
- Function that ingests ISO format and returns datetime? HOT 1
- CMake uses different compiler flags to autotools HOT 6
- Processing of `secondsSinceEpoch` and its reverse processing routine. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datetime-fortran.