Prev: Looking for some advice on string passing and dealing with hardcoded constants
Next: use of EQUIVALENCE for a dynamical assignment of data
From: baf on 12 May 2010 00:36 On 5/11/2010 7:29 PM, ivan martin wrote: > Greetings all, > > following dpb's advice from my previous question: 'calling a subroutine with a "string constant"': > > <quote> > As you say, however, it doesn't make a whole lot of sense to code a > constant as the argument in the call; it would seem more logical for > that to be a variable read in or somehow else set. But, that wasn't the > question asked.... :) > </quote> > > I'm sorry for bringing this topic up again. I'm trying to make work some prediction program > as part of my thesis work which deals in approximating performance data of models (geometrically > similar, but small) and of real life structures (large). > > And I'm looking for your expertise advice, for I'm still adapting to fortran95 which I'm also > learning in the process. > > a) my wish is to make a subroutine for plotting which can be called from anywhere in the program, > with as little modifications as possible to the rest of the program. It is based on german dislin > library, which I have been using so far and am very satisfied with. > / I must notice, there isn't all that much fortran graphic libraries. Which I think is very damaging > in view of making fortran a language for rapid development of numerically demanding programs. / > > I have the need for it for when I run into some strange results data, that I can relatively quickly > plot it. > > I'm trying to make it in a way then upon calling I give the routine the vectors (arrays) with data, > chart title and axis titles (maybe some other small parameters, but they don't matter for now). > > The titles are always the same (i.e. they do not change with different runs of the program), but > still I cannot code them in the routine itself, since I mean to use the routine for several plots > which themselves have different titles. So I need a way to give the title name while calling the > routine itself. > > How would you go about it (not necessary code specifically, but more in a way of > organization) ? > > For example; below is an example program of dislin's plotting (this one plots 6 different plots on > screen; an example I copied off dislin's examples page). I thought of taking everything > (starting from SETPAG) into a subroutine, so I can call it again and again. I'm trying to > make it as much "self dependant" as possible (avoid as much as I can of hardcoding any > "magic numbers" and constants) in a program. > > I'm hoping to accomplish something like: > call plot(xdata, ydata, 'my chart title', 'my x title', 'my y title') > > i.e. just to give it the data, and the necessary strings, but now I see this is a bad approach. But > I'm not sure how to make it in a different manner, yet to avoid as many bad approaches as possible. > > ! ############## > PROGRAM EXA_4 > USE DISLIN > IMPLICIT NONE > > REAL, DIMENSION (16) ::& > X = (/0.,1.,3.,4.5,6.,8.,9.,11.,12.,12.5,13.,15.,16.,17.,19.,20./),& > Y = (/2.,4.,4.5,3.,1.,7.,2.,3.,5.,2.,2.5,2.,4.,6.,5.5,4./) > CHARACTER (LEN = 60) :: CTIT = 'Interpolation Methods' > CHARACTER (LEN = 6), DIMENSION (6) ::& > CPOL = (/'SPLINE','STEM ','BARS ','STEP ','STAIRS',& > 'LINEAR'/) > INTEGER :: I,NX,NY,NYA=2700,IC > > CALL SETPAG('DA4P') > CALL DISINI() > CALL COMPLX() > CALL PAGERA() > CALL INCMRK(1) > CALL HSYMBL(25) > CALL TITLIN(CTIT,2) > CALL AXSLEN(1500,350) > CALL SETGRF('LINE','LINE','LINE','LINE') > IC=INTRGB(1.0,1.0,0.0) > CALL AXSBGD(IC) > > DO I=1,6 > CALL AXSPOS(350,NYA-(I-1)*350) > CALL POLCRV(CPOL(I)) > CALL MARKER(16) > > CALL GRAF(0.,20.,0.,5.,0.,10.,0.,5.) > NX=NXPOSN(1.) > NY=NYPOSN(8.) > CALL MESSAG(CPOL(I),NX,NY) > > CALL COLOR('RED') > CALL CURVE(X,Y,16) > CALL COLOR('FORE') > > IF(I.EQ.6) THEN > CALL HEIGHT(50) > CALL TITLE() > END IF > CALL ENDGRF() > END DO > > CALL DISFIN() > STOP > END PROGRAM EXA_4 > > ! ############## > > b) the second thing which troubles me is of numerical character. In calling the GRAF routine > in this example, it requires of me to provide several numeric parameters: > * lower and upper limit of X data for plotting > * and the first axis label and increment between labels > * (the same for Y) > > The lower and upper limits of X I know how to determine; just move through the vector of data, > and determine min. and max. values. But the first label and increment between labels baffle me. What you really want to decide is how many intervals you want (major tick marks) between the minimum and maximum value on the axis. I usually use something like 5 or 10. If you know the max and min value, then setting the first label and increment parameters is easy. > > I mentioned earlier that my program is using the same mathematics for both models and real > life constructions. As such, I do not know in which ranges my results will be. They can be between > 12 and 123 (something), and between 1234 and 12345 (something; N or lbf, for example). > > With that in mind, what is the usual practice as to determine the axis boundaries and increment > (step) so the plot has nice "round" limits. What I mean ? > I'm trying to avoid the plot starting at 1234 and having the step of 111.11 ( (12345-1234)/100 ), > for example. It is natural that the step should be 100, and according to it, the lower boundary 1230 > and upper 12400. Or something similar, but I'm sure you understand my meaning. Use something like int(log10(minval(yarray(1:n)))*10 to get a relative "round" magnitude of the values for the min and max axis numbers. BTW, dislin has a quickplot routine that does all of this dirty work for you for a quick view of your data. > > I'd really appreciate all advice all of you can give on any of the above; if you have time to help, > of course. > > My apologies for the length of the post. > > With regards, > Ivan |