/************************************************************************ f77_wrap1.c and f77_wrap2.c have now been split into 4 files to prevent compile-time memory errors (from expansion of compiler commands). f77_wrap1.c was split into f77_wrap1.c and f77_wrap3.c, and f77_wrap2.c was split into f77_wrap2.c and f77_wrap4.c: f77_wrap1.c contains routines operating on whole files and some utility routines. f77_wrap2.c contains routines operating on primary array, image, or column elements. f77_wrap3.c contains routines operating on headers & keywords. f77_wrap4.c contains miscellaneous routines. Peter's original comments: Together, f77_wrap1.c and f77_wrap2.c contain C wrappers for all the CFITSIO routines prototyped in fitsio.h, except for the generic datatype routines and features not supported in fortran (eg, unsigned integers), a few routines prototyped in fitsio2.h, which only a handful of FTOOLS use, plus a few obsolete FITSIO routines not present in CFITSIO. This file allows Fortran code to use the CFITSIO library instead of the FITSIO library without modification. It also gives access to new routines not present in FITSIO. Fortran FTOOLS must continue using the old routine names from FITSIO (ie, ftxxxx), but most of the C-wrappers simply redirect those calls to the corresponding CFITSIO routines (ie, ffxxxx), with appropriate parameter massaging where necessary. The main exception are read/write routines ending in j (ie, long data) which get redirected to C routines ending in k (ie, int data). This is more consistent with the default integer type in Fortran. f77_wrap1.c primarily holds routines operating on whole files and extension headers. f77_wrap2.c handle routines which read and write the data portion, plus miscellaneous extra routines. File created by Peter Wilson (HSTX), Oct-Dec. 1997 ************************************************************************/ #include "fitsio2.h" #include "f77_wrap.h" /*********************************************************************/ /* Iterator Functions */ /*********************************************************************/ /* Use a simple ellipse prototype for Fwork_fn to satisfy finicky compilers */ typedef struct { void *userData; void (*Fwork_fn)(PLONG_cfTYPE *total_n, ...); } FtnUserData; /* Declare protoypes to make C++ happy */ int Cwork_fn(long, long, long, long, int, iteratorCol *, void *); void Cffiter( int n_cols, int *units, int *colnum, char *colname[], int *datatype, int *iotype, long offset, long n_per_loop, void *Fwork_fn, void *userData, int *status); /******************************************************************/ /* Cffiter is the wrapper for CFITSIO's ffiter which takes most */ /* of its arguments via a structure, iteratorCol. This routine */ /* takes a list of arrays and converts them into a single array */ /* of type iteratorCol and passes it to CFITSIO. Because ffiter */ /* will be passing control to a Fortran work function, the C */ /* wrapper, Cwork_fn, must be passed in its place which then */ /* calls the Fortran routine after the necessary data */ /* manipulation. The Fortran routine is passed via the user- */ /* supplied parameter pointer. */ /******************************************************************/ void Cffiter( int n_cols, int *units, int *colnum, char *colname[], int *datatype, int *iotype, long offset, long n_per_loop, void *Fwork_fn, void *userData, int *status) { iteratorCol *cols; int i; FtnUserData FuserData; FuserData.Fwork_fn = (void(*)(PLONG_cfTYPE *,...))Fwork_fn; FuserData.userData = userData; cols = (iteratorCol *)malloc( n_cols*sizeof(iteratorCol) ); if( cols==NULL ) { *status = MEMORY_ALLOCATION; return; } for(i=0;iFwork_fn(&a1,&a2,&a3,&a4,&n_cols,units,colnum,datatype, iotype,repeat,&status,f->userData, ptrs[ 0], ptrs[ 1], ptrs[ 2], ptrs[ 3], ptrs[ 4], ptrs[ 5], ptrs[ 6], ptrs[ 7], ptrs[ 8], ptrs[ 9], ptrs[10], ptrs[11], ptrs[12], ptrs[13], ptrs[14], ptrs[15], ptrs[16], ptrs[17], ptrs[18], ptrs[19], ptrs[20], ptrs[21], ptrs[22], ptrs[23], ptrs[24] ); } /* Check whether there are any LOGICAL or STRING columns being outputted */ nstr=0; for( i=0;i