# My Modern Fortran book is now published

**URL:** <https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336>\
**Category:** Announcements\
**Created:** [October 7, 2020, 4:09pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336 "2020-10-07T16:09:22Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![Harper](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@Harper](https://fortran-lang.discourse.group/u/Harper)\
**Post date:** [April 30, 2022, 6:10am UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/63 "2022-04-30T06:10:38Z")

</div>

You can’t have unit = \* in an inquire statement: how would the system know whether you wanted input\_unit or output\_unit?

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [April 30, 2022, 6:38am UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/64 "2022-04-30T06:38:34Z")

</div>

Without some other flag or option I cannot think of a way, but I thought someone told me you could when he was asking why I virtually never use asterisk (any more; I used to). So I guess that is still a valid reason to prefer using unit number labels. Oddities between compilers and/or operating systems on whether \* and 5 and 6 referred to the same connection or not, whether closing or rewinding affected the \*-associated file, and so on caused enough issues with portability that once the ISO\_FORTRAN\_ENV implementation because common enough I essentially quit using asterisks; so I have not even paid attention to whether some of those questions/differences have been standardized or not. Getting off-topic from the book, but if the book is updated, the problems with asterisk and INQUIRE/REWIND/OPEN and padding and delimiters and such is worth mentioning, perhaps.

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [April 30, 2022, 7:28am UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/65 "2022-04-30T07:28:21Z")

</div>

I noticed this thread a bit late, but better late than never…  
Congratulations @milancurcic for your book, and best wishes for its journey in the market! I am pretty sure I will find useful information in it - especially in parts 3 and 4, but probably earlier as well. I ordered my printed copy - since I really _hate_ reading long texts from a computer screen - after all, nothing can replace a real book.

Besides that, I am glad another book about _ **Modern** _ Fortran is published in an era when - against any common sense - programming languages obviously, clearly, blatantly inadequate for scientific computing become more and more commonly used for that task.

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [April 30, 2022, 1:38pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/66 "2022-04-30T13:38:49Z")

</div>

Thanks a lot @Pap for your support.The book targets newcomers to Fortran, but I hope you find useful (or at least entertaining) bits here and there.🙂

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [April 30, 2022, 3:58pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/67 "2022-04-30T15:58:01Z")

</div>

> [@milancurcic](#):
>
> The book targets newcomers to Fortran

I disagree 😉 I think it’s also for “oldcomers” not familiar with some or all of the new features of Fortran 2003/2008/2018: OOP, coarrays and coroutines, C interoperability, etc. Therefore, if you learned Fortran in the 20th century, it’s a good read to quickly catch up modern Fortran.

Sincerely, at the moment my two principal Fortran books are [Modern Fortran: Building Efficient Parallel Applications](https://www.amazon.com/gp/product/1617295280) and [Modern Fortran Explained: Incorporating Fortran 2018](https://oxford.universitypressscholarship.com/view/10.1093/oso/9780198811893.001.0001/oso-9780198811893). Very different styles and objectives, but very complementary, at least for me.

---

<div class="post-metadata">

**Author:** ![nbehrnd](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@nbehrnd](https://fortran-lang.discourse.group/u/nbehrnd)\
**Post date:** [May 1, 2022, 4:17pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/68 "2022-05-01T16:17:14Z")

</div>

A brief survey about Milan’s book on [worldcat.org](https://www.worldcat.org/search?q=ti%3AModern+Fortran+au%3ACurcic&qt=advanced&dblist=638) mentions 173 participating institutions with an edition [_in print_](https://www.worldcat.org/title/modern-fortran-building-efficient-parallel-applications/oclc/1263179322&referer=brief_results) .or. as [_e-video_](https://www.worldcat.org/title/exploring-modern-fortran-basics/oclc/1273489759&referer=brief_results) (128 entries) .or. [_electronic book_](https://www.worldcat.org/title/modern-fortran/oclc/1226440192&referer=brief_results) (15 entries, survey by 2022-May-01). There is an overlap with institutions offering more than one version, and of course there are libraries to offer access to the book within a package of the online shelves by O’Reilly, Safari Online Books, etc.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [May 26, 2022, 4:55pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/69 "2022-05-26T16:55:47Z")

</div>

Milan @milancurcic,  
page 351 of your book, there is that line (middle of the page):

```fortran
call event_query(time_step_event, time_step_count)

```

with that comment in the right margin _“Blocks until the event is posted”._

I think it is a CTRL+C/CTRL+V error coming from the code at the bottom of page 350 (with `event_wait()`), as `call event_query()` is non-blocking but just returns in `time_step_count` the number of posted events.

Am I right? Page 339 you say it is non-blocking.

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [May 26, 2022, 5:05pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/70 "2022-05-26T17:05:36Z")

</div>

Thanks, @vmagnin, good catch, you’re correct. `event_query` doesn’t block. You’re also correct about how this error might have happened. 🙂

I will add to the errata.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [May 26, 2022, 5:06pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/71 "2022-05-26T17:06:15Z")

</div>

Another question is:  
is it possible to post an event to all images simultaneously? Or only to one image?  
Page 341, I don’t know if that is what you are speaking about.

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [May 26, 2022, 5:21pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/72 "2022-05-26T17:21:59Z")

</div>

> [@vmagnin](#):
>
> is it possible to post an event to all images simultaneously? Or only to one image?

I had to look into this. From my reading of MFE and the working draft of the standard, no.

If coindices to the event variable in `event post` are omitted, you’re posting to the local copy, that is, the event variable on this image. Otherwise, the co-index must be scalar. I don’t know if there’s a reason that it was designed like this, or merely an oversight.

I imagine it’d be straightforward to write a subroutine to post to all images at once.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [May 26, 2022, 7:26pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/73 "2022-05-26T19:26:57Z")

</div>

Thanks.

> [@milancurcic](#):
>
> If coindices to the event variable in `event post` are omitted, you’re posting to the local copy, that is, the event variable on this image. Otherwise, the co-index must be scalar. I don’t know if there’s a reason that it was designed like this, or merely an oversight.

Yes, that is strange. I thought omitting the codindices would send to all images… But no (and it is logical). My need is just to stop all images when the image 1 (managing a GTK window) is closed.

> [@milancurcic](#):
>
> I imagine it’d be straightforward to write a subroutine to post to all images at once.

I tried this (executed only in image 1):

```auto
    if (num_images() >= 2) then
      do i = 2, num_images()
        event post(stop_notification[i])
      end do
    end if

```

and all images are regularly doing:

```auto
call event_query(stop_notification, counter)
print *, counter

```

But the counter is non zero only in the image 4 (over 4). The images 2 and 3 receive nothing (or am I doing something wrong?).

I am using GFortran 11.2.0 + OpenCoarrays 2.10.0 under Ubuntu 22.04.  
I have also tried to use `image_status(1)` but it does not seem to be implemented yet in OpenCoarrays.

I have now tried with ifort and it’s worse: no image received any event.

I have also tried to add a sync all before or after the `event post`. No success.

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [May 26, 2022, 8:15pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/74 "2022-05-26T20:15:20Z")

</div>

@vmagnin Can you post the complete program? I could look at it and try it on my end.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [May 26, 2022, 8:38pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/75 "2022-05-26T20:38:38Z")

</div>

Thanks @milancurcic , I will push it tomorrow (22:37 here!). And open a new post.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [February 10, 2024, 6:01pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/76 "2024-02-10T18:01:03Z")

</div>

Dear Milan @milancurcic,

I have found a typo page 246 of your book (listing 9.2 _A function to average an array of integers_). The comment on the right of that line:

```fortran
integer, intent(in) :: x(:)

```

states _“Assumed size, one dimensional **real** array”_ instead of _integer_.

(Obviously due to a CTRL+C/CTRL+V of the listing 9.1 on the previous page).

* * *

And my naive question is: do generic procedures also work with `intent(inout)` ot `intent(out)` arguments?  
I would like to have three procedures returning several integers which could be `int8`, `int16` or `int32`.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [February 10, 2024, 7:07pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/77 "2024-02-10T19:07:40Z")

</div>

> [@vmagnin](#):
>
> And my naive question is: do generic procedures also work with `intent(inout)` ot `intent(out)` arguments?  
> I would like to have three procedures returning several integers which could be `int8`, `int16` or `int32`.

You could create an `interface` with `module procedure`s, for example

```auto
module m
use iso_fortran_env, only: int32, int64
implicit none
interface twice
   module procedure twice_int32, twice_int64
end interface twice
contains
subroutine twice_int32(i)
integer(kind=int32), intent(in out) :: i
i = 2*i
end subroutine twice_int32
!
subroutine twice_int64(i)
integer(kind=int64), intent(in out) :: i
i = 2*i
end subroutine twice_int64
end module m

```

What you can’t do is pass the kind as a separate argument, as some intrinsic procedures, such as `real`, allow.

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [February 11, 2024, 2:10pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/78 "2024-02-11T14:10:17Z")

</div>

Thank you! You can use any intent but you can’t use intent alone to distinguish between specific procedures; it needs to be a distinguishable type, kind, or rank.

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [February 12, 2024, 3:25pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/79 "2024-02-12T15:25:29Z")

</div>

> [@vmagnin](#):
>
> states _“Assumed size, one dimensional **real** array”_ instead of _integer_.

Also worth noting that that is an assumed shape, not assumed size array.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [February 12, 2024, 3:41pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/80 "2024-02-12T15:41:10Z")

</div>

Indeed, “assumed-shape” like in listings 5.18 and 3.11.

The difference is explained page 307:

> This is a somewhat obscure feature of Fortran called _assumed-size_ arrays (in contrast to assumed shape) and applies to array or character string arguments to C functions. It’s there for easier interfacing with C functions, but otherwise you shouldn’t ever use it in pure Fortran programs.

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [February 12, 2024, 3:47pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/81 "2024-02-12T15:47:07Z")

</div>

You missed my favorite part from this–the quote from Walter Brainerd. 🙂

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [February 12, 2024, 3:48pm UTC](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336/82 "2024-02-12T15:48:26Z")

</div>

> It’s there for easier interfacing with C functions, but otherwise you shouldn’t ever use it in pure Fortran programs. To quote the late Walter Brainerd in his book Guide to Fortran 2008 Programming: “Do not ask why—just do it.”

😉

And this is your example of an assumed-size array (which uses a star instead of a colon for assumed-shape):

```fortran
character(c_char), intent(out) :: buf(*)

```

(does the difference could be somehow related to the fact that C arrays start at 0?)

[Previous page](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336.md?page=3)

[Next page](https://fortran-lang.discourse.group/t/my-modern-fortran-book-is-now-published/336.md?page=5)
