Fortran runtime error bad integer for item 1 in list input

Below is the current program, everything checks out to me, except when I execute the program itself it gives me this error. Fortran runtime error: Bad integer for item 1 in list input. The first n...

To expand on francescalus’ and Vladimir F’s comments:

Catching bugs

The simplest way of debugging a program is adding a bunch of print statements. If you add these to your code, like

    implicit none
    
    !declaring the single precision for real numbers, array, and variables.
    integer :: i, firstnumber
    real*4 :: average, sum_, standarddeviation
    
    real*4, allocatable :: arrayone(:)!making sure that the array is single precision real
    
    open(unit=1,file="C:cygwin64data sets for labs and assignmentsNumbers.txt")!opening file
    
    do 
        read(1,*)firstnumber!reading the first number
        print *, 'firstnumber = ', firstnumber
    end do

    allocate(arrayone(firstnumber))!allocating the array with the first number variable obtained from previous statement
    
    close(1)
    
    do i = 2, firstnumber
    
    open(i,file="C:cygwin64data sets for labs and assignmentsNumbers.txt")
        read(i,*)
        
        print *, 'arrayone = ', arrayone
        
        sum_ = Sum(arrayone) !sums all of the numbers from arrayone
        
        print *, 'sum_= ', sum_
        
        average = Sum_/firstnumber 
        
        print *, 'average= ', average
        
        standarddeviation = sqrt(sum_ - average) * (sum_ - average)!calculates the standard deviation of the data set
        
        print *, 'standarddeviation= ', standarddeviation
        
        close(i)
    end do
    print*,"Average = "
    print*,"Standard Deviation = "

then you can see what your program is actually doing, and work out what’s going wrong.

Your current error

Your first problem is that the lines

do 
  read(1,*)firstnumber!reading the first number
end do

are performing the read operation multiple times. It will literally try to read integers from the file forever. Obviously the file is finite, so eventually it runs out of valid things to read, and throws the error you are seeing.

To fix this, you should simply get rid of the infinite loop, by removing the lines do and end do.

The empty read

Your next problem is the statement

read(i,*)

This reads from the file you just opened, but doesn’t store the results anywhere. It looks like you’re trying to populate the arrayone array, which you would do like

read(i,*) arrayone(j)

where j is the index of arrayone corresponding to the element which you want to fill.

In a loop

The other problem you have is that you’re doing a lot of things inside a loop which you should be doing outside the loop. As it stands, the code

do i = 2, firstnumber
  open(i,file="C:cygwin64data sets for labs and assignmentsNumbers.txt")
  read(i,*)
  sum_ = Sum(arrayone)
  average = Sum_/firstnumber 
  standarddeviation = sqrt(sum_ - average) * (sum_ - average)
  close(i)
end do

will:

  • open the file
  • read the first number in the file, but not store it anywhere
  • calculate the sum, average and standard deviation of the entire array arrayone, even though most of the elements of arrayone are not yet filled.
  • close the file

and it will do all of this over and over again, firstnumber times.

I suspect that what you want to do is read the firstnumber elements of arrayone from lines 2 through firstnumber+1 of the file, and only then (after the loop) calculate the sum, average, and standard deviation of arrayone.

In order to read multiple rows from your file, you should only open it once (at the statement open(unit=1...), and only close it once (using close(1), but at the end of your program). Each read statement should then read from the same file (so each should be read(1,...).

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.
  • Forums

  • Other Sciences

  • Programming and Computer Science

[Fortran] problem on reading the csv file

  • Fortran

  • Thread starter
    fortranuser

  • Start date
    Aug 29, 2012

  • Aug 29, 2012
  • #1
hi.
I have a csv file name Relative which has 24 different data set containing characters as well as numbers. It looks like
Date,Hour,Min (RH),Max (RH),Avg (RH)

2012-08-28,0,85.190,87.200,86.325

2012-08-28,1,85.390,88.570,86.775

With reference to one of the thread reply in this forum ,I wrote a fortran code to read the file which is as follows

PROGRAM CSVREAD
CHARACTER(LEN=11)::DATE
INTEGER::HR
REAL::MAX,MIN,AVG
OPEN(FILE=»RELATIVE»,UNIT=15,STATUS=»UNKNOWN»)

DO WHILE(.TRUE.)

READ(15,*,END=123)DATE,HR,MIN,MAX,AVG
WRITE(*,*)DATE,HR,MIN,MAX,AVG
END DO
123 CONTINUE
CLOSE(15)
END PROGRAM CSVREAD

This program was successfully compiled but while executing its exe file no output in the terminal.

Answers and Replies

  • Aug 30, 2012
  • #2

In above program I found out 1 mistake . The file to be opened was Relative instead RELATIVE. Again on executing exe file i got error message .

At line 9 of file csvread.f90 (unit = 15, file = ‘Relative’)
Fortran runtime error: Bad integer for item 1 in list input

Again I change code to
Read(15,*,END=123) DATE
write(*,*)DATE

That case i got 24 different set of date.
But on including Date,Hour,Min (RH),Max (RH),Avg (RH)
the problem is the same

Last edited: Aug 30, 2012

  • Aug 30, 2012
  • #3
The program works just fine after removing usage of input file (opening, reading from unit 15 and closing).

I personally don’t use an explicit file unit for input files, because then I am stuck with a given file name; instead, I use re-direction…so, I simply read from the implicit standard input.

This works for me:

PROGRAM CSVREAD
CHARACTER(LEN=11)::DATE
INTEGER::HR
REAL::MAX,MIN,AVG

DO WHILE(.TRUE.)
    READ(*,*,END=123)DATE,HR,MIN,MAX,AVG
    WRITE(*,*)DATE,HR,MIN,MAX,AVG
END DO
123 CONTINUE

END PROGRAM CSVREAD

Then, execute progra like this:
Or whatever is your actual fortran file’s name and your csv file’s name…and yes, pay attention to letter’s case…Windows exercises case-preserving for you, but IT IS NOT case sensitive; Unix/Linux, on the other hand ARE case sensitive.

  • Aug 30, 2012
  • #4
The program works just fine after removing usage of input file (opening, reading from unit 15 and closing).

I personally don’t use an explicit file unit for input files, because then I am stuck with a given file name; instead, I use re-direction…so, I simply read from the implicit standard input.

This works for me:

PROGRAM CSVREAD
CHARACTER(LEN=11)::DATE
INTEGER::HR
REAL::MAX,MIN,AVG

DO WHILE(.TRUE.)
    READ(*,*,END=123)DATE,HR,MIN,MAX,AVG
    WRITE(*,*)DATE,HR,MIN,MAX,AVG
END DO
123 CONTINUE

END PROGRAM CSVREAD

Then, execute progra like this:
Or whatever is your actual fortran file’s name and your csv file’s name…and yes, pay attention to letter’s case…Windows exercises case-preserving for you, but IT IS NOT case sensitive; Unix/Linux, on the other hand ARE case sensitive.

Hi gsal.Thank you.
I have saved the fortran code in csvread.f90 and csv filename is Relative.
To compile , in terminal I have to write gfortran -o csvread.exe csvread.f90
To execute it ,in terminal I write as ./csvread.exe

removing usage of input file (opening, reading from unit 15 and closing) didnt work in my case.

  • Aug 30, 2012
  • #5
go ahead and paste a copy of what the terminal looks like from compiling the program and running it or screen shot if you cannot simply copy the text

  • Aug 31, 2012
  • #6
go ahead and paste a copy of what the terminal looks like from compiling the program and running it or screen shot if you cannot simply copy the text

Hi,
I have attached the screenshot of my terminal used in centos 6. For your information I use vi editor to write fortran program.

Attachments

  • Screenshot-3.png

  • Aug 31, 2012
  • #7
Hhhhmmm…

The error message says that there is a type discrepancy…while the program is expecting an integer, the number found in the input file (at some given time) does not seem to be one.

Go ahead and add a debugging write statement after the read to print back to the screen what you just read; also, follow that write statement with a flush…we don’t want the program to terminate and leaving stuff in the queue…we want all of it back so we know exactly which was the last line read from the input file.

Also, look into compilation flags that the gfortran compile takes…add whatever helps, like flags the report more stuff at run time, or flags for debugging purposes, tracing, etc.

Is what you are presenting your actual entire program? or is your program larger than this with other read statements somewhere else? reading something else from the Relative file, etc?…because that way I see, the error does not quite make sense or something…unless the message is not 100% precise…we shall see.

Please attach both your latest source code and your actual Relative file. I say attach, because I don’t want you copy and paste and possibly eliminate characters from the actual file, etc.

…so, please attach, if you still can’t make the program run after reviewing it one more time on the basis of the above hints.

Suggested for: [Fortran] problem on reading the csv file

  • Last Post
  • Jun 15, 2022
  • Last Post
  • Feb 27, 2021
  • Last Post
  • Mar 23, 2021
  • Last Post
  • Feb 20, 2021
  • Last Post
  • Mar 12, 2019
  • Last Post
  • Aug 11, 2022
  • Last Post
  • Apr 1, 2019
  • Last Post
  • May 27, 2020
  • Last Post
  • Feb 26, 2021
  • Last Post
  • Jan 10, 2021
  • Forums

  • Other Sciences

  • Programming and Computer Science

I put «Real» MATC before I even opened my project and restart two twice, but still the same error message:
ELMER SOLVER (v 7.0) STARTED AT: 2014/08/11 10:31:01
MAIN:
MAIN: =============================================================
MAIN: ElmerSolver finite element software, Welcome!
MAIN: This program is free software licensed under (L)GPL
MAIN: Copyright 1st April 1995 — , CSC — IT Center for Science Ltd.
MAIN: Webpage http://www.csc.fi/elmer, Email elmeradm@csc.fi
MAIN: Library version: 7.0 (Rev: exported)
MAIN: =============================================================
MAIN:
MAIN:
MAIN: ————————————-
MAIN: Reading Model: case.sif

Loading user function library: [HeatSolve]…[HeatSolver_Init0]
LoadMesh: Scaling coordinates: 1.000E-03 1.000E-03 1.000E-03

MAIN: ————————————-

Loading user function library: [HeatSolve]…[HeatSolver_Init]
Loading user function library: [HeatSolve]…[HeatSolver]
OptimizeBandwidth: ———————————————————
OptimizeBandwidth: Computing matrix structure for: heat equation…done.
OptimizeBandwidth: Half bandwidth without optimization: 8575
OptimizeBandwidth:
OptimizeBandwidth: Bandwidth Optimization …done.
OptimizeBandwidth: Half bandwidth after optimization: 1478
OptimizeBandwidth: ———————————————————

MAIN:
MAIN: ————————————-
MAIN: Time: 1/14 86400.000000000000
MAIN: ————————————-
MAIN:
HeatSolve:
HeatSolve:
HeatSolve: ————————————-
HeatSolve: TEMPERATURE ITERATION 1
HeatSolve: ————————————-
HeatSolve:
HeatSolve: Starting Assembly…
HeatSolve: Assembly:

: …..Assembly done
DefUtils::DefaultDirichletBCs: Setting Dirichlet boundary conditions
DefUtils::DefaultDirichletBCs: Dirichlet boundary conditions set
CRS_IncompleteLU: ILU(0) (Real), Starting Factorization:
CRS_IncompleteLU: ILU(0) (Real), NOF nonzeros: 120074
CRS_IncompleteLU: ILU(0) (Real), filling (%) : 100
CRS_IncompleteLU: ILU(0) (Real), Factorization ready at (s): 0.02

1 0.3895E-02
2 0.1909E-03
3 0.2327E-04
4 0.1216E-04
5 0.5040E-05
6 0.5204E-04
7 0.1487E-05
8 0.1616E-05
9 0.2218E-06
10 0.1219E-06
11 0.2561E-06
12 0.3507E-07
13 0.7409E-07
14 0.7608E-08
15 0.8945E-08
16 0.1223E-08
17 0.1234E-08
18 0.1603E-09
19 0.2121E-09
20 0.3031E-10
20 0.3031E-10
ComputeChange: NS (ITER=1) (NRM,RELC): ( 24.900009 2.0000000 ) :: heat equation
HeatSolve: iter: 1 Assembly: (s) 5.53 5.53
HeatSolve: iter: 1 Solve: (s) 0.16 0.16
HeatSolve: Result Norm : 24.900008502275778
HeatSolve: Relative Change : 2.0000000000000000
HeatSolve:
HeatSolve:
HeatSolve: ————————————-
HeatSolve: TEMPERATURE ITERATION 2
HeatSolve: ————————————-
HeatSolve:
HeatSolve: Starting Assembly…
HeatSolve: Assembly:

At line 2841 of file Lists.f90
Fortran runtime error: Bad real number in item 1 of list input

Hello courtois,

well … quite frankly, I didn’t really know what to choose from all these options. I don’t have Fortran experience. However, in my Makefile.inc, there seems to be no such option. Here is my Makefile.inc

SCOTCHDIR  = /usr
ISCOTCH    = -I$(SCOTCHDIR)/include/scotch 
LSCOTCH    = -L$(SCOTCHDIR)/lib -lptesmumps -lptscotch -lptscotcherr

LPORDDIR = $(topdir)/PORD/lib/
IPORD    = -I$(topdir)/PORD/include/
LPORD    = -L$(LPORDDIR) -lpord

# (parmetis is supplied by aur mpi vers):
LMETISDIR = /usr/lib
IMETIS = -I/usr/include
LMETIS    = -L$(LMETISDIR) -lparmetis -lmetis

ORDERINGSF = -Dptscotch -Dparmetis -Dpord 
ORDERINGSC  = $(ORDERINGSF)

LORDERINGS = $(LMETIS) $(LPORD) $(LSCOTCH)
IORDERINGSF = $(ISCOTCH)
IORDERINGSC = $(IMETIS) $(IPORD) $(ISCOTCH)

PLAT    =
RM = /bin/rm -f
CC = mpicc
FC = mpif90
FL = mpif90
AR = ar vr
RANLIB  = echo
# I don't have any blacs libs there, although scalapack installer reports that blacs is contained in libscalapack
SCALAP  = /opt/scalapack/lib/libscalapack.a 
# INCPAR = -I/usr/local/mpich/include
INCPAR = -I/usr/include
LIBPAR = $(SCALAP) # -L/usr/lib/openmpi/ -lmpi 
# See point 17 in the FAQ to have more details on the compilation of mpich with gfortran
INCSEQ = -I$(topdir)/libseq
LIBSEQ  =  -L$(topdir)/libseq -lmpiseq
#LIBBLAS = -L/usr/lib/xmm/ -lf77blas -latlas
# SE: (using non optimized lapack /blas)
LIBBLAS = -L/opt/scalapack/lib -lreflapack -lrefblas
LIBOTHERS = -lpthread
#Preprocessor defs for calling Fortran from C (-DAdd_ or -DAdd__ or -DUPPER)
CDEFS   = -DAdd_

#Begin Optimized options
OPTF    = -O -Dintel_ -DALLOW_NON_INIT 
OPTL    = -O 
OPTC    = -O
#End Optimized options
INC = $(INCPAR)
LIB = $(LIBPAR)
LIBSEQNEEDED =

I have:

$ mpif90 --showme
/usr/bin/gfortran -I/usr/include -pthread -I/usr/lib/openmpi -L/usr/lib/openmpi -lmpi_f90 -lmpi_f77 -lmpi -ldl -lhwloc
$ mpicc --showme
gcc -pthread -L/usr/lib/openmpi -lmpi -ldl -lhwloc

Furthermore, I compiled parmetis, metis and (pt)scotch_esmumps (as indicated by the paths above). If you could take a look at that and the config I supplied in my last post I’d be very grateful.

I also tried to install aster with the aid of setup.py (fresh install), but that always when I wanted to link against the openmpi version of mumps. I may open a new thread on this.

merci!

PS: If I recompile mumps now, I do not need to rebuild aster, correct? If no, do I need to do `make clean` or will a `make` suffice? I should probably try to systematically deselect parmetis, ptscotch…

Last edited by Anna (2012-05-07 19:41:18)


«the document you have requested to translate is already in English»

Moderators: arango, robertson

jihene

Posts: 14
Joined: Wed Mar 16, 2005 4:56 pm
Location: Institut Préparatoire aux études d’ingénieurs de T

Fortran error after succeeding roms compilation

#1

Unread post

by jihene » Wed Jan 06, 2016 7:47 am

Hi all,
I have recently used a new version of fortran compiler. The ROMS compilation succeed but when i run:
mpirun -np 4 ./oceanM ocean3gridnest.in

the following error occurs:
At line 919 of file inp_par.f90
Fortran runtime error: Bad integer for item 1 in list input
At line 919 of file inp_par.f90
Fortran runtime error: Bad integer for item 1 in list input
At line 919 of file inp_par.f90
Fortran runtime error: Bad integer for item 1 in list input
At line 919 of file inp_par.f90
Fortran runtime error: Bad integer for item 1 in list input

This line corresponds to :
READ (Vstring(is:Imul(ic)-1),*) copies
in inp_par.f90

The inp_par.F is compiled as follow :
cd Build; /usr/bin/mpif90 -c -frepack-arrays -O3 -ffast-math inp_par.f90

It seems that it can’t read string character from input file!
has anyone an idea to resolve this problem?
Thanks


User avatar

kate

Posts: 4032
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: Fortran error after succeeding roms compilation

#2

Unread post

by kate » Wed Jan 06, 2016 5:30 pm

Can you go back to an older compiler? Which compiler is it exactly? What version number?

If the compiler really is failing on good input, I would want to know which input line it is failing on and what it contains. Is this a problem only with multiple grids?


jihene

Posts: 14
Joined: Wed Mar 16, 2005 4:56 pm
Location: Institut Préparatoire aux études d’ingénieurs de T

Re: Fortran error after succeeding roms compilation

#3

Unread post

by jihene » Thu Jan 07, 2016 8:39 am

Thanks kate for your reply!
Unfortunately I can’t go back on previous version of compiler. I’ve changed the opensuse kerf’s version (from 11.3 to 13.1)and within this change comes an upgraded version of gfortran,gcc and gcc-fortran (the oldest version of gcc, gcc-fortran and gfortran are 4.6.2 and now the newest ones are 4.8.2).
I get the same error message and in the same line in inp_par.F. Even if I use mpi or openmp , simple or multiple grid. The error message is the same and occurs always in this line of the code:

READ (Vstring(is:Imul(ic)-1),*) copies

Attachments
inp_par.f90
the errot occurs in line 919
(72.56 KiB) Downloaded 188 times


User avatar

kate

Posts: 4032
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: Fortran error after succeeding roms compilation

#4

Unread post

by kate » Thu Jan 07, 2016 5:42 pm

It’s probably failing the first time through. Can you have it print Vstring, is, lmul and copies before that line? (I would of course run in the debugger…) Have you tried a lower level of compiler optimization?


jihene

Posts: 14
Joined: Wed Mar 16, 2005 4:56 pm
Location: Institut Préparatoire aux études d’ingénieurs de T

Re: Fortran error after succeeding roms compilation

#5

Unread post

by jihene » Fri Jan 08, 2016 8:01 am

HEllo kate!
Thanks again for your reply. I ‘ve just discovered that the new version of compiler recognize differently space and tab in my input file ocean.in.
I replaced tab by spaces and it works now!!
Thanks again for your help


Понравилась статья? Поделить с друзьями:

Читайте также:

  • Fortniteclient win64 shipping exe ошибка приложения 0xc000009a как исправить
  • Freelancer как изменить цвет двигателя
  • Fortnite ошибка при подборе игроков
  • Freeglut error no display callback registered for window 1
  • Fortnite ошибка при обращении к игровым серверам шкафчик

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии