May 18, 2006 - George H. Fisher
----------------------------------------------
The C/Fortran callable version of SDF:
----------------------------------------------
The source code for version-0.59-3 of the SDF i/o software is contained
in 2 files, sdf_subs.c and sdf_subs.h
Thus far, the SDF code has been successfully compiled and
tested in Linux (x86 and x86_64), Solaris, Mac OS X, and Windows XP.
There is a Makefile; to compile, just type make. In a unix environment,
this should create a linkable object, sdf_subs.o, and a library, libsdf.a .
It will also compile an executable command-line sdf file browser, sdf_browse .
If you want to use a different compiler from gcc, change the COMPILER
setting in Makefile.
If you are on a Solaris system make sure you use gnu make ('gmake') and not
Sun's make, which seems to generate spurious error messages about
unexpected ends of lines.
Make clean will remove all the objects, libraries, the sdf_browse
executable, and the example programs xtestmain, xtestf77, xtest_dyn_f95,
and xtest_transp_f95.
In MS Windows, the make file works fine under the mingw and msys
environments, at least using the mingw 3.1.0-1 installation package
(MinGW-3.1.0-1.exe) , and version 1.10 of msys (MSYS-1.0.10.exe) .
Mingw and msys are free software that can be downloaded
from www.mingw.org . Mingw stands for "minimal gnu for windows" and
provides a self-consistent package of the gcc compiler suite and gdb debugger
that link against existing Microsoft C libraries that are present in
most windows installations. Msys provides a unix-like shell environment
from which the mingw compilers and debuggers and make commands can be run.
Programs successfully compiled under mingw should work on most windows machines.
Mingw only includes the Fortran 77 compiler g77
as part of the compiler suite, but a free fortran 95 compiler, g95,
that works with mingw can be downloaded from www.g95.org .
One can now download mingw compatible versions of gfortran, the open source
fortran 95 compiler that is part of gcc version 4.
There are several versions of compiler flags in the Makefile, either for
debugging or for optimization. Pick the version you want and uncomment it.
If you pick a version with profiling ( with the -pg option) you may need to
add a -lgprof in addition to -lsdf in the appropriate lines of the Makefile.
To install the library and include file into the usual spots in /usr/local,
on a unix system, become root and type "make install". This will also
install an executable sdf file browser program sdf_browse in /usr/local/bin .
To link the sdf library into your fortran program barf.f creating
executable xbarf, these commands should work (according to these 4 compilers:
g77: g77 barf.f -lsdf -o xbarf
g95: g95 barf.f -lsdf -o xbarf
ifort: ifort barf.f -lsdf -o xbarf
gfortran: gfortran barf.f -lsdf -o xbarf
If the compiler/loader complains about missing symbols for various
sdf functions, try setting -L
in the compiler commands above,
where is the directory where the library libsdf.a is located.
Important Fortran note: The sdf software assumes the Fortran standard
for the size of integers passed as arguments, which is sizeof(double)/2.
If you change the integer size from sizeof(double)/2 in the integer
arguments used in calling sdf functions,
you must make a consistent typedef for variable type intf
in sdf_subs.h, and you must modify the test for intf size in test_sizes()
in sdf_subs.c accordingly. If you don't do this, strange and
hard-to-debug things may happen.
To link the sdf library into another C program barf.c to create executable
xbarf:
gcc -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE barf.c -lsdf
-o xbarf
The C program barf.c will need to include the line
#include in the declarations part of the code.
There is a hook in the make file for my_C_prog, which could be customized
for putting in your own C program that links with the sdf library.
If the compiler can't find the header sdf_subs.h, insert a -I
into the compiler command, where is the directory containing
sdf_subs.h . Similarly, if there are undefined sdf symbols from the loader,
insert a -L into the compiler line, where is the directory
containing libsdf.a .
The Makefile includes an entry for creating a dynamic load library sdf.dll
and definitions file sdf.def if you are using mingw in windows
("make sdf.dll"). Fortran and C programs
compiled under mingw appear to also successfully link to the dll using the
same -lsdf compiler option described earlier. It is not clear whether the
resulting dll would also work for programs compiled with different
(eg MS ) compilers under windows.
Examples of the usage of SDF i/o functions can be found in sdf_f77_tests.f
for Fortran 77, and main_test_sdf.c for C. This example should compile with
g77. Examples of fortran usage with
allocatable arrays are given in test_sdf_dynamic.F90 and
test_sdf_transpose.F90 . Here, you'll need to use a Fortran 90/95 compiler
such as g95, gfortran, or ifort. These use sample sdf files
bz.sdf and sdf_example_file.sdf that are included in the distribution.
The file bz.sdf is quite large, and contains the vertical magnetic field from a
snapshot of an anelastic MHD simulation run by Dave Bercik.
Note that as of late 12/22/05 large files (> 2GB) appear to be working properly
at least for the cases I've considered thus far, at least in linux and
windows. Note that in Windows, you must be using an NTFS partition
(and not a FAT32 partition) for this to work.
---------------------------------------------------
The IDL version of SDF:
---------------------------------------------------
Put all the files in the IDL folder somewhere in your IDL path, and that
should be all that is necessary to install the IDL version of SDF.
IDL functions sdf_read, sdf_write, sdf_query, sdf_sizes, sdf_insert,
sdf_delete, sdf_insert mirror the C/Fortran callable functions, and are
"self-documenting", at least as far as the calling syntax goes; typing
in the name of the procedure should spit out the correct calling syntax.
Try exploring the contents of the two example sdf files included in the
distribution (sdf_example_file.sdf and bz.sdf) with sdf_query, sdf_read_all,
etc.
The IDL versions of sdf_insert, sdf_replace, and sdf_delete are pretty slow
when applied to datasets near the front of very large ( > 2GB) files.
The C/Fortran callable versions seem to run faster.