My Project
Functions/Subroutines | Variables
m_fileio Module Reference

Functions/Subroutines

subroutine z_fileio (filename, qual, iufind, iunit, iostat)
 
subroutine z_fclose (iunit)
 
subroutine z_flunit (iunit, ierr)
 

Variables

integer, parameter i_print =0
 
integer, parameter i_out =6
 
integer i_log
 
integer i_prt
 
integer i_tst
 
integer lu_err
 
integer lu_inp
 
integer lu_log
 
integer lu_prt
 
integer lu_tst
 
character(len=80) tempfile
 

Function/Subroutine Documentation

◆ z_fclose()

subroutine m_fileio::z_fclose ( integer, intent(inout)  iunit)

Definition at line 446 of file swmod3.f90.

446 !-----------------------------------------------------------------------------!
447 !
448 ! +-------+ ALKYON Hydraulic Consultancy & Research
449 ! | | Gerbrant van Vledder
450 ! | +---+
451 ! | | +---+
452 ! +---+ | |
453 ! +---+
454 !
455 !
456 ! SWAN (Simulating WAves Nearshore); a third generation wave model
457 ! Copyright (C) 2004-2005 Delft University of Technology
458 !
459 ! This program is free software; you can redistribute it and/or
460 ! modify it under the terms of the GNU General Public License as
461 ! published by the Free Software Foundation; either version 2 of
462 ! the License, or (at your option) any later version.
463 !
464 ! This program is distributed in the hope that it will be useful,
465 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
466 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
467 ! GNU General Public License for more details.
468 !
469 ! A copy of the GNU General Public License is available at
470 ! http://www.gnu.org/copyleft/gpl.html#SEC3
471 ! or by writing to the Free Software Foundation, Inc.,
472 ! 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
473 !
474 !
475  implicit none
476 !
477 ! 0. Update history
478 !
479 ! 0.01 24/08/2000 First version
480 !
481 ! 1. Purpose
482 !
483 ! Close file with unit number IUNIT, and set IUNIT=-1
484 !
485 ! 2. Method
486 !
487 !
488 ! 3. Parameter list
489 !
490 !Type I/O Name Description
491 !-----------------------------------------------------------------------------
492  integer, intent(inout) :: iunit ! Unit number
493 !-----------------------------------------------------------------------------
494  close(iunit)
495  iunit = -1
496 !
497  return
Here is the caller graph for this function:

◆ z_fileio()

subroutine m_fileio::z_fileio ( character(len=*), intent(inout)  filename,
character(len=2), intent(in)  qual,
integer, intent(in)  iufind,
integer, intent(inout)  iunit,
integer, intent(out)  iostat 
)

Definition at line 147 of file swmod3.f90.

147 !-----------------------------------------------------------------------------!
148 !
149 ! +-------+ ALKYON Hydraulic Consultancy & Research
150 ! | | Gerbrant van Vledder
151 ! | +---+
152 ! | | +---+
153 ! +---+ | |
154 ! +---+
155 !
156 !
157 ! SWAN (Simulating WAves Nearshore); a third generation wave model
158 ! Copyright (C) 2004-2005 Delft University of Technology
159 !
160 ! This program is free software; you can redistribute it and/or
161 ! modify it under the terms of the GNU General Public License as
162 ! published by the Free Software Foundation; either version 2 of
163 ! the License, or (at your option) any later version.
164 !
165 ! This program is distributed in the hope that it will be useful,
166 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
167 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
168 ! GNU General Public License for more details.
169 !
170 ! A copy of the GNU General Public License is available at
171 ! http://www.gnu.org/copyleft/gpl.html#SEC3
172 ! or by writing to the Free Software Foundation, Inc.,
173 ! 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
174 !
175 !
176  use m_parall
177  implicit none
178 !
179 ! 0. Update history
180 !
181 ! 24/07/1999 First version
182 ! 28/09/1999 Module name changed from FILEOPEN -> Z_FILEIO
183 ! 27/10/1999 Option to delete an existing file added
184 ! 18/11/1999 Argument IUNIT used to control use of Z_FLUNIT
185 ! 22/11/1999 Parameter iunit not changed unless by z_flunit
186 ! 28/12/1999 Interface with Z_FLUNIT updated and
187 ! input parameter iufind added
188 ! 14/04/2000 Module m_fileio included in this routine
189 ! 25/05/2000 Module m_fileio excluded, if an already opened file is
190 ! found, the corresponding unit number is assigned to output
191 ! 21/09/2001 Form=binary added, extension to Fortran 95 standard
192 ! 5/10/2001 Form=fixed Record length, as specified in input argument
193 ! 17/06/2002 Initialisation of IUNIT=-1 included
194 ! 24/08/2002 Bug fixed when routine called with IUFIND=0
195 ! 08/02/2003 Bug fixed when file could not be created due to invalid path
196 ! 27/08/2004 Appending node number to FILENAME in case of parallel computing
197 !
198 ! 1. Purpose
199 !
200 ! Open file with name FILENAME and determine unit number IUNIT
201 ! With file type determined in QUAL
202 !
203 ! Depending on the value of IUFIND a search is performed for a
204 ! free unit number
205 !
206 ! 2. Method
207 !
208 ! If file exists then
209 ! if QUAL = 'D'
210 ! delete file
211 ! Else
212 ! inquire if file opened
213 ! If opened
214 ! determine unit number
215 ! Else
216 ! If iunit >= 10 Find free unit number
217 ! Open file with unit number and file qualifier
218 ! End if
219 ! End if
220 ! Else
221 ! If QUAL='SNU'
222 ! If iunit >= 10 find free unit number
223 ! Open new file with unit number and qualifier
224 ! Else
225 ! Iunit = -1 File does not exist
226 ! End if
227 ! End if
228 !
229 !
230 ! 3. Parameter list
231 !
232 !Type I/O Name Description
233 !----------------------------------------------------
234  character(len=*), intent(inout) :: filename ! File name
235  character(len=2), intent(in) :: qual ! File qualifyer
236  integer, intent(in) :: iufind ! Indicator for search of unit number
237  integer, intent(inout) :: iunit ! Unit number
238  integer, intent(out) :: iostat ! Error indicator
239 !
240 ! 4. Subroutines used
241 !
242 ! Z_FLUNIT
243 !
244 ! 5. Error messages
245 !
246 ! IUNIT > 0 File exists, is (already) connected to unit number IUNIT, or is
247 ! created and connected to unit number
248 ! IUNIT == 0 File has been deleted or does not exist
249 ! < 0 An error occurred, no file or unit number found
250 !
251 ! IOSTAT = 0 No errors detected
252 ! -1 Incorrect file qualifier
253 ! -2 Unit number does not exist
254 ! -3 Attempt to open non-existing file with status=OLD
255 ! -4 Attempt to open existing file with wrong FORMATTING
256 ! -5 Incorrect value for IUFIND: not in range [0,1]
257 ! -6 File could not be created due to,e.g. incorrect path
258 !
259 ! 6. Remarks
260 !
261 ! 1) Use of file qualifier:
262 !
263 ! 1st char: O(ld),R(eplace),S(cratch),
264 ! U(nknown),(D)elete
265 ! 2nd char: F(ormatted),U(nformatted),B(inary)
266 !
267 ! 2) Use of IUFIND
268 !
269 ! if IUFIND==0, No search is performed for a free unit number
270 ! ==1, A search is performed in routine Z_FLUNIT
271 !
272 ! 3) This routine is based on routine FOR from
273 ! SWAN version 40.00 of Delft University of Technology
274 !
275 !------------------------------------------------------------------------------
276 ! Local variables
277 !
278  character(len=7) :: cstat ! string with status of file I/O
279  character(len=11) :: cform ! string with format of file I/O
280  integer junit ! temporary unit number
281  logical lexist ! indicator if a file exists
282  logical lopen ! indicator if a file is opened
283  integer iuerr ! error indicator from Z_FLUNIT
284  integer ilpos ! start position for appending node number
285 !-------------------------------------------------------------------------------------
286 ! initialisations
287 !-------------------------------------------------------------------------------------
288  iostat = 0
289  if(iufind==1) iunit = -1
290 !
291 ! Check value of IUFIND
292 !
293  if(iufind/=0 .and. iufind/=1) then
294  if(i_print >0) write(i_out,*) &
295  'Z_FILEIO: Incorrect value for IUFIND:',iufind
296  iostat = -5
297  goto 9999
298  end if
299 !
300  if ( parll .and. iunit <= 0 ) then
301  ilpos = index( filename, ' ' )-1
302  write(filename(ilpos+1:ilpos+4),33) inode
303 33 format('-',i3.3)
304  end if
305 !
306 ! check input argument QUAL
307 !
308  if(i_print>=1) write(i_out,*) 'Z_FILEIO/A:',trim(filename),' ', &
309  qual,iunit,iostat
310 !
311  if (index('ORSUD',qual(1:1)) ==0 .or. &
312  index('FUB',qual(2:2)) ==0) then
313  if(i_print > 0) write(i_out,*) 'Incorrect file qualifier'
314  iostat = -1
315  else
316  if(qual(1:1) == 'O') cstat = 'old'
317  if(qual(1:1) == 'R') cstat = 'replace'
318  if(qual(1:1) == 'S') cstat = 'scratch'
319  if(qual(1:1) == 'U') cstat = 'unknown'
320  if(qual(1:1) == 'D') cstat = 'delete'
321 !
322  if(qual(2:2) == 'F') cform = 'formatted'
323  if(qual(2:2) == 'U') cform = 'unformatted'
324  if(qual(2:2) == 'B') cform = 'binary' ! extension to FORTRAN 95 standard
325  if(qual(2:2) == 'R') cform = 'unformatted'
326 !
327 ! Check if file exists
328 !
329  inquire(file=filename,exist=lexist)
330  if(i_print >=2) write(i_out,*) 'Z_FILEIO file exists?:', &
331  trim(filename),':',lexist
332 !
333 ! delete file if it exists and qual == 'D'
334 !
335  if(lexist .and. qual(1:1)=='D') then
336  inquire(file=filename,opened=lopen)
337  if(lopen) then
338  inquire(file=filename,number=junit)
339  else
340  if(iufind == 1) call z_flunit(iunit,iuerr)
341  junit = iunit
342  if(junit > 0) then
343  open(file=filename,unit=junit,form=cform,iostat=iostat)
344  if(iostat/=0) then
345  iostat = -4
346  goto 9999
347  end if
348  end if
349  end if
350  close(junit,status=cstat)
351  goto 9999
352  end if
353 !
354 ! if the file exists, check if it is opened
355 !
356  if(lexist) then
357  if(i_print >=2) write(i_out,*) 'Z_FILEIO: File exists:', &
358  trim(filename)
359  inquire(file=filename,opened=lopen)
360  if(lopen) then
361  if(i_print >=2) write(i_out,*) 'Z_FILEIO: File is opened:', &
362  trim(filename)
363 !
364 ! determine unit number to which this file is connected
365 ! and assign it to the output number
366 !
367  inquire(file=filename,number=junit)
368  if(i_print >=2) write(i_out,*) &
369  'Z_FILEIO: File is connected to unit:', junit
370  iunit = junit
371  else
372 !
373 ! if the file exists and not connected to a unit number, search a free unit number
374 !
375  if(i_print >=2) write(i_out,*) &
376  'Z_FILEIO: File is not connected to a unit number'
377  if(iufind==0) then
378  if(i_print >=2) write(i_out,*) &
379  'Z_FILEIO: Assign user defined unit number:',iunit
380  elseif(iufind==1) then
381  call z_flunit(iunit,iuerr)
382  if(i_print >=2) write(i_out,*) &
383  'Z_FILEIO: New unit number IUNIT:',iunit
384  end if
385  junit = iunit
386 !
387  if(junit > 0) then
388  open(file=filename,unit=junit,form=cform,status=cstat)
389  else
390  iostat = -2
391  end if
392  end if
393 !
394 ! the file does not exist, so open it and find a free unit number
395 !
396  else
397 !
398  if(i_print>=2) then
399  write(i_out,*) 'Z_FILEIO: File does not exist !'
400  write(i_out,*) 'Z_FILEIO: Qual:',qual(1:1)
401  end if
402 !
403  if(index('SRU',qual(1:1)) > 0) then
404  if(iufind==1) then
405  call z_flunit(iunit,iuerr)
406  if(i_print >=1) write(i_out,*) &
407  'Z_FILEIO: New unit number IUNIT:',iunit
408  end if
409  junit = iunit
410 !
411 ! open file to IUNIT, if possible
412 !
413  if(junit > 0) then
414  open(file=filename,unit=junit,form=cform,iostat=iuerr)
415 !
416 ! check added 8/2/2003
417 !
418  if(iuerr/=0) then
419  iunit = -1
420  iostat = -6
421  end if
422  else
423  iostat = -2
424  end if
425 !
426 ! file cannot be opened because it does not exist
427 !
428  elseif('O'==qual(1:1)) then ! File should exist
429  if(i_print>=2) write(i_out,*) &
430  'Z_FILEIO: File cannot be opened because it does not exist'
431  iostat = -3
432  end if
433  end if
434  end if
435 !
436 9999 continue
437 !
438  if(i_print>=1) write(i_out,*) 'Z_FILEIO/Z:',trim(filename),' ', &
439  qual,iunit,iostat
440 !
441  return
integer inode
Definition: swmod2.f90:881
logical parll
Definition: swmod2.f90:884
Here is the call graph for this function:
Here is the caller graph for this function:

◆ z_flunit()

subroutine m_fileio::z_flunit ( integer, intent(out)  iunit,
integer, intent(out)  ierr 
)

Definition at line 502 of file swmod3.f90.

502 !-----------------------------------------------------------------------------!
503 !
504 ! +-------+ ALKYON Hydraulic Consultancy & Research
505 ! | | Gerbrant van Vledder
506 ! | +---+
507 ! | | +---+
508 ! +---+ | |
509 ! +---+
510 !
511 !
512 ! SWAN (Simulating WAves Nearshore); a third generation wave model
513 ! Copyright (C) 2004-2005 Delft University of Technology
514 !
515 ! This program is free software; you can redistribute it and/or
516 ! modify it under the terms of the GNU General Public License as
517 ! published by the Free Software Foundation; either version 2 of
518 ! the License, or (at your option) any later version.
519 !
520 ! This program is distributed in the hope that it will be useful,
521 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
522 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
523 ! GNU General Public License for more details.
524 !
525 ! A copy of the GNU General Public License is available at
526 ! http://www.gnu.org/copyleft/gpl.html#SEC3
527 ! or by writing to the Free Software Foundation, Inc.,
528 ! 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
529 !
530 !
531  implicit none
532 !
533 ! 0. Update history
534 !
535 ! Version Date Modification
536 !
537 ! 0.01 24/07/1999 Initial version
538 ! 0.02 01/10/1999 Extra check added to ensure maximum unit number
539 ! 0.03 07/10/1999 Check of existence of uni number deleted,
540 ! since this test produces different answer
541 ! on Lahey compiler
542 ! 0.04 25/11/1999 Intent added
543 ! 0.05 24/12/1999 Module M_GENVAR added for information about range of unit numbers
544 ! 0.06 27/12/1999 Module M_GENVAR replaced by M_FILEIO
545 ! Check added for forbidden unit numbers
546 ! 0.07 28/12/1999 Internal checks added and IERR added to parameter list
547 ! 0.08 08/02/2000 User of lu_min & lu_max deleted
548 ! 0.09 14/04/2000 Module m_fileio included in this routine
549 !
550 ! 1. Purpose
551 !
552 ! Find a free unit number
553 !
554 ! 2. Method
555 !
556 ! Starting at LU_MIN till LU_MAX are investigated until
557 ! a free (i.e. not connected to a file) is found.
558 ! Use is made of the standard fortran INQUIRE function.
559 ! The values of LU_MIN and LU_MAX should be specified
560 ! in an initialisation routine
561 !
562 ! 3. Parameter list
563 !
564 !Type I/O Name Description
565 !----------------------------------------------------------
566  integer, intent(out) :: iunit ! resulting unit number
567  integer, intent(out) :: ierr ! error level
568 !
569 ! 4. Subroutines used
570 !
571 ! None
572 !
573 ! 5. Error messages
574 !
575 ! ierr=0 No errors encountered
576 ! 1 Invalud combination lu_low >= lu_high
577 ! 2 Invalid value for lu_low
578 ! 3 Invalid value for lu_high
579 ! 4 No free unit number could be found
580 !
581 ! 6. Remarks
582 !
583 ! If no free unit number if found in the range
584 ! lu_min - lu_high, then the function returns IUNIT = -1
585 !
586 ! The switch i_print can be used to generate test output
587 !
588 !----------------------------------------------------------------------------------
589 ! local parameters
590 !
591  integer junit ! counter for unit numbers
592  logical lopen ! indicator if a unit number is connected to a file
593  logical lnot ! indicates if a forbidden unit number is checked
594  integer i_not ! counter to check forbidded unit numbers
595 !
596 !---------------------------------------------------------------------------------
597 ! range of unit numbers to search
598 !
599  integer, parameter :: lu_min=60 ! minimum unit number
600  integer, parameter :: lu_max=200 ! maximum unit number
601 !
602 ! specification of forbidden unit numbers
603 !
604  integer, parameter :: lu_nr=3 ! number of forbidden unit numbers
605  integer lu_not(lu_nr) ! list of forbidden unit numbers
606 !----------------------------------------------------------------------------------
607  lu_not(1) = 100
608  lu_not(2) = 101
609  lu_not(3) = 102
610 !-----------------------------------------------------------------------------------
611 !
612  ierr = 0
613 !
614  if(i_print >= 2) then
615  write(i_out,*) 'Z_FLUNIT: forbidden :',lu_not
616  write(i_out,*) 'Z_FLUNIT: lu_min lu_max :',lu_min,lu_max
617  end if
618 !
619 ! check data specified in Module Z_FILEIO
620 !
621  if(lu_min >= lu_max) then
622  ierr = 1
623  write(i_out,*) &
624  'Z_FLUNIT: Incorrect boundaries for LU_MIN & LU_MAX:', &
625  lu_min,lu_max
626  end if
627 !
628  junit = lu_min
629 !
630  iunit = -1
631 !
632  do while (iunit ==-1)
633 !
634 ! Check if unit number is free, i.e. not in use by an opened file
635 !
636  inquire(unit=junit,opened=lopen)
637 !
638 ! check if unit number is not a forbidden unit number
639 !
640  lnot = .false.
641  do i_not=1,lu_nr
642  if(lu_not(i_not)==junit) then
643  lnot = .true.
644  if(i_print >= 1) write(i_out,*) &
645  'Z_FLUNIT: a forbidden unit number was encountered:',junit
646  end if
647  end do
648 !
649  if(lopen.or.lnot) then
650  junit = junit + 1
651  else
652  iunit = junit
653  end if
654  if(junit > lu_max) exit
655  end do
656 !
657  if(iunit < 0) then
658  write(i_out,*) &
659  'ERROR in Z_FLUNIT: No free unit number could be found'
660  end if
661 !
662  return
Here is the caller graph for this function:

Variable Documentation

◆ i_log

integer m_fileio::i_log

Definition at line 129 of file swmod3.f90.

129  integer i_log ! (0/1) Logging off/on

◆ i_out

integer, parameter m_fileio::i_out =6

Definition at line 122 of file swmod3.f90.

122  integer,parameter :: i_out=6 ! Output channel to screen

◆ i_print

integer, parameter m_fileio::i_print =0

Definition at line 119 of file swmod3.f90.

119  integer,parameter :: i_print=0 ! (0/1/2) Test output printing off/on

◆ i_prt

integer m_fileio::i_prt

Definition at line 130 of file swmod3.f90.

130  integer i_prt ! (0/1) Printing off/on

◆ i_tst

integer m_fileio::i_tst

Definition at line 131 of file swmod3.f90.

131  integer i_tst ! (0,1,2...) Test level off/on

◆ lu_err

integer m_fileio::lu_err

Definition at line 136 of file swmod3.f90.

136  integer lu_err ! standard error file

◆ lu_inp

integer m_fileio::lu_inp

Definition at line 137 of file swmod3.f90.

137  integer lu_inp ! standard input file

◆ lu_log

integer m_fileio::lu_log

Definition at line 138 of file swmod3.f90.

138  integer lu_log ! standard logging

◆ lu_prt

integer m_fileio::lu_prt

Definition at line 139 of file swmod3.f90.

139  integer lu_prt ! standard print output

◆ lu_tst

integer m_fileio::lu_tst

Definition at line 140 of file swmod3.f90.

140  integer lu_tst ! standard test output

◆ tempfile

character(len=80) m_fileio::tempfile

Definition at line 142 of file swmod3.f90.

142  character(len=80) :: tempfile ! temporary file to be used for parallel computing