Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cant solve this problem 1

Status
Not open for further replies.

Tony1984

Technical User
Jul 2, 2012
20
US
Hey all
I just start writing a program by f77, but im facing a problem, while i debugging the compiler several error massege came out and i cant find a way to solve it, please see it below, if you can help i will appreciate it


Code:
       program BAY
	 implicit double precision (a-h, o-z)
	 logical jjpar, jjdat, jjth, jjg, jjrel, jjchl, jjreb,
     *      jjchb, jjgmg
c
	 common /number/ ndat, npar, iter, itmax, conver
	 common /par/ pold(25), parm(25), pdum(25), varpar(325), 
     *	       varnew(325), idum(25)
c**** 235=(25*(25+1))/2
c
	 common /dat/ e(51), e2(51), data(51), vardat(1326), 
     *        en(1326), th(51), dum(51), sig(51)
c***** 1326=)51*(51+1))/2
c
	 common /both/ g(51,25), emg(51,25)
	 common /yrpar/ param(26), parcov(26,26), ydum(26), 
     *        iydum(26), ifpar(26), iwhere(26), nparam
c	 
	 data ndatmx /51/, nparmx /25/, nnparm/26/
	 data yes /1hy/
c
	 call outall(jjpar, jjdat, jjth, jjg, jjrel, jjchl, 
     *            jjreb, jjchb, jjgmg)
c
       write (5,99999)
	 read  (5,99998) itmax, conver
	 write (6,99997) itmax, conver
c	 
	 write(5,99996)
	 read(5,99995) auto 
	 if (auto.NE.yes) go to 10
c
	 write(5,99994)
	 read(5,99993) hbase
	 write(6,99992) hbase
c
   10  call pparam(nnparm)
c
	 if(npar.GT.nparmx) go to 40
c
	 if(jjpar) call outpar
c
	 if(jjpar .AND. npar.LT.nparam) call outypr
c
   20   call setdat
c
	  call fixv
c
	 if(ndat.GT.ndatmx) go to 50
c
	 if(jjdat) call outdat
	 iter=0

   30  call theory(auto, hbase)
	 if(jjth) call outth
	 if(jjg) call outg
c
	 call newpar(jjrel, jjchl, jjreb, jjchb, jjgmg)
c
	 if(iter.LT.itmax) call outp1
	 if(iter.EQ.itmax) call outp2
c
	 call update 
	 if(iter.EQ.itmax .AND. npar.LT.nparam) call outypr
c
	 iter=iter+1
	 if(iter.LE.itmax) go to 30
c
	 call restrt
	 go to 20
c	 
   40  write(5,99991) npar, nparmx
	 stop
c
   50  write(5,99990) ndat, ndatmx
	 stop
c ***********
99999  format( 42h, How many iterations?, 11h, cov fraction? $) 
99998  format(i, f)
99997  format(32h, Max number of iteration is, i3,/7h, conver, 16hgence
     *factor is, f10.6)
99996  format(39h Do you wish to use automatic numerical, 
     *	              14h derivative?, $)
99995  format(f)
99994  format(42h What is fraction difference for automatic, 
     *	              13h derivative?, $)
99993  format(f) 
99992  format(36h automatic derivative uses step size , f10.5)
99991  format(9h, You wanna, i5, 21h, but you are allowed only, i5, 
     *17hparameter values./28h change in commons /par/ and,
     *8h /both/,,25h and in sunroutines pparam and oldp)
99990  format(9h, You wannna, i5, 21h, but you are allowed only, i5, 
     *13h data values/, 30h change in commons /dat/ and,
     *42h /both,  and in sunroutines setdat and fixv)

	 end
 
Wouldn't be too bad an idea if you posted those errormessages so we know what we are looking for.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Just on second sight, but this may have nothing to do with your errormessages:

Get rid of this h-editing, this is way out of time and a source of error.
See your first format:
Code:
99999  format( 42h, How many iterations?, 11h, cov fraction? $)

42h specifies that the following 42 characters are to be printed. I would say this gives the printout

, How many iterations?, 11h, cov fraction? $

on your screen. Is this what you wanted to have?

Much easier to program, for you do not have to count characters would be to use '

Code:
99999  format(' How many iterations?', ' cov fraction?', $)

This would give

How many iterations? cov fraction?

Which seems much more to be what you wanted to achieve (or what was this 11h good for?)

Norbert

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
this the error massege:

Compiling Fortran...
E:\bayes\bbbbb.for
E:\bayes\bbbbb.for(92) : Error: This character is not valid in a format list. [n]
99990 format(9h, You wannna, i5, 21h, but you are allowed only, i5,
^
E:\bayes\bbbbb.for(92) : Error: This character is not valid in a format list. [y]
99990 format(9h, You wannna, i5, 21h, but you are allowed only, i5,
^
E:\bayes\bbbbb.for(94) : Error: A constant or general expression must appear in a format list in this context. [both,andinsunroutinessetdatandfixv]
*42h /both, and in sunroutines setdat and fixv)
-----------^
E:\bayes\bbbbb.for(92) : Error: This character is not valid in a format list. [h]
99990 format(9h, You wannna, i5, 21h, but you are allowed only, i5,
^
E:\bayes\bbbbb.for(92) : Error: This character is not valid in a format list.
99990 format(9h, You wannna, i5, 21h, but you are allowed only, i5,
^
E:\bayes\bbbbb.for(92) : Error: This character is not valid in a format list. [r]
99990 format(9h, You wannna, i5, 21h, but you are allowed only, i5,
^
E:\bayes\bbbbb.for(92) : Error: This character is not valid in a format list. [v]
99990 format(9h, You wannna, i5, 21h, but you are allowed only, i5,
^
E:\bayes\bbbbb.for(89) : Error: This character is not valid in a format list. [n]
99991 format(9h, You wanna, i5, 21h, but you are allowed only, i5,
^
E:\bayes\bbbbb.for(89) : Error: This character is not valid in a format list. [y]
99991 format(9h, You wanna, i5, 21h, but you are allowed only, i5,
^
E:\bayes\bbbbb.for(89) : Error: This character is not valid in a format list. [m]
99991 format(9h, You wanna, i5, 21h, but you are allowed only, i5,
^
E:\bayes\bbbbb.for(80) : Error: This character is not valid in a format list. [r]
99997 format(32h, Max number of iteration is, i3,/7h, conver, 16hgence
^
Error executing df.exe.

bbbbb.obj - 11 error(s), 0 warning(s)
 
after changing the format to still have 3 errors, listed below
Code:
99999  format('How many iterations?', 'cov fraction?', $) 
99998  format(i, f)
99997  format('Max number of iteration is', i3, 'convergence factor is', f10.6)
99996  format('Do you wish to use automatic numerical derivative?', $)
99995  format(f)
99994  format('What is fraction difference for automatic derivative?', $)
99993  format(f) 
99992  format('automatic derivative uses step size', f10.5)
99991  format('You wanna', i5, 'but you are allowed only', i5, 'parameter 
     * values.'/ 'change in commons' /'par'/ 'and',
     * /'both'/,' and in sunroutines pparam and oldp')
99990  format('You wannna', i5, 'but you are allowed only', i5, 
     * 'data values'/, 'change in commons' /'dat'/ 'and',
     * /'both',  'and in sunroutines setdat and fixv')
	 end


Compiling Fortran...
E:\bayes\bbbbb.for
E:\bayes\bbbbb.for(80) : Error: Syntax error, found END-OF-STATEMENT when expecting one of: <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ) <HOLLERITH_CONSTANT> ...
99997 format('Max number of iteration is', i3, 'convergence factor is', f10.6)
-------------------------------------------------------------------------------^
E:\bayes\bbbbb.for(83) : Error: Syntax error, found END-OF-STATEMENT when expecting one of: <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ) <HOLLERITH_CONSTANT> ...
99994 format('What is fraction difference for automatic derivative?', $)
-------------------------------------------------------------------------^
E:\bayes\bbbbb.for(80) : Error: An extra comma appears in the format list. [$]
99997 format('Max number of iteration is', i3, 'convergence factor is', f10.6)
^
Error executing df.exe.

bbbbb.obj - 3 error(s), 0 warning(s)
 
Column limit is 72. Anything after column 72 is ignored. Remove the ,$ at the end of the format statements.
 
You would get rid of these problems - and others too - if you would swap to freeform fortran coding.
You would have to apply a few changes to your curent code (replacing c for commentlines by !, maybe some adaption to define continuation lines, I am not so sure about this).

On the pther hand there are some advantages:
- forget about the limit of 72 characters. This is especially a nuisance when debugging for you tend to come out with longer lines. This could give nasty errors.
- you could use longer and more telling variable names.
- you could add some comment to a line of code.

Maybe there are more.

Then there is one more general advice:
Messing with formats usually is the first step that a new programmer does to establish a relationship between himself and his programming language. Be sure, there is more to come. So take it as a necessary part of your education to figure this out with help of the docs you have about your programming environment. Of course this community here is ready to help you - but sooner or later you will have to understand how to swim yourself - better you are in easy waters when you start to learn.

Norbert

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
If you wish to use free format as suggested, just change the extension from .for to .f90 or .f95. You can't do this if you are restricted to F77 (some places only use F77 and nothing else).

Alternatively, some compilers have a line width parameter which you can add to the compile line.
 
i solve the last problem, but i faced another one please see the subroutine below, and the list of the errors:
Code:
subroutine outrel
	implicit double precision(a-h,o-z)
	common /number/ ndat, npar, iter, itmax, conver
	common /par/ pold(25), parm(25), pdum(25), varpar(325), 
     &	        varnew(325), idum(25)
	common /dat/ e(51), e2(51), data(51), vardat(1326), en(1326), 
     &	         th(51), dum(51), sig(51)
	common /both/ g(51,25), emg(51,25)
      dimension formt(4)
	data pl/1h(/, pr /1h)/
	data formt / 40h ((1x, 4(a1, i3, a1, 0pf8.0, 1pg13.5, 2x))) /
	data  aa5 / 10h.1, 1pg13.5/, aa4/ 10h.2, 1pg13.5/, aa3 /
     &	    10h.3, ipg13.5 /, aa2/ 10h.4, 1pg13.5 /, aa1 /  
     &	    10h.5, ipg13.5 /, aa0/ 10h.6, 1pg13.5 /, aa6  /  
     &	    10h.0, ipg13.5 /
	 data t1 / 10henergy     / , t2 / 10hresidual  /
	 write(6,99999)
	 go to 10
	 entry outreb
 	 write(6,99998)
10     write(6,99997) (t1,t2,i=1,4)
	 formt(3)= aa6
	 if(e(ndat).LT.1.D5) formt(3)=aa5
	 if(e(ndat).LT.1.D4) formt(3)=aa4
	 if(e(ndat).LT.1.D3) formt(3)=aa3
	 if(e(ndat).LT.1.D2) formt(3)=aa2
	 if(e(ndat).LT.1.D1) formt(3)=aa1
	 if(e(ndat).LT.1.D0) formt(3)=aa0
	 n=ndat
	 m= n/4
	 mm= m*4
	 if(mm.NE.N) go to 20
	 mm=m
	 go to 30
20     m= m+1
	    k= mm + 4 - n
	    if(k.GE.m) go to 70
	    mm= m - k
30     continue
	   im= 3*m
	   do 40 i=1, mm
	      im = im+1
	      write(6,formt) (pl, l, pr, e(l), dum(l), l=i, im, m)
40     continue
	    if(mm.EQ.m) go to 60
	    im= 2*m + mm
	    mm= mm + 1
	    do 50 i=mm, m
	         im = im+1
	         write(6,formt) (pl,l,pr,e(l),dum(l),l=i,im,m)
50     continue
60     continue
	  return
70     write(6,formt) (pl,l,pr,e(l),dum(l),l=i,im,m)
	 return
99999 format('   ***** Least-square weighted residual, at former 
     & values of parameters')
99998 format('   ***** bayesian weighted residual,  at former values
     & of parameters')
99997 format('  ' , 4(2x, a10, 2x, a10, 4x))
	end

E:\bayes\bbbbb.for(1051) : Error: Syntax error, found ')' when expecting one of: , /
data formt / 40h ((1x, 4(a1, i3, a1, 0pf8.0, 1pg13.5, 2x))) /
----------------------------------------------------------------^
E:\bayes\bbbbb.for(1052) : Error: Syntax error, found INTEGER_CONSTANT '5' when expecting one of: , /
data aa5 / 10h.1, 1pg13.5/, aa4/ 10h.2, 1pg13.5/, aa3 /
---------------------------------^
E:\bayes\bbbbb.for(1052) : Error: Syntax error, found INTEGER_CONSTANT '5' when expecting one of: , /
data aa5 / 10h.1, 1pg13.5/, aa4/ 10h.2, 1pg13.5/, aa3 /
-------------------------------------------------------^
E:\bayes\bbbbb.for(1053) : Error: Syntax error, found INTEGER_CONSTANT '5' when expecting one of: , /
& 10h.3, ipg13.5 /, aa2/ 10h.4, 1pg13.5 /, aa1 /
-------------------------^
E:\bayes\bbbbb.for(1053) : Error: Syntax error, found INTEGER_CONSTANT '5' when expecting one of: , /
& 10h.3, ipg13.5 /, aa2/ 10h.4, 1pg13.5 /, aa1 /
------------------------------------------------^
E:\bayes\bbbbb.for(1054) : Error: Syntax error, found INTEGER_CONSTANT '5' when expecting one of: , /
& 10h.5, ipg13.5 /, aa0/ 10h.6, 1pg13.5 /, aa6 /
-------------------------^
E:\bayes\bbbbb.for(1054) : Error: Syntax error, found INTEGER_CONSTANT '5' when expecting one of: , /
& 10h.5, ipg13.5 /, aa0/ 10h.6, 1pg13.5 /, aa6 /
------------------------------------------------^
E:\bayes\bbbbb.for(1055) : Error: Syntax error, found INTEGER_CONSTANT '5' when expecting one of: , /
& 10h.0, ipg13.5 /
-------------------------^
E:\bayes\bbbbb.for(1052) : Error: This Hollerith or character constant is too long and cannot be used in the current numeric context. [10H.1, 1pg13.]
data aa5 / 10h.1, 1pg13.5/, aa4/ 10h.2, 1pg13.5/, aa3 /
--------------------^
E:\bayes\bbbbb.for(1052) : Error: In this DATA statement, there are more values assigned to variables then there are variables. There must be the same number of values and variables. [5]
data aa5 / 10h.1, 1pg13.5/, aa4/ 10h.2, 1pg13.5/, aa3 /
---------------------------------^
E:\bayes\bbbbb.for(1052) : Error: This Hollerith or character constant is too long and cannot be used in the current numeric context. [10H.2, 1pg13.]
data aa5 / 10h.1, 1pg13.5/, aa4/ 10h.2, 1pg13.5/, aa3 /
------------------------------------------^
E:\bayes\bbbbb.for(1052) : Error: In this DATA statement, there are more values assigned to variables then there are variables. There must be the same number of values and variables. [5]
data aa5 / 10h.1, 1pg13.5/, aa4/ 10h.2, 1pg13.5/, aa3 /
-------------------------------------------------------^
E:\bayes\bbbbb.for(1053) : Error: This Hollerith or character constant is too long and cannot be used in the current numeric context. [10H.3, ipg13.]
& 10h.3, ipg13.5 /, aa2/ 10h.4, 1pg13.5 /, aa1 /
------------^
E:\bayes\bbbbb.for(1053) : Error: In this DATA statement, there are more values assigned to variables then there are variables. There must be the same number of values and variables. [5]
& 10h.3, ipg13.5 /, aa2/ 10h.4, 1pg13.5 /, aa1 /
-------------------------^
E:\bayes\bbbbb.for(1053) : Error: This Hollerith or character constant is too long and cannot be used in the current numeric context. [10H.4, 1pg13.]
& 10h.3, ipg13.5 /, aa2/ 10h.4, 1pg13.5 /, aa1 /
-----------------------------------^
E:\bayes\bbbbb.for(1053) : Error: In this DATA statement, there are more values assigned to variables then there are variables. There must be the same number of values and variables. [5]
& 10h.3, ipg13.5 /, aa2/ 10h.4, 1pg13.5 /, aa1 /
------------------------------------------------^
E:\bayes\bbbbb.for(1054) : Error: This Hollerith or character constant is too long and cannot be used in the current numeric context. [10H.5, ipg13.]
& 10h.5, ipg13.5 /, aa0/ 10h.6, 1pg13.5 /, aa6 /
------------^
E:\bayes\bbbbb.for(1054) : Error: In this DATA statement, there are more values assigned to variables then there are variables. There must be the same number of values and variables. [5]
& 10h.5, ipg13.5 /, aa0/ 10h.6, 1pg13.5 /, aa6 /
-------------------------^
E:\bayes\bbbbb.for(1054) : Error: This Hollerith or character constant is too long and cannot be used in the current numeric context. [10H.6, 1pg13.]
& 10h.5, ipg13.5 /, aa0/ 10h.6, 1pg13.5 /, aa6 /
-----------------------------------^
E:\bayes\bbbbb.for(1054) : Error: In this DATA statement, there are more values assigned to variables then there are variables. There must be the same number of values and variables. [5]
& 10h.5, ipg13.5 /, aa0/ 10h.6, 1pg13.5 /, aa6 /
------------------------------------------------^
E:\bayes\bbbbb.for(1055) : Error: This Hollerith or character constant is too long and cannot be used in the current numeric context. [10H.0, ipg13.]
& 10h.0, ipg13.5 /
------------^
E:\bayes\bbbbb.for(1055) : Error: In this DATA statement, there are more values assigned to variables then there are variables. There must be the same number of values and variables. [5]
& 10h.0, ipg13.5 /
-------------------------^
Error executing df.exe.
 
Tony,

these are bugs are very easy to handle. Try to figure them out with help of your documentation.
Tip: you assign literals to double precision variables.

But....

I do not know how demanding your code is going to be. To get along with this, make yourself familiar with the basic concepts of fortran. Like data types, data input and output and the like. And try to avoid spaghetty coding. And swap to a newer version of fortran, at least fortran 90/95 if available in your environment. From the nature of your errormessages it seems you are using a more contemporary compiler anyway, so you may well use the benefits.

Best would be you refer to a good textbook (search for Stephen J. Chapman's books on fortran in Amazon) and work your way through the examples there. I dare say you will get lost in your coding efforts sooner or later if you don't.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Dear gummibaer:
some times you cant find the mistakes while you codding by your self, i am trying to solve the bug, but nothing happened espically in this lines
Code:
data formt / 40h ((1x, 4(a1, i3, a1, 0pf8.0, 1pg13.5, 2x))) /
	data  aa5 / 10h.1, 1pg13.5/, aa4/ 10h.2, 1pg13.5/, aa3 /
     &	    10h.3, ipg13.5 /, aa2/ 10h.4, 1pg13.5 /, aa1 /  
     &	    10h.5, ipg13.5 /, aa0/ 10h.6, 1pg13.5 /, aa6  /  
     &	    10h.0, ipg13.5 /
 
Tony,

that was what I meant: you are tackling fairly easy to solve problems now. And you should use them to get into the move of things. See, you should start learining chasing bugs: look up the relevant documents and start checking if you observed all the rules given there for the statements the compiler indicates in the errormessages.

You would have found then that
- a data statement requires as many data entries as there are elements in an array. How many elements has formt? How many data do you give?
- a hollerith constant has the number of characters as given by the integer before the 'h'. What is your character count in formt and aa0 to aa5 in comparison?
- how many bytes are there in a double precision variable? How many bytes do you try to save to formt and aa0 to aa5 (1 letter = 1 byte)?
- is it the proper datatype to save alphanumericals to double precision variables (I guess that will cause problems executing your code)?

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Dear gummibaer:
i think i solved the problem but still one error bar, i spent 3 hours ro solve it but not working with me , please see below:
Code:
 subroutine outrel
	implicit double precision(a-h, o-z)
	common /number/ ndat, npar, iter, itmax, conver
	common /par/ pold(25), parm(25), pdum(25), varpar(325), 
     &	        varnew(325), idum(25)
	common /dat/ e(51), e2(51), data(51), vardat(1326), en(1326), 
     &	         th(51), dum(51), sig(51)
	common /both/ g(51,25), emg(51,25)
      dimension formt(5)
	data pl/1h(/, pr /1h)/
	data formt /40h((1x, 4(a1, i3, a1, 0pf8.0, 1pg13.5, 2x))) /
	data  aa5/'      '/, aa4/'      '/, aa3/'       '/,
     &      aa2/'      '/, aa1 /'     '/, aa0/'     '/, aa6/'      '/

: Error: Syntax error, found ')' when expecting one of: , /
data formt /40h((1x, 4(a1, i3, a1, 0pf8.0, 1pg13.5, 2x))) /
---------------------------------------------------------------^
 
Count those characters! Or better still, get rid of this h-format! This error would not occur if you use 'string' instead.
One of the closing bracket is character #41 after h and does not belong to the string that is saved to formt.

Norbert

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Dear gummibaer:
i really tried a lot, but its not working with me.
 
Tony,

this string here

((1x, 4(a1, i3, a1, 0pf8.0, 1pg13.5, 2x)))

is 42 characters long. If you specify 40h in front of it, this is two characters short, so the compiler suddenly finds )) in the command and does not know what to do with that.

Buuut....

If you do not mind my saying: If you cannot figure out this very easy bug - replace 40h by 42h or better write '((1x, 4(a1, i3, a1, 0pf8.0, 1pg13.5, 2x)))' - then you should think about if programming is the right thing for you to do.

I'd say, it is rather useless to continue this way. The next bugs will come - I'd say when you start the program you will find that saving a string to a real*8 variable is not so good an idea, even if the compiler does not conmplain - and you will be utterly helpless. Stand some buddy some beer to do the programming for you if you need it to be done.

Norbert

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top