Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_ascii_io.F90
Go to the documentation of this file.
1 !**************************************************************
2 ! Copyright INRIA
3 ! Authors :
4 ! CALVI project team
5 !
6 ! This code SeLaLib (for Semi-Lagrangian-Library)
7 ! is a parallel library for simulating the plasma turbulence
8 ! in a tokamak.
9 !
10 ! This software is governed by the CeCILL-B license
11 ! under French law and abiding by the rules of distribution
12 ! of free software. You can use, modify and redistribute
13 ! the software under the terms of the CeCILL-B license as
14 ! circulated by CEA, CNRS and INRIA at the following URL
15 ! "http://www.cecill.info".
16 !**************************************************************
17 
26 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27 #include "sll_working_precision.h"
28 
29  implicit none
30 
31  public :: &
38 
39  private
40 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 
47  module procedure sll_s_ascii_write_array_1d
48  module procedure sll_s_ascii_write_array_2d
49  module procedure sll_ascii_write_array_3d
50  end interface
51 
52 contains
53 
55  subroutine sll_s_ascii_file_create(file_name, file_id, error)
56 
57  character(len=*), intent(in) :: file_name
58  sll_int32, intent(out) :: error
59  sll_int32, intent(out) :: file_id
60  logical :: lopen
61 
62  error = 0
63 
64 ! do 100 file_id = 20, 99
65 !
66 ! inquire (unit=file_id, opened=lopen)
67 ! if (lopen) then
68 ! cycle
69 ! else
70 ! open (file_id, status='SCRATCH', err=100)
71 ! close (file_id, status='DELETE', err=100)
72 ! goto 200
73 ! end if
74 !
75 ! 100 continue
76 ! error = 1
77 ! 200 continue
78 ! error = 0
79 
80  open(newunit=file_id,file=file_name,form='FORMATTED',iostat=error)
81  rewind(file_id)
82 
83  end subroutine sll_s_ascii_file_create
84 
86  subroutine sll_s_ascii_file_close(file_id, error)
87  sll_int32, intent(in) :: file_id
88  sll_int32, intent(out) :: error
89 
90  close (file_id, iostat=error)
91 
92  end subroutine sll_s_ascii_file_close
93 
95  subroutine sll_ascii_write_array_0d(file_id, array, error)
96  sll_int32, intent(in) :: file_id
97  sll_int32, intent(out) :: error
98  sll_real64, intent(in) :: array
99  write (file_id, *, iostat=error) array
100  end subroutine
101 
103  subroutine sll_s_ascii_write_array_1d(file_id, array, error, num_points, array2, array3)
104  sll_int32, intent(in) :: file_id
105  sll_int32, intent(out) :: error
106  sll_real64, intent(in) :: array(:)
107  sll_int32, intent(in), optional :: num_points
108  sll_real64, intent(in), optional :: array2(:)
109  sll_real64, intent(in), optional :: array3(:)
110  sll_int32 :: i
111  character(len=30) :: rowfmt
112 
113  if (.not. present(num_points)) then
114  write (file_id, *, iostat=error) array
115  else
116  if (size(array) < num_points) then
117  print *, '#bad size for array'
118  print *, '#at line/file', __line__, __file__
119  stop
120  end if
121  if (present(array2)) then
122  if (size(array2) < num_points) then
123  print *, '#bad size for array2'
124  print *, '#at line/file', __line__, __file__
125  stop
126  end if
127  if (present(array3)) then
128  if (size(array3) < num_points) then
129  print *, '#bad size for array3'
130  print *, '#at line/file', __line__, __file__
131  stop
132  end if
133  do i = 1, num_points
134  write (file_id, *, iostat=error) array(i), array2(i), array3(i)
135  end do
136  else
137  do i = 1, num_points
138  write (file_id, *, iostat=error) array(i), array2(i)
139  end do
140  end if
141  else
142  write (rowfmt, '(a,i7,a)') '(', num_points, '(1x,g15.5))'
143  do i = 1, num_points
144  write (file_id, trim(rowfmt), iostat=error) array(i)
145  end do
146 
147  end if
148  end if
149  end subroutine
150 
152  subroutine sll_s_ascii_write_array_2d(file_id, array, error)
153  sll_int32, intent(in) :: file_id
154  sll_int32, intent(out) :: error
155  sll_real64, intent(in) :: array(:, :)
156  write (file_id, "(100(1x,g15.5))", iostat=error) array
157  end subroutine
158 
160  subroutine sll_ascii_write_array_3d(file_id, array, error)
161  sll_int32, intent(in) :: file_id
162  sll_int32, intent(out) :: error
163  sll_real64, intent(in) :: array(:, :, :)
164  write (file_id, *, iostat=error) array
165  end subroutine sll_ascii_write_array_3d
166 
167 
169  subroutine sll_s_ascii_write_array_1d_as_row(file_id,array,num_points)
170  sll_int32 , intent(in) :: file_id
171  sll_real64, intent(in) :: array(:)
172  sll_int32, intent(in) :: num_points
173  sll_int32 :: i
174 
175  do i=1,num_points-1
176  write(file_id, '(2g24.16)', advance='no') array(i)
177  end do
178  write(file_id, '(2g24.16)') array(num_points)
179 
180  end subroutine sll_s_ascii_write_array_1d_as_row
181 
182  end module sll_m_ascii_io
183 
Write nD array in ascii file.
Module that contains routines to write data in ASCII format file.
subroutine, public sll_s_ascii_write_array_1d(file_id, array, error, num_points, array2, array3)
Write a 1d array ASCII format.
subroutine, public sll_s_ascii_file_close(file_id, error)
Close ASCII file.
subroutine, public sll_s_ascii_write_array_1d_as_row(file_id, array, num_points)
Write a 1d array ASCII format.
subroutine sll_ascii_write_array_3d(file_id, array, error)
Write a 3d array ASCII format.
subroutine, public sll_s_ascii_file_create(file_name, file_id, error)
Create ASCII file.
subroutine sll_ascii_write_array_0d(file_id, array, error)
Write a 1d array ASCII format.
subroutine, public sll_s_ascii_write_array_2d(file_id, array, error)
Write a 2d array ASCII format.
    Report Typos and Errors