Updated Tue.
Feb. 1
Creating 2D plots in C/Fortran
For 2D plotting there are now routines in C and Fortran in my
directory on Stampede2:
- /home1/00478/tg457444/502/Pgm2/Fortran
- /home1/00478/tg457444/502/Pgm2/C
You should be able to cd to your directory, and then
cp
either-Fortran-or-C-directory-above/* .
and this would copy all the files from that directory to your
account.
OK, so then what?
Each directory has a couple source files and a README file.
README-Plotting-Fortran/or/C.txt how to call the routines
- contr.f90 or contr.c - the 2D contour plotting routine
- sfc.f90 or sfc.c - the Surface routine
particularly for Fortran, do please replace your old sfc.f90
with this one.
Inside the README*.txt file is information on how to call the
routine from your program. I suggest putting a call to "contr"
inside your main program , which would be pgm2.f90 or pgm2.c.
- in C, you will have to add
the contr() prototype information to the other prototype
declarations near the top of your main pgm2.c routine.
- In Fortran, you will need
to add the INTERFACE settings to those already present near the
top of your main pgm2.f90 routine. Instructions on how to do
that are in the contr.f90 or contr.c files.
The last step to prepare your code to do the contour plots is to
change the Makefile so everything compiles OK. You would edit
"Makefile" the way you edit anything else - it is just a text
file. Here are the changes you would want to make there:
- Where it says PROGRAM =, change that to PROGRAM = pgm2.
- (yes, please change your main program to be pgm2.f90 or
pgm2.c, not pgm1)
- Change all the places where pgm1 appears in the Makefile to be
"pgm2"
- Adding contr:
- in the line that says OBJECTS =, add "contr.o" to that list.
- in the line that says SOURCE =, add contr.f90 or contr.c to
that list.
That should be all the changes you need. Then add a call to the
contr routine in your main program (pgm2.f90 or pgm2.c) after you
call your ic() routine, so you can plot contours of your 2D s1()
array or u() array or v() array. But do know that there is a trick
to not plot the ghost points of the s1 array, which is described
in the README file in each directory (Fortran or C) that you are
copying.
- in Fortran, we can use
array subscripting to tell the program to plot only the interior
(physical, not-ghost) grid points. For example, as shown in the
README, call contr( s1(1:nx,1:ny), ... This tells Fortran to
only pass the interior values to the contr() routine. when
plotting u or v, you either need to plot all the points - in
which case you tell contr that the dimensions are nx+1,ny (for
U) or nx,ny+1 (for V), or average the points to the center s1()
locations and plot that. I do the latter in my plots. One way to
do the latter - averaging velocity points to the s1 locations -
is to plot (for U): 0.5*( u( 1:nx,1:ny)+u(2:nx+1,1:ny) ) which
averages everything in X ... and gives you a nx,ny result.
- in C, I set up an array
just for plotting. I called it splot() and it has dimensions
[NX][NY] -- no ghost points. (see the README for an example). So
you can use this array for plotting s1 or s2 or u or v, as long
as you interpolate everything to the (nx,ny) dimensions of
splot. Once you have done that, you call contr in the usual way.
contr(NX,NY,splot, ... note that in copying s1 to splot() we
subtract off I1 or J1 from the array indices (see the README
file for an example) to "remove" the ghost point aspects of the
indexing, as contr() doesn't understand ghost points. See the
README file for an example of how to do this. for plotting u or
v, either plot all the points, in which case you tell contr that
the dimension are NX+1,NY (for U) or NX,NY+1 (for V), or average
the U or V values to the center s1() locations i.e. unstaggering
them. For u, you would have splot(i,j) = 0.5*( u(i,j)+u(i+1,j) )
to unstagger in the X direction for U - and then do contr(
NX,NY,splot... as before.
With those changes to your code and the Makefile, you can
hopefully then just type "make pgm2" to build the program.