Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Problems in reading data file T.T

harry27606
Beginner
714 Views

This is the simplified logic of the part that I am working on in my program.

There is a main input file with the extension of *.dat

1. When my program find the character string transient boundary condition (TBC) in it,

2. program looks for *.chm data file.

a. If there is no *.chm file, then stop and print error message to the screen/output file.

b. If *.chm file exists,

i. Open/read it

ii. Calculate transient boundary chemistry

This is what I am trying to do. At this point, even though I have TBC in input file and dont have *.chm, my program keep calculating other things. It must stop and print error message!!!

I think there must be very simple (and stupid T.T) mistakes, but I cannot find it. Please take a look at my source file and give me some suggestions. Thanks.

c ----------------------------------------------------------------------

c subroutine initchm

c -------------------

c

c written by: Harry Kim - July __, 2004.

c

c variables have already declaired in other modules or subroutines

c ----------------------------------------------------------------------

subroutine initchm

use gen

use parm

use chem

implicit real*8 (a-h,o-z)

character subsection

logical found_subsection

external findstrg, intpolchm, opnchm

c assign transient boundary chemistry

subsection = 'transient boundary chemistry'

call findstrg (subsection,itmp,found_subsection)

if (found_subsection) then

update_chm = .true.

c else

c return

end if

c open file containing transient boundary chemistry (TBC) data

c and read initial boundary chemistry data

if (update_chm) then

call opnchm

c interpolate time-dependent chemistries on grid

call intpolchm

else

c goto 999

return

end if

c debugging information

info_debug = 0

c transient boundary chemistry

do ichem = 1,nchm

write(idbg,*) 'trschm(ichem) ',trschm(ichem)

end do

if (info_debug.gt.1) then

stop

end if

999 write(ilog,*) 'SIMULATION TERMINATED'

write(ilog,*) 'file ', prefix(:l_prfx)//'.chm missing'

stop

return

end

Message Edited by Harry27606 on 07-08-2004 12:58 AM

0 Kudos
3 Replies
Jugoslav_Dujic
Valued Contributor II
714 Views
But you didn't show us anything about how you open the .chm file?
You can test existence and open the file if OK using:
Code:
OPEN(Some_unit, file="Some_File", STATUS="OLD", IOSTAT=iError)
IF (iError.NE.0) THEN
   Stop "File "//"Some_File"//" does not exist"!
END IF

Jugoslav

P.S. Your posted source code will look much better if you use "SRC" button (but it will work only on Internet Exploder).
0 Kudos
harry27606
Beginner
714 Views
You are right. This is the next subroutine... If you have any suggestion, please let me know. Thanks.
Code:
c ----------------------------------------------------------------------
c subroutine opnchm
c ------------------
c
c open *.chm file containing transient boundary chemistry
c
c written by:      Harry Kim - July __, 2004
c
c last modified:   
c
c definition of variables:
c
c I --> on input   * arbitrary  - initialized  + entries expected
c O --> on output  * arbitrary  - unaltered    + altered
c 
c                                                                    I O
c passed:    -
c
c common: 
c gen.f:    integer*4:
c           ----------
c           ichm               = unit number, transient boundary 
c                                chemistry                            - +       
c chem.f:   real*8:
c           -------
c           dt_chm             = time increment in transient boundary - +
c                                chemistry file
c           chm_read           = time to read next boundary          - +
c                                chemistry             
c           schm(nit)          = time steps of specified input     
c                                chemistry 
c local:    integer*4:
c           ---------- 
c           nchm               = number of components related to     - +
c                                chemistry input  
c           it                 = counter (inlet chemistry points)  
c           nit                = number of input time (tbc) 
c 
c           ----------
c           logical:
c           --------
c
c           character:
c           ----------
c
c external:  mem_chm = allocate memory for one-dimensional arrays
c                       of size nchmp
c ----------------------------------------------------------------------
 
      subroutine opnchm
 
      use parm
      use gen
      use chem
      implicit real*8 (a-h,o-z)
      integer it 
      external mem_chm
c  define unit number
      ichm = 17
c  open file containing transient boundary chemistry
      open(ichm,file=prefix(:l_prfx)//'.chm', err=999, status='old')
      read(ichm,*,err=998,end=998) time_chm
c     open(ichm,file=prefix(:l_prfx)//'.chm',err=999, status='old')
 
c     open(ichm,file=prefix(:l_prfx)//'.cbcvs',err=997, status='old')

c  read time interval, number of data points and associated depths
c  and allocate memory
      read(ichm,*) dt_chm, nit
      call mem_chm
      backspace(ichm)
      read(ichm,*) dt_chm, nit, (schm(it),i=1,nit) 
      chm_read = dt_chm
c  read initial input boundary chemistry data
      read(ichm,*) (chm(it),it=1,nit)
998   write(ilog,*) 'SIMULATION TERMINATED' 
      write(ilog,*) 'error reading file ', prefix(:l_prfx)//'.chm'
      stop
999   write(ilog,*) 'SIMULATION TERMINATED' 
      write(ilog,*) 'file ', prefix(:l_prfx)//'.chm missing'
      stop
      return
      end
0 Kudos
Jugoslav_Dujic
Valued Contributor II
714 Views
Code looks OK to me -- are you positive that the file doesn't exist? (You probably want a RETURN before label 998, but that's not the issue at the moment).
In any case, you can debug it -- place a breakpoint (F9) at e.g. OPEN line, start debugger (F5), then step-by-step (F10) to see what's going on.
Jugoslav
0 Kudos
Reply