0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Fortran備忘録(2) 用途別Fortran90/95基本メモ

Posted at

ヘッダーとプリプロセッサ

!Fortranコードの一部
#include "f_condition_select.h"

#if defined CONDITION_NAME1
		print *, "This is condition1."
#elif defined CONDITION_NAME2
		print *, "This is condition2."
#else
		print *, "Condition is undefined."
#endif

この時、ファイルの拡張子を.F90とする。.f90ではプリプロセッサが認識されず、コンパイル時-cppオプションを加える必要があると何処かで読んだ。
fortranはC/C++と同様、#ifdefで一文を区切ることができる。

condition_select.h
/*ヘッダーファイルの一部*/

/* Condition Selection */

/* #define CONDITION_NAME1*/
#define CONDITION_NAME2
/* #define CONDITION_NAME3*/

ヘッダー側でincludeするマクロを決める。

データを変数に格納

integer :: i
integer :: ios
integer :: nm_data
real(8), allocatable :: sample_data(:)    !imported dat file with any row * 1 column array

open(77,file='./input/sample_data.dat')   !Any row * 1 column array per dt_sample hours

! Count data number
nm_data = 0
do
	read(77,*,iostat=ios)
	if(ios==-1) exit
	nm_data = nm_data+1
end do
allocate( sample_data(nm_data) )
rewind(77)

! Read data
do i =1, nm_data
	read(77,*) sample_data(i)
end do
close(77)

!-----
!sample_dataの使用終了後、
deallocate(sample_data)



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?