Sometimes, the arrow key in python shell does not act like usually. Pressing arrow key does not gives history(previous line) but gives characters. This can be fixed by installing "gnureadline" package.
2024년 11월 13일 수요일
2024년 11월 10일 일요일
Binary file problem with intel fortran (ifort) and gfortran (GNU fortran)
I found that reading a binary file created with the same source file but compiled by ifort and gfortan give different results. By searching internet, I found that the way binary file is written in ifort is not the same sa gfortran. Thus, to make the same code gives the same results, one have to use open binary files with ACCESS='stream', FORM='unformatted'.
- Non-standard: open(unit=20,file=fname,form='binary')
- Standard: open(unit=20,file=fname,form='unformatted',access='stream',status='replace')
But, this seems to be not the full story.
I need to check the correct way to convert following gfortran code to ifort code.
open(pin_file_id, file=trim(pin_file), status='unknown',form='unformatted', &
access='direct',action='write',recl=nsize,iostat=ios)
* After testing, following seems to be equivalent to the above one.
open(pin_file_id, file=trim(pin_file), status='unknown',form='BINARY', &
access='direct',action='write',recl=nsize,iostat=ios)
* According to ChatGPT, ifort and gfortran interpret differently the recl= argument in open statement. In gfortran, 'recl' is interpreted as length of bytes. In ifort, 'recl' is interpreted as length of 4 bytes. Thus, to get the same results, if "recl= nsize" in gfortran , "recl= nsize/4" in ifort have to be used. Or/And(?) one have to use compile option in "ifort -assume byterecl .
This also imply that the "recl" in gfortran must be a multiple of 4.
* But, modifying the source code depending on the compiler or machine is not desirable. access='stream' option without 'recl=' parameter will behave similarily in both ifort and gfortran. keep form='unformatted'. status='replace' create a new file if it does not exist, or replace it if it exist. Thus, it may be better than status='unknown' to ensure freshfile in each run. (Or default status='unknown' may be okay??)
But, to access specific data, one have to use 'pos=' parameter which should be counted in whole file. For example, if data is stored as 'real(8), integer(4), real(4)', to read these
read(file_id, pos=1) real_value
read(file_id, pos=9) int_value
read(file_id, pos=13) real4_value
In other words, 'pos' specify the starting byte position, and type of variable specify the length of the data to read.