Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Holger #14

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Holger #14

wants to merge 6 commits into from

Conversation

HoWol76
Copy link
Contributor

@HoWol76 HoWol76 commented Dec 12, 2018

Add a notebook about Fortran Binary Files

"integer(kind=4) :: ii ! Still not good\n",
"```\n",
"\n",
"There is no guarantee that every compiler will use the same kind values for the same variable types.\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit overdramatic, kind=4 and kind=8 will be 32 and 64 bit respectively.

"### newunit\n",
"\n",
"Whenever you interact with a file, you need a unit, an integer value that references a specific open file.\n",
"Some I/O streams, specifically Standard Input, Standard Output, and Standard Error have compiler dependent values for these units, which unfortunately are not standardised.\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you're talking about stdout etc here, but they also have defined constants in iso_fortran_env

"\n",
"```fortran\n",
"program write_stream\n",
" use iso_fortran_env, only: int16\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to use int32, int16 isn't commonly used

"name": "stdout",
"output_type": "stream",
"text": [
"00000000 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 |................|\r\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to explain what we're looking at here, and why 1 is represented as 01 00

"\n",
"For an overview of possible data types, see [here](https://docs.scipy.org/doc/numpy/reference/arrays.interface.html#python-side).\n",
"\n",
"The integer values are correctly read in, but of course the 'H' and 'e' get mashed into a single integer value of 25928, 'll' becomes 27759, and so forth.\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I was unfamiliar with binary files I don't think this would be an 'of course' statement

"\n",
"### Python read\n",
"\n",
"To read this data in Python, you need to know the data type of the header, almost always an unsigned int, and usually 4 bytes in length:"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a 32 or 64 bit value, depending on compiler options. Also be careful about big vs little endian values. It may be useful to write a known header at the start of the file so this can be identified, but then if you're going that in depth you should be using netcdf

"source": [
"## Introduction\n",
"\n",
"Fortran is still the go-to language for number crunching."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could perhaps be either expanded or removed entirely

"```\n",
"\n",
"There is no guarantee that every compiler will use the same kind values for the same variable types.\n",
"If for some reason you can not use `iso_fortran_env`, use the `selected_int_kind` and `selected_real_kind` methods instead:\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could explain what the selected_*_kind() intrinsics do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants