├── iter_a.fit ├── iter_c.fit ├── testf77.std ├── testprog.std ├── cfitsio.pc.in ├── cfitsio.pc.cmake ├── testprog.tpt ├── drvrgsiftp.h ├── f77.inc ├── simplerng.h ├── License.txt ├── group.h ├── region.h ├── makepc.bat ├── README.MacOS ├── fitscopy.c ├── smem.c ├── iter_image.c ├── iter_var.c ├── README_OLD.win ├── cfitsio.xcodeproj └── project.pbxproj ├── sample.tpl ├── iter_b.c ├── vmsieee.c ├── README ├── eval_defs.h ├── winDumpExts.mak ├── funpack.c ├── eval_tab.h ├── iter_a.c ├── grparser.h ├── iter_b.f ├── iter_c.c ├── Makefile.in ├── drvrsmem.h ├── iter_a.f ├── fpack.h ├── pliocomp.c ├── swapproc.c ├── README.win ├── scalnull.c ├── imcopy.c ├── f77_wrap.h ├── iter_c.f ├── putcols.c └── CMakeLists.txt /iter_a.fit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/healpy/cfitsio/HEAD/iter_a.fit -------------------------------------------------------------------------------- /iter_c.fit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/healpy/cfitsio/HEAD/iter_c.fit -------------------------------------------------------------------------------- /testf77.std: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/healpy/cfitsio/HEAD/testf77.std -------------------------------------------------------------------------------- /testprog.std: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/healpy/cfitsio/HEAD/testprog.std -------------------------------------------------------------------------------- /cfitsio.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: cfitsio 7 | Description: FITS File Subroutine Library 8 | URL: https://heasarc.gsfc.nasa.gov/fitsio/ 9 | Version: @CFITSIO_MAJOR@.@CFITSIO_MINOR@.@CFITSIO_MICRO@ 10 | Libs: -L${libdir} -lcfitsio -lcurl 11 | Libs.private: -lm @LIBS@ 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /cfitsio.pc.cmake: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=@CMAKE_INSTALL_PREFIX@ 3 | libdir=@LIB_DESTINATION@ 4 | includedir=@INCLUDE_INSTALL_DIR@ 5 | 6 | Name: cfitsio 7 | Description: FITS File Subroutine Library 8 | URL: https://heasarc.gsfc.nasa.gov/fitsio/ 9 | Version: @CFITSIO_MAJOR@.@CFITSIO_MINOR@.@CFITSIO_MICRO@ 10 | Libs: -L${libdir} -lcfitsio @PKG_CONFIG_LIBS@ 11 | Libs.private: -lm 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /testprog.tpt: -------------------------------------------------------------------------------- 1 | tmpcard1 1001 this is the 1st template card 2 | tmpcard2 ABCD this is the 2nd template card 3 | tmpcard3 1001.23 this is the 3rd template card 4 | tmpcard4 1001.45 this is the 4rd template card 5 | comment this is the 5th template card 6 | history this is the 6th template card 7 | tmpcard7 = / comment for null keyword 8 | -tmpcard1 tmpcarda change the name of tmpcard1 9 | -tmpcard4 10 | end 11 | 12 | junk will be ignored 13 | -------------------------------------------------------------------------------- /drvrgsiftp.h: -------------------------------------------------------------------------------- 1 | #ifndef _GSIFTP_H 2 | #define _GSIFTP_H 3 | 4 | int gsiftp_init(void); 5 | int gsiftp_setoptions(int options); 6 | int gsiftp_getoptions(int *options); 7 | int gsiftp_getversion(int *version); 8 | int gsiftp_shutdown(void); 9 | int gsiftp_checkfile(char *urltype, char *infile, char *outfile); 10 | int gsiftp_open(char *filename, int rwmode, int *driverhandle); 11 | int gsiftp_create(char *filename, int *driverhandle); 12 | int gsiftp_truncate(int driverhandle, LONGLONG filesize); 13 | int gsiftp_size(int driverhandle, LONGLONG *filesize); 14 | int gsiftp_close(int driverhandle); 15 | int gsiftp_remove(char *filename); 16 | int gsiftp_flush(int driverhandle); 17 | int gsiftp_seek(int driverhandle, LONGLONG offset); 18 | int gsiftp_read (int driverhandle, void *buffer, long nbytes); 19 | int gsiftp_write(int driverhandle, void *buffer, long nbytes); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /f77.inc: -------------------------------------------------------------------------------- 1 | C Codes for FITS extension types 2 | integer IMAGE_HDU, ASCII_TBL, BINARY_TBL 3 | parameter ( 4 | & IMAGE_HDU = 0, 5 | & ASCII_TBL = 1, 6 | & BINARY_TBL = 2 ) 7 | 8 | C Codes for FITS table data types 9 | 10 | integer TBIT,TBYTE,TLOGICAL,TSTRING,TSHORT,TINT 11 | integer TFLOAT,TDOUBLE,TCOMPLEX,TDBLCOMPLEX 12 | parameter ( 13 | & TBIT = 1, 14 | & TBYTE = 11, 15 | & TLOGICAL = 14, 16 | & TSTRING = 16, 17 | & TSHORT = 21, 18 | & TINT = 31, 19 | & TFLOAT = 42, 20 | & TDOUBLE = 82, 21 | & TCOMPLEX = 83, 22 | & TDBLCOMPLEX = 163 ) 23 | 24 | C Codes for iterator column types 25 | 26 | integer InputCol, InputOutputCol, OutputCol 27 | parameter ( 28 | & InputCol = 0, 29 | & InputOutputCol = 1, 30 | & OutputCol = 2 ) 31 | 32 | -------------------------------------------------------------------------------- /simplerng.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple Random Number Generators 3 | - getuniform - uniform deviate [0,1] 4 | - getnorm - gaussian (normal) deviate (mean=0, stddev=1) 5 | - getpoisson - poisson deviate for given expected mean lambda 6 | 7 | This code is adapted from SimpleRNG by John D Cook, which is 8 | provided in the public domain. 9 | 10 | The original C++ code is found here: 11 | http://www.johndcook.com/cpp_random_number_generation.html 12 | 13 | This code has been modified in the following ways compared to the 14 | original. 15 | 1. convert to C from C++ 16 | 2. keep only uniform, gaussian and poisson deviates 17 | 3. state variables are module static instead of class variables 18 | 4. provide an srand() equivalent to initialize the state 19 | */ 20 | 21 | extern void simplerng_setstate(unsigned int u, unsigned int v); 22 | extern void simplerng_getstate(unsigned int *u, unsigned int *v); 23 | extern void simplerng_srand(unsigned int seed); 24 | extern double simplerng_getuniform(void); 25 | extern double simplerng_getnorm(void); 26 | extern int simplerng_getpoisson(double lambda); 27 | extern double simplerng_logfactorial(int n); 28 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | Copyright (Unpublished--all rights reserved under the copyright laws of 2 | the United States), U.S. Government as represented by the Administrator 3 | of the National Aeronautics and Space Administration. No copyright is 4 | claimed in the United States under Title 17, U.S. Code. 5 | 6 | Permission to freely use, copy, modify, and distribute this software 7 | and its documentation without fee is hereby granted, provided that this 8 | copyright notice and disclaimer of warranty appears in all copies. 9 | 10 | DISCLAIMER: 11 | 12 | THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, 13 | EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, 14 | ANY WARRANTY THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY 15 | IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 16 | PURPOSE, AND FREEDOM FROM INFRINGEMENT, AND ANY WARRANTY THAT THE 17 | DOCUMENTATION WILL CONFORM TO THE SOFTWARE, OR ANY WARRANTY THAT THE 18 | SOFTWARE WILL BE ERROR FREE. IN NO EVENT SHALL NASA BE LIABLE FOR ANY 19 | DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL OR 20 | CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, OR IN ANY WAY 21 | CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, 22 | CONTRACT, TORT , OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY 23 | PERSONS OR PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED 24 | FROM, OR AROSE OUT OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR 25 | SERVICES PROVIDED HEREUNDER. 26 | -------------------------------------------------------------------------------- /group.h: -------------------------------------------------------------------------------- 1 | #define MAX_HDU_TRACKER 1000 2 | 3 | typedef struct _HDUtracker HDUtracker; 4 | 5 | struct _HDUtracker 6 | { 7 | int nHDU; 8 | 9 | char *filename[MAX_HDU_TRACKER]; 10 | int position[MAX_HDU_TRACKER]; 11 | 12 | char *newFilename[MAX_HDU_TRACKER]; 13 | int newPosition[MAX_HDU_TRACKER]; 14 | }; 15 | 16 | /* functions used internally in the grouping convention module */ 17 | 18 | int ffgtdc(int grouptype, int xtensioncol, int extnamecol, int extvercol, 19 | int positioncol, int locationcol, int uricol, char *ttype[], 20 | char *tform[], int *ncols, int *status); 21 | 22 | int ffgtgc(fitsfile *gfptr, int *xtensionCol, int *extnameCol, int *extverCol, 23 | int *positionCol, int *locationCol, int *uriCol, int *grptype, 24 | int *status); 25 | 26 | int ffvcfm(fitsfile *gfptr, int xtensionCol, int extnameCol, int extverCol, 27 | int positionCol, int locationCol, int uriCol, int *status); 28 | 29 | int ffgmul(fitsfile *mfptr, int rmopt, int *status); 30 | 31 | int ffgmf(fitsfile *gfptr, char *xtension, char *extname, int extver, 32 | int position, char *location, long *member, int *status); 33 | 34 | int ffgtrmr(fitsfile *gfptr, HDUtracker *HDU, int *status); 35 | 36 | int ffgtcpr(fitsfile *infptr, fitsfile *outfptr, int cpopt, HDUtracker *HDU, 37 | int *status); 38 | 39 | int fftsad(fitsfile *mfptr, HDUtracker *HDU, int *newPosition, 40 | char *newFileName); 41 | 42 | int fftsud(fitsfile *mfptr, HDUtracker *HDU, int newPosition, 43 | char *newFileName); 44 | 45 | void prepare_keyvalue(char *keyvalue); 46 | 47 | int fits_path2url(char *inpath, int maxlength, char *outpath, int *status); 48 | 49 | int fits_url2path(char *inpath, char *outpath, int *status); 50 | 51 | int fits_get_cwd(char *cwd, int *status); 52 | 53 | int fits_get_url(fitsfile *fptr, char *realURL, char *startURL, 54 | char *realAccess, char *startAccess, int *iostate, 55 | int *status); 56 | 57 | int fits_clean_url(char *inURL, char *outURL, int *status); 58 | 59 | int fits_relurl2url(char *refURL, char *relURL, char *absURL, int *status); 60 | 61 | int fits_url2relurl(char *refURL, char *absURL, char *relURL, int *status); 62 | 63 | int fits_encode_url(char *inpath, int maxlength, char *outpath, int *status); 64 | 65 | int fits_unencode_url(char *inpath, char *outpath, int *status); 66 | 67 | int fits_is_url_absolute(char *url); 68 | 69 | -------------------------------------------------------------------------------- /region.h: -------------------------------------------------------------------------------- 1 | /***************************************************************/ 2 | /* REGION STUFF */ 3 | /***************************************************************/ 4 | 5 | #include "fitsio.h" 6 | #define myPI 3.1415926535897932385 7 | #define RadToDeg 180.0/myPI 8 | 9 | typedef struct { 10 | int exists; 11 | double xrefval, yrefval; 12 | double xrefpix, yrefpix; 13 | double xinc, yinc; 14 | double rot; 15 | char type[6]; 16 | } WCSdata; 17 | 18 | typedef enum { 19 | point_rgn, 20 | line_rgn, 21 | circle_rgn, 22 | annulus_rgn, 23 | ellipse_rgn, 24 | elliptannulus_rgn, 25 | box_rgn, 26 | boxannulus_rgn, 27 | rectangle_rgn, 28 | diamond_rgn, 29 | sector_rgn, 30 | poly_rgn, 31 | panda_rgn, 32 | epanda_rgn, 33 | bpanda_rgn 34 | } shapeType; 35 | 36 | typedef enum { pixel_fmt, degree_fmt, hhmmss_fmt } coordFmt; 37 | 38 | typedef struct { 39 | char sign; /* Include or exclude? */ 40 | shapeType shape; /* Shape of this region */ 41 | int comp; /* Component number for this region */ 42 | 43 | double xmin,xmax; /* bounding box */ 44 | double ymin,ymax; 45 | 46 | union { /* Parameters - In pixels */ 47 | 48 | /**** Generic Shape Data ****/ 49 | 50 | struct { 51 | double p[11]; /* Region parameters */ 52 | double sinT, cosT; /* For rotated shapes */ 53 | double a, b; /* Extra scratch area */ 54 | } gen; 55 | 56 | /**** Polygon Data ****/ 57 | 58 | struct { 59 | int nPts; /* Number of Polygon pts */ 60 | double *Pts; /* Polygon points */ 61 | } poly; 62 | 63 | } param; 64 | 65 | } RgnShape; 66 | 67 | typedef struct { 68 | int nShapes; 69 | RgnShape *Shapes; 70 | WCSdata wcs; 71 | } SAORegion; 72 | 73 | /* SAO region file routines */ 74 | int fits_read_rgnfile( const char *filename, WCSdata *wcs, SAORegion **Rgn, int *status ); 75 | int fits_in_region( double X, double Y, SAORegion *Rgn ); 76 | void fits_free_region( SAORegion *Rgn ); 77 | void fits_set_region_components ( SAORegion *Rgn ); 78 | void fits_setup_shape ( RgnShape *shape); 79 | int fits_read_fits_region ( fitsfile *fptr, WCSdata * wcs, SAORegion **Rgn, int *status); 80 | int fits_read_ascii_region ( const char *filename, WCSdata * wcs, SAORegion **Rgn, int *status); 81 | 82 | 83 | -------------------------------------------------------------------------------- /makepc.bat: -------------------------------------------------------------------------------- 1 | rem: this batch file builds the cfitsio library 2 | rem: using the Borland C++ v4.5 or new free v5.5 compiler 3 | rem: 4 | bcc32 -c buffers.c 5 | bcc32 -c cfileio.c 6 | bcc32 -c checksum.c 7 | bcc32 -c drvrfile.c 8 | bcc32 -c drvrmem.c 9 | bcc32 -c editcol.c 10 | bcc32 -c edithdu.c 11 | bcc32 -c eval_l.c 12 | bcc32 -c eval_y.c 13 | bcc32 -c eval_f.c 14 | bcc32 -c fitscore.c 15 | bcc32 -c getcol.c 16 | bcc32 -c getcolb.c 17 | bcc32 -c getcolsb.c 18 | bcc32 -c getcoli.c 19 | bcc32 -c getcolj.c 20 | bcc32 -c getcolui.c 21 | bcc32 -c getcoluj.c 22 | bcc32 -c getcoluk.c 23 | bcc32 -c getcolk.c 24 | bcc32 -c getcole.c 25 | bcc32 -c getcold.c 26 | bcc32 -c getcoll.c 27 | bcc32 -c getcols.c 28 | bcc32 -c getkey.c 29 | bcc32 -c group.c 30 | bcc32 -c grparser.c 31 | bcc32 -c histo.c 32 | bcc32 -c iraffits.c 33 | bcc32 -c modkey.c 34 | bcc32 -c putcol.c 35 | bcc32 -c putcolb.c 36 | bcc32 -c putcolsb.c 37 | bcc32 -c putcoli.c 38 | bcc32 -c putcolj.c 39 | bcc32 -c putcolui.c 40 | bcc32 -c putcoluj.c 41 | bcc32 -c putcoluk.c 42 | bcc32 -c putcolk.c 43 | bcc32 -c putcole.c 44 | bcc32 -c putcold.c 45 | bcc32 -c putcols.c 46 | bcc32 -c putcoll.c 47 | bcc32 -c putcolu.c 48 | bcc32 -c putkey.c 49 | bcc32 -c region.c 50 | bcc32 -c scalnull.c 51 | bcc32 -c swapproc.c 52 | bcc32 -c wcsutil.c 53 | bcc32 -c wcssub.c 54 | bcc32 -c imcompress.c 55 | bcc32 -c quantize.c 56 | bcc32 -c ricecomp.c 57 | bcc32 -c pliocomp.c 58 | bcc32 -c fits_hcompress.c 59 | bcc32 -c fits_hdecompress.c 60 | bcc32 -c zuncompress.c 61 | bcc32 -c zcompress.c 62 | bcc32 -c adler32.c 63 | bcc32 -c crc32.c 64 | bcc32 -c inffast.c 65 | bcc32 -c inftrees.c 66 | bcc32 -c trees.c 67 | bcc32 -c zutil.c 68 | bcc32 -c deflate.c 69 | bcc32 -c infback.c 70 | bcc32 -c inflate.c 71 | bcc32 -c uncompr.c 72 | del cfitsio.lib 73 | tlib cfitsio +buffers +cfileio +checksum +drvrfile +drvrmem 74 | tlib cfitsio +editcol +edithdu +eval_l +eval_y +eval_f +fitscore 75 | tlib cfitsio +getcol +getcolb +getcolsb +getcoli +getcolj +getcolk +getcoluk 76 | tlib cfitsio +getcolui +getcoluj +getcole +getcold +getcoll +getcols 77 | tlib cfitsio +getkey +group +grparser +histo +iraffits +modkey +putkey 78 | tlib cfitsio +putcol +putcolb +putcoli +putcolj +putcolk +putcole +putcold 79 | tlib cfitsio +putcoll +putcols +putcolu +putcolui +putcoluj +putcoluk 80 | tlib cfitsio +region +scalnull +swapproc +wcsutil +wcssub +putcolsb 81 | tlib cfitsio +imcompress +quantize +ricecomp +pliocomp 82 | tlib cfitsio +fits_hcompress +fits_hdecompress 83 | tlib cfitsio +zuncompress +zcompress +adler32 +crc32 +inffast 84 | tlib cfitsio +inftrees +trees +zutil +deflate +infback +inflate +uncompr 85 | bcc32 -f testprog.c cfitsio.lib 86 | bcc32 -f cookbook.c cfitsio.lib 87 | 88 | -------------------------------------------------------------------------------- /README.MacOS: -------------------------------------------------------------------------------- 1 | By default, the CFITSIO library will be a "Universal Binary" (i.e. 2 | 32- and 64-bit compatible) under Mac OS X when built in the standard 3 | way, i.e. 4 | 5 | - tar xzf cfitsio3370.tar.gz (or whatever version this is) 6 | - cd cfitsio/ 7 | 8 | - ./configure 9 | - make 10 | - make install 11 | 12 | --------------------------------------------------------------------- 13 | To install CFITSIO using MacPorts: 14 | --------------------------------------------------------------------- 15 | 16 | If you have MacPorts installed, you may install CFITSIO simply with 17 | the command 18 | 19 | $ sudo port install cfitsio +universal 20 | 21 | For more information, please visit: 22 | 23 | http://macports.org 24 | https://trac.macports.org/browser/trunk/dports/science/cfitsio/Portfile 25 | 26 | --------------------------------------------------------------------- 27 | To install CFITSIO using Homebrew: 28 | --------------------------------------------------------------------- 29 | 30 | If you have Homebrew installed, you may install CFITSIO simply with 31 | the command 32 | 33 | $ brew install cfitsio 34 | 35 | For more information, please visit: 36 | 37 | http://brew.sh 38 | http://brewformulas.org/Cfitsio 39 | 40 | --------------------------------------------------------------------- 41 | To build CFITSIO using the XCode GUI: 42 | --------------------------------------------------------------------- 43 | 44 | - tar xzf cfitsio3370.tar.gz (or whatever version this is) 45 | - cd cfitsio/ 46 | 47 | - Start Xcode and open cfitsio.xcodeproj/project.pbxproj, 48 | or just "open" the file from a terminal command line, 49 | 50 | $ open cfitsio.xcodeproj/project.pbxproj 51 | 52 | and this will start up XCode for you. 53 | 54 | - Press the Build (or "Play") button in the upper left 55 | corner of the GUI. 56 | 57 | --------------------------------------------------------------------- 58 | --------------------------------------------------------------------- 59 | 60 | Below, are the old (and now obsolete) instructions for building CFITSIO 61 | on classic Mac OS-9 or earlier versions: 62 | 63 | 1. Un binhex and unstuff cfitsio_mac.sit.hqx 64 | 2. put CFitsioPPC.mcp in the cfitsio directory. 65 | 2. Load CFitsioPPC.mcp into CodeWarrior Pro 5 and make. 66 | This builds the cfitsio library for PPC. There are also targets for both 67 | the test program and the speed test program. 68 | 69 | To use the MacOS port you can add Cfitsio PPC.lib to your Codewarrior Pro 5 70 | project. Note that this only has been tested for the PPC. It probably 71 | won't work on 68k macs. Also note that the fortran bindings aren't 72 | included. I haven't worked with the codewarrior f2c plugin so I don't know 73 | how these would work. If one is interested, please write and I can look 74 | into this. 75 | 76 | -------------------------------------------------------------------------------- /fitscopy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "fitsio.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | fitsfile *infptr, *outfptr; /* FITS file pointers defined in fitsio.h */ 7 | int status = 0; /* status must always be initialized = 0 */ 8 | 9 | if (argc != 3) 10 | { 11 | printf("Usage: fitscopy inputfile outputfile\n"); 12 | printf("\n"); 13 | printf("Copy an input file to an output file, optionally filtering\n"); 14 | printf("the file in the process. This seemingly simple program can\n"); 15 | printf("apply powerful filters which transform the input file as\n"); 16 | printf("it is being copied. Filters may be used to extract a\n"); 17 | printf("subimage from a larger image, select rows from a table,\n"); 18 | printf("filter a table with a GTI time extension or a SAO region file,\n"); 19 | printf("create or delete columns in a table, create an image by\n"); 20 | printf("binning (histogramming) 2 table columns, and convert IRAF\n"); 21 | printf("format *.imh or raw binary data files into FITS images.\n"); 22 | printf("See the CFITSIO User's Guide for a complete description of\n"); 23 | printf("the Extended File Name filtering syntax.\n"); 24 | printf("\n"); 25 | printf("Examples:\n"); 26 | printf("\n"); 27 | printf("fitscopy in.fit out.fit (simple file copy)\n"); 28 | printf("fitscopy - - (stdin to stdout)\n"); 29 | printf("fitscopy in.fit[11:50,21:60] out.fit (copy a subimage)\n"); 30 | printf("fitscopy iniraf.imh out.fit (IRAF image to FITS)\n"); 31 | printf("fitscopy in.dat[i512,512] out.fit (raw array to FITS)\n"); 32 | printf("fitscopy in.fit[events][pi>35] out.fit (copy rows with pi>35)\n"); 33 | printf("fitscopy in.fit[events][bin X,Y] out.fit (bin an image) \n"); 34 | printf("fitscopy in.fit[events][col x=.9*y] out.fit (new x column)\n"); 35 | printf("fitscopy in.fit[events][gtifilter()] out.fit (time filter)\n"); 36 | printf("fitscopy in.fit[2][regfilter(\"pow.reg\")] out.fit (spatial filter)\n"); 37 | printf("\n"); 38 | printf("Note that it may be necessary to enclose the input file name\n"); 39 | printf("in single quote characters on the Unix command line.\n"); 40 | return(0); 41 | } 42 | /* Open the input file */ 43 | if ( !fits_open_file(&infptr, argv[1], READONLY, &status) ) 44 | { 45 | /* Create the output file */ 46 | if ( !fits_create_file(&outfptr, argv[2], &status) ) 47 | { 48 | 49 | /* copy the previous, current, and following HDUs */ 50 | fits_copy_file(infptr, outfptr, 1, 1, 1, &status); 51 | 52 | fits_close_file(outfptr, &status); 53 | } 54 | fits_close_file(infptr, &status); 55 | } 56 | 57 | /* if error occured, print out error message */ 58 | if (status) fits_report_error(stderr, status); 59 | return(status); 60 | } 61 | -------------------------------------------------------------------------------- /smem.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #ifdef __APPLE__ 5 | #include 6 | #else 7 | #include 8 | #endif 9 | #include "fitsio.h" /* needed to define LONGLONG */ 10 | #include "drvrsmem.h" /* uses LONGLONG */ 11 | 12 | int main(int argc, char **argv) 13 | { int cmdok, listmode, longlistmode, recovermode, deletemode, id; 14 | int status; 15 | char *address; 16 | 17 | listmode = longlistmode = recovermode = deletemode = 0; 18 | id = -1; 19 | cmdok = 1; 20 | 21 | switch (argc) 22 | { case 1: listmode = 1; 23 | break; 24 | case 2: 25 | if (0 == strcmp("-l", argv[1])) longlistmode = 1; 26 | else if (0 == strcmp("-r", argv[1])) recovermode = 1; 27 | else if (0 == strcmp("-d", argv[1])) deletemode = 1; 28 | else cmdok = 0; 29 | break; 30 | case 3: 31 | if (0 == strcmp("-r", argv[1])) recovermode = 1; 32 | else if (0 == strcmp("-d", argv[1])) deletemode = 1; 33 | else 34 | { cmdok = 0; /* signal invalid cmd line syntax */ 35 | break; 36 | } 37 | if (1 != sscanf(argv[2], "%d", &id)) cmdok = 0; 38 | break; 39 | default: 40 | cmdok = 0; 41 | break; 42 | } 43 | 44 | if (0 == cmdok) 45 | { printf("usage :\n\n"); 46 | printf("smem - list all shared memory segments\n"); 47 | printf("\t!\tcouldn't obtain RDONLY lock - info unreliable\n"); 48 | printf("\tIdx\thandle of shared memory segment (visible by application)\n"); 49 | printf("\tKey\tcurrent system key of shared memory segment. Key\n"); 50 | printf("\t\tchanges whenever shmem segment is reallocated. Use\n"); 51 | printf("\t\tipcs (or ipcs -a) to view all shmem segments\n"); 52 | printf("\tNproc\tnumber of processes attached to segment\n"); 53 | printf("\tSize\tsize of shmem segment in bytes\n"); 54 | printf("\tFlags\tRESIZABLE - realloc allowed, PERSIST - segment is not\n"); 55 | printf("\t\tdeleted after shared_free called by last process attached\n"); 56 | printf("\t\tto it.\n"); 57 | printf("smem -d - delete all shared memory segments (may block)\n"); 58 | printf("smem -d id - delete specific shared memory segment (may block)\n"); 59 | printf("smem -r - unconditionally reset all shared memory segments\n\t\t(does not block, recovers zombie handles left by kill -9)\n"); 60 | printf("smem -r id - unconditionally reset specific shared memory segment\n"); 61 | } 62 | 63 | if (shared_init(0)) 64 | { printf("couldn't initialize shared memory, aborting ...\n"); 65 | return(10); 66 | } 67 | 68 | if (listmode) shared_list(id); 69 | else if (recovermode) shared_recover(id); 70 | else if (deletemode) shared_uncond_delete(id); 71 | 72 | for (id = 0; id <16; id++) { 73 | status = shared_getaddr(id, &address); 74 | if (!status)printf("id, status, address %d %d %ld %.30s\n", id, status, address, address); 75 | } 76 | return(0); 77 | } 78 | -------------------------------------------------------------------------------- /iter_image.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "fitsio.h" 5 | 6 | /* 7 | This program illustrates how to use the CFITSIO iterator function. 8 | It reads and modifies the input 'iter_image.fit' image file by setting 9 | all the pixel values to zero (DESTROYING THE ORIGINAL IMAGE!!!) 10 | */ 11 | main() 12 | { 13 | extern zero_image(); /* external work function is passed to the iterator */ 14 | fitsfile *fptr; 15 | iteratorCol cols[3]; /* structure used by the iterator function */ 16 | int n_cols; 17 | long rows_per_loop, offset; 18 | 19 | int status, nkeys, keypos, hdutype, ii, jj; 20 | char filename[] = "iter_image.fit"; /* name of rate FITS file */ 21 | 22 | status = 0; 23 | 24 | fits_open_file(&fptr, filename, READWRITE, &status); /* open file */ 25 | 26 | 27 | n_cols = 1; 28 | 29 | /* define input column structure members for the iterator function */ 30 | fits_iter_set_file(&cols[0], fptr); 31 | fits_iter_set_iotype(&cols[0], InputOutputCol); 32 | fits_iter_set_datatype(&cols[0], 0); 33 | 34 | rows_per_loop = 0; /* use default optimum number of rows */ 35 | offset = 0; /* process all the rows */ 36 | 37 | /* apply the rate function to each row of the table */ 38 | printf("Calling iterator function...%d\n", status); 39 | 40 | fits_iterate_data(n_cols, cols, offset, rows_per_loop, 41 | zero_image, 0L, &status); 42 | 43 | fits_close_file(fptr, &status); /* all done */ 44 | 45 | if (status) 46 | fits_report_error(stderr, status); /* print out error messages */ 47 | 48 | return(status); 49 | } 50 | /*--------------------------------------------------------------------------*/ 51 | int zero_image(long totalrows, long offset, long firstrow, long nrows, 52 | int ncols, iteratorCol *cols, void *user_strct ) 53 | 54 | /* 55 | Sample iterator function that calculates the output flux 'rate' column 56 | by dividing the input 'counts' by the 'time' column. 57 | It also applies a constant deadtime correction factor if the 'deadtime' 58 | keyword exists. Finally, this creates or updates the 'LIVETIME' 59 | keyword with the sum of all the individual integration times. 60 | */ 61 | { 62 | int ii, status = 0; 63 | 64 | /* declare variables static to preserve their values between calls */ 65 | static int *counts; 66 | 67 | /*--------------------------------------------------------*/ 68 | /* Initialization procedures: execute on the first call */ 69 | /*--------------------------------------------------------*/ 70 | if (firstrow == 1) 71 | { 72 | if (ncols != 1) 73 | return(-1); /* number of columns incorrect */ 74 | 75 | /* assign the input pointers to the appropriate arrays and null ptrs*/ 76 | counts = (int *) fits_iter_get_array(&cols[0]); 77 | } 78 | 79 | /*--------------------------------------------*/ 80 | /* Main loop: process all the rows of data */ 81 | /*--------------------------------------------*/ 82 | 83 | /* NOTE: 1st element of array is the null pixel value! */ 84 | /* Loop from 1 to nrows, not 0 to nrows - 1. */ 85 | 86 | for (ii = 1; ii <= nrows; ii++) 87 | { 88 | counts[ii] = 1.; 89 | } 90 | printf("firstrows, nrows = %d %d\n", firstrow, nrows); 91 | 92 | return(0); /* return successful status */ 93 | } 94 | -------------------------------------------------------------------------------- /iter_var.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "fitsio.h" 5 | 6 | /* 7 | This program illustrates how to use the CFITSIO iterator function. 8 | It reads and modifies the input 'iter_a.fit' file by computing a 9 | value for the 'rate' column as a function of the values in the other 10 | 'counts' and 'time' columns. 11 | */ 12 | main() 13 | { 14 | extern flux_rate(); /* external work function is passed to the iterator */ 15 | fitsfile *fptr; 16 | iteratorCol cols[3]; /* structure used by the iterator function */ 17 | int n_cols; 18 | long rows_per_loop, offset; 19 | 20 | int status, nkeys, keypos, hdutype, ii, jj; 21 | char filename[] = "vari.fits"; /* name of rate FITS file */ 22 | 23 | status = 0; 24 | 25 | fits_open_file(&fptr, filename, READWRITE, &status); /* open file */ 26 | 27 | /* move to the desired binary table extension */ 28 | if (fits_movnam_hdu(fptr, BINARY_TBL, "COMPRESSED_IMAGE", 0, &status) ) 29 | fits_report_error(stderr, status); /* print out error messages */ 30 | 31 | n_cols = 1; /* number of columns */ 32 | 33 | /* define input column structure members for the iterator function */ 34 | fits_iter_set_by_name(&cols[0], fptr, "COMPRESSED_DATA", 0, InputCol); 35 | 36 | rows_per_loop = 0; /* use default optimum number of rows */ 37 | offset = 0; /* process all the rows */ 38 | 39 | /* apply the rate function to each row of the table */ 40 | printf("Calling iterator function...%d\n", status); 41 | 42 | fits_iterate_data(n_cols, cols, offset, rows_per_loop, 43 | flux_rate, 0L, &status); 44 | 45 | fits_close_file(fptr, &status); /* all done */ 46 | 47 | if (status) 48 | fits_report_error(stderr, status); /* print out error messages */ 49 | 50 | return(status); 51 | } 52 | /*--------------------------------------------------------------------------*/ 53 | int flux_rate(long totalrows, long offset, long firstrow, long nrows, 54 | int ncols, iteratorCol *cols, void *user_strct ) 55 | 56 | /* 57 | Sample iterator function that calculates the output flux 'rate' column 58 | by dividing the input 'counts' by the 'time' column. 59 | It also applies a constant deadtime correction factor if the 'deadtime' 60 | keyword exists. Finally, this creates or updates the 'LIVETIME' 61 | keyword with the sum of all the individual integration times. 62 | */ 63 | { 64 | int ii, status = 0; 65 | long repeat; 66 | 67 | /* declare variables static to preserve their values between calls */ 68 | static unsigned char *counts; 69 | 70 | /*--------------------------------------------------------*/ 71 | /* Initialization procedures: execute on the first call */ 72 | /*--------------------------------------------------------*/ 73 | if (firstrow == 1) 74 | { 75 | 76 | printf("Datatype of column = %d\n",fits_iter_get_datatype(&cols[0])); 77 | 78 | /* assign the input pointers to the appropriate arrays and null ptrs*/ 79 | counts = (long *) fits_iter_get_array(&cols[0]); 80 | 81 | } 82 | 83 | /*--------------------------------------------*/ 84 | /* Main loop: process all the rows of data */ 85 | /*--------------------------------------------*/ 86 | 87 | /* NOTE: 1st element of array is the null pixel value! */ 88 | /* Loop from 1 to nrows, not 0 to nrows - 1. */ 89 | 90 | 91 | for (ii = 1; ii <= nrows; ii++) 92 | { 93 | repeat = fits_iter_get_repeat(&cols[0]); 94 | printf ("repeat = %d, %d\n",repeat, counts[1]); 95 | 96 | } 97 | 98 | 99 | return(0); /* return successful status */ 100 | } 101 | -------------------------------------------------------------------------------- /README_OLD.win: -------------------------------------------------------------------------------- 1 | =============================================================================== 2 | =============================================================================== 3 | = NOTE: This is the old version of the README.win32 file that was distributed 4 | = with CFITSIO up until version 3.35 in 2013. These instruction may still work 5 | = with more recent versions of CFITSIO, however, users are strongly urged to 6 | = use the CMake procedures that are now documented in the new README.win32 file. 7 | =============================================================================== 8 | =============================================================================== 9 | 10 | Instructions on using CFITSIO on Windows platforms for C programmers 11 | 12 | These instructions use a simple DOS-style command window. It is also possible 13 | to build and use CFITSIO within a GUI programming environment such as Visual 14 | Studio, but this is not supported here. 15 | 16 | =============================================================================== 17 | 1. Build the CFITSIO dll library 18 | 19 | This step will create the cfitsio.def, cfitsio.dll, and cfitsio.lib files. 20 | (If you downloaded the CFITSIO .zip file that contains the pre-built binary 21 | .dll file, then SKIP THIS STEP). 22 | 23 | A. With Microsoft Visual C++: 24 | 25 | 1. Open a DOS command window and execute the vcvars32.bat file that 26 | is distributed with older versions of Visual C++, or simply open 27 | the Visual C++ command window (e.g., when using Visual Studio 2010). 28 | 29 | 2. Unpack the CFITSIO source files (cfitxxxx.zip) into a new empty directory 30 | 31 | 3. In the DOS command window, cd to that directory and enter the 32 | following commands: 33 | 34 | nmake winDumpExts.mak 35 | nmake makefile.vcc 36 | (ignore the compiler warning messages) 37 | 38 | B: With Borland C++: 39 | 40 | First, follow the instructions provided by Borland to set up 41 | the proper environment variables and configure files for the compiler. 42 | 43 | Unpack the cfitsio.zip source file distribution into a suitable directory. 44 | 45 | In a DOS command window, cd to that directory and then execute the 46 | makepc.bat batch file on the command line to build the CFITSIO library, 47 | and the testprog and cookbook sample programs. 48 | 49 | =============================================================================== 50 | 2. Test the CFITSIO library with Visual C++ 51 | 52 | Compile and link the testprog.c test program. When using Visual Studio, 53 | the command is: 54 | 55 | cl /MD testprog.c cfitsio.lib 56 | 57 | 58 | This will create the testprog.exe executable program. Running this 59 | program should print out a long series of diagnostic messages 60 | that should end with "Status = 0; OK - no error" 61 | 62 | =============================================================================== 63 | 3. Compile and link an application program that calls CFITSIO routines 64 | with Visual C++ 65 | 66 | Include the fitsio.h and longnam.h header files in the C source code. 67 | 68 | Link the program with the cfitsio.lib file: 69 | 70 | cl /MD your_program.c cfitsio.lib 71 | 72 | 73 | NOTE: The /MD command line switch must be specified on the cl 74 | command line to force the compiler/linker to use the 75 | appropriete runtime library. If this switch is omitted, then 76 | the fits_report_error function in CFITSIO will likely crash. 77 | 78 | When building programs in the Visual Studio environment, one 79 | can force the equivalent of the /MD switch by selecting 80 | 'Settings...' under the 'Project' menu, then click on the C/C++ 81 | tab and select the 'Code Generator' category. Then under 'User 82 | Run-time Library' select 'Multithreaded DLL'. 83 | 84 | -------------------------------------------------------------------------------- /cfitsio.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXAggregateTarget section */ 10 | 462A28570A4EF04900AB8766 /* CFITSIO */ = { 11 | isa = PBXAggregateTarget; 12 | buildConfigurationList = 462A285C0A4EF05400AB8766 /* Build configuration list for PBXAggregateTarget "CFITSIO" */; 13 | buildPhases = ( 14 | 462A28580A4EF05100AB8766 /* ShellScript */, 15 | ); 16 | dependencies = ( 17 | ); 18 | name = CFITSIO; 19 | productName = "Build Universal"; 20 | }; 21 | /* End PBXAggregateTarget section */ 22 | 23 | /* Begin PBXGroup section */ 24 | 22831BBD1146D2B6004A1DD3 /* Products */ = { 25 | isa = PBXGroup; 26 | children = ( 27 | ); 28 | name = Products; 29 | sourceTree = ""; 30 | }; 31 | 462A28340A4EEE3200AB8766 = { 32 | isa = PBXGroup; 33 | children = ( 34 | 22831BBD1146D2B6004A1DD3 /* Products */, 35 | ); 36 | sourceTree = ""; 37 | }; 38 | /* End PBXGroup section */ 39 | 40 | /* Begin PBXProject section */ 41 | 462A28360A4EEE3200AB8766 /* Project object */ = { 42 | isa = PBXProject; 43 | attributes = { 44 | LastUpgradeCheck = 0630; 45 | }; 46 | buildConfigurationList = 462A28370A4EEE3200AB8766 /* Build configuration list for PBXProject "cfitsio" */; 47 | compatibilityVersion = "Xcode 3.2"; 48 | developmentRegion = English; 49 | hasScannedForEncodings = 0; 50 | knownRegions = ( 51 | en, 52 | ); 53 | mainGroup = 462A28340A4EEE3200AB8766; 54 | productRefGroup = 22831BBD1146D2B6004A1DD3 /* Products */; 55 | projectDirPath = ""; 56 | projectRoot = ""; 57 | targets = ( 58 | 462A28570A4EF04900AB8766 /* CFITSIO */, 59 | ); 60 | }; 61 | /* End PBXProject section */ 62 | 63 | /* Begin PBXShellScriptBuildPhase section */ 64 | 462A28580A4EF05100AB8766 /* ShellScript */ = { 65 | isa = PBXShellScriptBuildPhase; 66 | buildActionMask = 2147483647; 67 | files = ( 68 | ); 69 | inputPaths = ( 70 | ); 71 | outputPaths = ( 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | shellPath = /bin/sh; 75 | shellScript = "# shell script goes here\nmake distclean\n./configure\nmake shared\nmake testprog\nmake fpack\nmake funpack\nmake fitscopy\nexit 0"; 76 | }; 77 | /* End PBXShellScriptBuildPhase section */ 78 | 79 | /* Begin XCBuildConfiguration section */ 80 | 462A28390A4EEE3200AB8766 /* Release */ = { 81 | isa = XCBuildConfiguration; 82 | buildSettings = { 83 | COPY_PHASE_STRIP = YES; 84 | }; 85 | name = Release; 86 | }; 87 | 462A285E0A4EF05400AB8766 /* Release */ = { 88 | isa = XCBuildConfiguration; 89 | buildSettings = { 90 | COPY_PHASE_STRIP = YES; 91 | GCC_ENABLE_FIX_AND_CONTINUE = NO; 92 | GCC_GENERATE_DEBUGGING_SYMBOLS = NO; 93 | PRODUCT_NAME = CFITSIO; 94 | ZERO_LINK = NO; 95 | }; 96 | name = Release; 97 | }; 98 | /* End XCBuildConfiguration section */ 99 | 100 | /* Begin XCConfigurationList section */ 101 | 462A28370A4EEE3200AB8766 /* Build configuration list for PBXProject "cfitsio" */ = { 102 | isa = XCConfigurationList; 103 | buildConfigurations = ( 104 | 462A28390A4EEE3200AB8766 /* Release */, 105 | ); 106 | defaultConfigurationIsVisible = 0; 107 | defaultConfigurationName = Release; 108 | }; 109 | 462A285C0A4EF05400AB8766 /* Build configuration list for PBXAggregateTarget "CFITSIO" */ = { 110 | isa = XCConfigurationList; 111 | buildConfigurations = ( 112 | 462A285E0A4EF05400AB8766 /* Release */, 113 | ); 114 | defaultConfigurationIsVisible = 0; 115 | defaultConfigurationName = Release; 116 | }; 117 | /* End XCConfigurationList section */ 118 | }; 119 | rootObject = 462A28360A4EEE3200AB8766 /* Project object */; 120 | } 121 | -------------------------------------------------------------------------------- /sample.tpl: -------------------------------------------------------------------------------- 1 | # sample template - create 9 HDUs in one FITS file 2 | 3 | # syntax : 4 | 5 | # everything which starts with a hashmark is ignored 6 | # the same for empty lines 7 | 8 | # one can use \include filename to include other files 9 | # equal sign after keyword name is optional 10 | # \group must be terminated by \end 11 | # xtension is terminated by \group, xtension or EOF 12 | # First HDU of type image may be defined using "SIMPLE T" 13 | # group may contain other groups and xtensions 14 | # keywords may be indented, but indentation is limited to max 7chars. 15 | 16 | # template parser processes all keywords, makes substitutions 17 | # when necessary (hashmarks -> index), converts keyword names 18 | # to uppercase and writes keywords to file. 19 | # For string keywords, parser uses CFITSIO long string routines 20 | # to store string values longer than 72 characters. Parser can 21 | # read/process lines of any length, as long as there is enough memory. 22 | # For a very limited set of keywords (like NAXIS1 for binary tables) 23 | # template parser ignores values specified in template file 24 | # (one should not specify NAXIS1 for binary tables) and computes and 25 | # writes values respective to table structure. 26 | # number of rows in binary/ascii tables can be specified with NAXIS2 27 | 28 | # if the 1st HDU is not defined with "SIMPLE T" and is defined with 29 | # xtension image/asciitable/bintable then dummy primary HDU is 30 | # created by parser. 31 | 32 | simple t 33 | bitpix 16 34 | naxis 1 35 | naxis1 10 36 | COMMENT 37 | comment 38 | sdsdf / keyword without value (null type) 39 | if line begins with 8+ spaces everything is a comment 40 | 41 | xtension image 42 | bitpix 16 43 | naxis 1 44 | naxis1 10 45 | QWERW F / dfg dfgsd fg - boolean keyword 46 | FFFSDS45 3454345 /integer_or_real keyword 47 | SSSDFS34 32345.453 / real keyword 48 | adsfd34 (234234.34,2342342.3) / complex keyword - no space between () 49 | SDFDF# adfasdfasdfdfcvxccvzxcvcvcxv / autoindexed keyword, here idx=1 50 | SDFD# 'asf dfa dfad df dfad f ad fadfdaf dfdfa df loooooong keyyywoooord - reaaalllly verrrrrrrrrryy loooooooooong' / comment is max 80 chars 51 | history history record, spaces (all but 1st) after keyname are copied 52 | SDFDF# strg_value_without_spaces / autoindexed keyword, here idx=2 53 | comment comment record, spaces (all but 1st) after keyname are copied 54 | strg45 'sdfasdfadfffdfasdfasdfasdf &' 55 | continue 'sdfsdfsdfsd fsdf' / 3 spaces must follow CONTINUE keyword 56 | 57 | 58 | xtension image 59 | bitpix 16 60 | naxis 1 61 | naxis1 10 62 | 63 | \group 64 | 65 | xtension image 66 | bitpix 16 67 | naxis 1 68 | naxis1 10 69 | 70 | # create group inside group 71 | 72 | \group 73 | 74 | # one can specify additional columns in group HDU. The first column 75 | # specified will have index 7 however, since the first 6 columns are occupied 76 | # by grouping table itself. 77 | # Please note, that it is not allowed to specify EXTNAME keyword as an 78 | # additional keyword for group HDU, since parser automatically writes 79 | # EXTNAME = GROUPING keyword. 80 | 81 | TFORM# 13A 82 | TTYPE# ADDIT_COL_IN_GRP_HDU 83 | TFORM# 1E 84 | TTYPE# REAL_COLUMN 85 | COMMENT sure, there is always place for comments 86 | 87 | # the following specifies empty ascii table (0 cols / 0 rows) 88 | 89 | xtension asciitable 90 | 91 | \end 92 | 93 | \end 94 | 95 | # one do not have to specify all NAXISn keywords. If not specified 96 | # NAXISn equals zero. 97 | 98 | xtension image 99 | bitpix 16 100 | naxis 1 101 | # naxis1 10 102 | 103 | # the following tells how to set number of rows in binary table 104 | # note also that the last line in template file does not have to 105 | # have LineFeed character as the last one. 106 | 107 | xtension bintable 108 | naxis2 10 109 | EXTNAME asdjfhsdkf 110 | TTYPE# MEMBER_XTENSION 111 | TFORM# 8A 112 | TTYPE# MEMBER_2 113 | TFORM# 8U 114 | TTYPE# MEMBER_3 115 | TFORM# 8V 116 | TTYPE# MEMBER_NAME 117 | TFORM# 32A 118 | TDIM# '(8,4)' 119 | TTYPE# MEMBER_VERSION 120 | TFORM# 1J 121 | TNULL# 0 -------------------------------------------------------------------------------- /iter_b.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "fitsio.h" 5 | 6 | /* 7 | This program illustrates how to use the CFITSIO iterator function. 8 | It simply prints out the values in a character string and a logical 9 | type column in a table, and toggles the value in the logical column 10 | so that T -> F and F -> T. 11 | */ 12 | main() 13 | { 14 | extern str_iter(); /* external work function is passed to the iterator */ 15 | fitsfile *fptr; 16 | iteratorCol cols[2]; 17 | int n_cols; 18 | long rows_per_loop, offset; 19 | int status = 0; 20 | char filename[] = "iter_b.fit"; /* name of rate FITS file */ 21 | 22 | /* open the file and move to the correct extension */ 23 | fits_open_file(&fptr, filename, READWRITE, &status); 24 | fits_movnam_hdu(fptr, BINARY_TBL, "iter_test", 0, &status); 25 | 26 | /* define input column structure members for the iterator function */ 27 | n_cols = 2; /* number of columns */ 28 | 29 | /* define input column structure members for the iterator function */ 30 | fits_iter_set_by_name(&cols[0], fptr, "Avalue", TSTRING, InputOutputCol); 31 | fits_iter_set_by_name(&cols[1], fptr, "Lvalue", TLOGICAL, InputOutputCol); 32 | 33 | rows_per_loop = 0; /* use default optimum number of rows */ 34 | offset = 0; /* process all the rows */ 35 | 36 | /* apply the function to each row of the table */ 37 | printf("Calling iterator function...%d\n", status); 38 | 39 | fits_iterate_data(n_cols, cols, offset, rows_per_loop, 40 | str_iter, 0L, &status); 41 | 42 | fits_close_file(fptr, &status); /* all done */ 43 | 44 | if (status) 45 | fits_report_error(stderr, status); /* print out error messages */ 46 | 47 | return(status); 48 | } 49 | /*--------------------------------------------------------------------------*/ 50 | int str_iter(long totalrows, long offset, long firstrow, long nrows, 51 | int ncols, iteratorCol *cols, void *user_strct ) 52 | 53 | /* 54 | Sample iterator function. 55 | */ 56 | { 57 | int ii; 58 | 59 | /* declare variables static to preserve their values between calls */ 60 | static char **stringvals; 61 | static char *logicalvals; 62 | 63 | /*--------------------------------------------------------*/ 64 | /* Initialization procedures: execute on the first call */ 65 | /*--------------------------------------------------------*/ 66 | if (firstrow == 1) 67 | { 68 | if (ncols != 2) 69 | return(-1); /* number of columns incorrect */ 70 | 71 | if (fits_iter_get_datatype(&cols[0]) != TSTRING || 72 | fits_iter_get_datatype(&cols[1]) != TLOGICAL ) 73 | return(-2); /* bad data type */ 74 | 75 | /* assign the input pointers to the appropriate arrays */ 76 | stringvals = (char **) fits_iter_get_array(&cols[0]); 77 | logicalvals = (char *) fits_iter_get_array(&cols[1]); 78 | 79 | printf("Total rows, No. rows = %d %d\n",totalrows, nrows); 80 | } 81 | 82 | /*------------------------------------------*/ 83 | /* Main loop: process all the rows of data */ 84 | /*------------------------------------------*/ 85 | 86 | /* NOTE: 1st element of array is the null pixel value! */ 87 | /* Loop from 1 to nrows, not 0 to nrows - 1. */ 88 | 89 | for (ii = 1; ii <= nrows; ii++) 90 | { 91 | printf("%s %d\n", stringvals[ii], logicalvals[ii]); 92 | if (logicalvals[ii]) 93 | { 94 | logicalvals[ii] = FALSE; 95 | strcpy(stringvals[ii], "changed to false"); 96 | } 97 | else 98 | { 99 | logicalvals[ii] = TRUE; 100 | strcpy(stringvals[ii], "changed to true"); 101 | } 102 | } 103 | 104 | /*-------------------------------------------------------*/ 105 | /* Clean up procedures: after processing all the rows */ 106 | /*-------------------------------------------------------*/ 107 | 108 | if (firstrow + nrows - 1 == totalrows) 109 | { 110 | /* no action required in this case */ 111 | } 112 | 113 | return(0); 114 | } 115 | -------------------------------------------------------------------------------- /vmsieee.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | unsigned long CVT$CONVERT_FLOAT(); 5 | 6 | /* IEEVPAKR -- Pack a native floating point vector into an IEEE one. 7 | */ 8 | void ieevpr (unsigned int *native, unsigned int *ieee, int *nelem) 9 | { 10 | unsigned long status; 11 | unsigned long options; 12 | unsigned int *unanval; 13 | int nanval = -1; 14 | int i,n; 15 | 16 | unanval = (unsigned int *) &nanval; 17 | options = CVT$M_BIG_ENDIAN; 18 | 19 | n = *nelem; 20 | status = CVT$_NORMAL; 21 | 22 | for (i = 0; i < n ; i++) { 23 | 24 | status = CVT$CONVERT_FLOAT (&native[i], CVT$K_VAX_F, 25 | &ieee[i], CVT$K_IEEE_S, 26 | options); 27 | if (status != CVT$_NORMAL) { 28 | ieee[i] = *unanval; 29 | } 30 | } 31 | 32 | } 33 | /* IEEVPAKD -- Pack a native double floating point vector into an IEEE one. 34 | */ 35 | void ieevpd (unsigned long *native, unsigned long *ieee, int *nelem) 36 | { 37 | unsigned long status; 38 | unsigned long options; 39 | unsigned long *unanval; 40 | long nanval = -1; 41 | int i,n; 42 | 43 | unanval = (unsigned long *) &nanval; 44 | options = CVT$M_BIG_ENDIAN; 45 | 46 | n = *nelem * 2; 47 | status = CVT$_NORMAL; 48 | 49 | for (i = 0; i < n ; i=i+2) { 50 | 51 | status = CVT$CONVERT_FLOAT (&native[i], CVT$K_VAX_D, 52 | &ieee[i], CVT$K_IEEE_T, 53 | options); 54 | if (status != CVT$_NORMAL) { 55 | ieee[i] = *unanval; 56 | ieee[i+1] = *unanval; 57 | } 58 | } 59 | 60 | } 61 | /* IEEVUPKR -- Unpack an ieee vector into native single floating point vector. 62 | */ 63 | void ieevur (unsigned int *ieee, unsigned int *native, int *nelem) 64 | { 65 | unsigned long status; 66 | unsigned long options; 67 | unsigned int *unanval; 68 | int nanval = -1; 69 | int j,n; 70 | 71 | unanval = (unsigned int *) &nanval; 72 | options = CVT$M_ERR_UNDERFLOW+CVT$M_BIG_ENDIAN; 73 | 74 | n = *nelem; 75 | 76 | status = CVT$_NORMAL; 77 | 78 | for (j = 0; j < n ; j++) { 79 | status = CVT$CONVERT_FLOAT (&ieee[j], CVT$K_IEEE_S, 80 | &native[j], CVT$K_VAX_F, 81 | options); 82 | if (status != CVT$_NORMAL) 83 | switch(status) { 84 | case CVT$_INVVAL: 85 | case CVT$_NEGINF: 86 | case CVT$_OVERFLOW: 87 | case CVT$_POSINF: 88 | native[j] = *unanval; 89 | break; 90 | default: 91 | native[j] = 0; 92 | } 93 | } 94 | } 95 | /* IEEVUPKD -- Unpack an ieee vector into native double floating point vector. 96 | */ 97 | void ieevud (unsigned long *ieee, unsigned long *native, int *nelem) 98 | { 99 | unsigned long status; 100 | unsigned long options; 101 | unsigned long *unanval; 102 | long nanval = -1; 103 | int j,n; 104 | 105 | unanval = (unsigned long *) &nanval; 106 | options = CVT$M_BIG_ENDIAN + CVT$M_ERR_UNDERFLOW; 107 | 108 | n = *nelem * 2; 109 | 110 | status = CVT$_NORMAL; 111 | 112 | for (j = 0; j < n ; j=j+2) { 113 | status = CVT$CONVERT_FLOAT (&ieee[j], CVT$K_IEEE_T, 114 | &native[j], CVT$K_VAX_D, 115 | options); 116 | if (status != CVT$_NORMAL) 117 | switch(status) { 118 | case CVT$_INVVAL: 119 | case CVT$_NEGINF: 120 | case CVT$_OVERFLOW: 121 | case CVT$_POSINF: 122 | native[j] = *unanval; 123 | native[j+1] = *unanval; 124 | break; 125 | default: 126 | native[j] = 0; 127 | native[j+1] = 0; 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | CFITSIO Interface Library 2 | 3 | CFITSIO is a library of ANSI C routines for reading and writing FITS 4 | format data files. A set of Fortran-callable wrapper routines are also 5 | included for the convenience of Fortran programmers. This README file 6 | gives a brief summary of how to build and test CFITSIO, but the CFITSIO 7 | User's Guide, found in the files cfitsio.doc (plain text), cfitsio.tex 8 | (LaTeX source file), cfitsio.ps, or cfitsio.pdf should be 9 | referenced for the latest and most complete information. 10 | 11 | BUILDING CFITSIO 12 | ---------------- 13 | 14 | The CFITSIO code is contained in about 40 *.c source files and several *.h 15 | header files. CFITSIO should compile and run on most Unix platforms without 16 | modification, except that Cray supercomputers computers are currently not 17 | supported. The CFITSIO library is built on Unix systems by typing: 18 | 19 | > ./configure [--prefix=/target/installation/path] 20 | > make (or 'make shared') 21 | > make install (this step is optional) 22 | 23 | at the operating system prompt. The configure command customizes the 24 | Makefile for the particular system, then the `make' command compiles the 25 | source files and builds the library. Type `./configure' and not simply 26 | `configure' to ensure that the configure script in the current directory 27 | is run and not some other system-wide configure script. The optional 28 | 'prefix' argument to configure gives the path to the directory where 29 | the CFITSIO library and include files should be installed via the later 30 | 'make install' command. For example, 31 | 32 | > ./configure --prefix=/usr1/local 33 | 34 | will cause the 'make install' command to copy the CFITSIO libcfitsio file 35 | to /usr1/local/lib and the necessary include files to /usr1/local/include 36 | (assuming of course that the process has permission to write to these 37 | directories). 38 | 39 | All the available configure options can be seen by entering the command 40 | 41 | > ./configure --help 42 | 43 | On VAX/VMS and ALPHA/VMS systems the make.com command file may be used 44 | to build the cfitsio.olb object library using the default G-floating 45 | point option for double variables. The make\_dfloat.com and make\_ieee.com 46 | files may be used instead to build the library with the other floating 47 | point options. 48 | 49 | A precompiled DLL version of CFITSIO is available for IBM-PC users of 50 | the Borland or Microsoft Visual C++ compilers in the files 51 | cfitsiodll_xxxx_borland.zip and cfitsiodll_xxxx_vcc.zip, where 'xxxx' 52 | represents the current release number. These zip archives also 53 | contains other files and instructions on how to use the CFITSIO DLL 54 | library. The CFITSIO library may also be built from the source code 55 | using the makefile.bc or makefile.vcc files. Finally, the makepc.bat 56 | file gives an example of building CFITSIO with the Borland C++ v4.5 57 | compiler using simpler DOS commands. 58 | 59 | Instructions for building CFITSIO on Mac OS can be found in 60 | the README.MacOS file. 61 | 62 | TESTING CFITSIO 63 | --------------- 64 | 65 | The CFITSIO library should be tested by building and running 66 | the testprog.c program that is included with the release. 67 | On Unix systems, type: 68 | - 69 | % make testprog 70 | % testprog > testprog.lis 71 | % diff testprog.lis testprog.out 72 | % cmp testprog.fit testprog.std 73 | - 74 | On VMS systems, 75 | (assuming cc is the name of the C compiler command), type: 76 | - 77 | $ cc testprog.c 78 | $ link testprog, cfitsio/lib 79 | $ run testprog 80 | - 81 | The testprog program should produce a FITS file called `testprog.fit' 82 | that is identical to the testprog.std FITS file included in this 83 | release. The diagnostic messages (which were piped to the file 84 | testprog.lis in the Unix example) should be identical to the listing 85 | contained in the file testprog.out. The 'diff' and 'cmp' commands 86 | shown above should not report any differences in the files. 87 | 88 | USING CFITSIO 89 | ------------- 90 | 91 | The CFITSIO User's Guide, contained in the files cfitsio.doc (plain 92 | text file) and cfitsio.ps (postscript file), provides detailed 93 | documentation about how to build and use the CFITSIO library. 94 | It contains a description of every user-callable routine in the 95 | CFITSIO interface. 96 | 97 | The cookbook.c file provides some sample routines for performing common 98 | operations on various types of FITS files. Programmers are urged to 99 | examine these routines for recommended programming practices when using 100 | CFITSIO. Users are free to copy or modify these routines for their own 101 | purposes. 102 | 103 | Any problem reports or suggestions for 104 | improvements are welcome and should be sent to the HEASARC 105 | help desk. 106 | 107 | ------------------------------------------------------------------------- 108 | William D. Pence 109 | HEASARC, NASA/GSFC 110 | -------------------------------------------------------------------------------- /eval_defs.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #if defined(__sgi) || defined(__hpux) 6 | #include 7 | #endif 8 | #ifdef sparc 9 | #include 10 | #endif 11 | #include "fitsio2.h" 12 | 13 | #define MAXDIMS 5 14 | #define MAXSUBS 10 15 | #define MAXVARNAME 80 16 | #define CONST_OP -1000 17 | #define pERROR -1 18 | #define MAX_STRLEN 256 19 | #define MAX_STRLEN_S "255" 20 | 21 | #ifndef FFBISON 22 | #include "eval_tab.h" 23 | #endif 24 | 25 | 26 | typedef struct { 27 | char name[MAXVARNAME+1]; 28 | int type; 29 | long nelem; 30 | int naxis; 31 | long naxes[MAXDIMS]; 32 | char *undef; 33 | void *data; 34 | } DataInfo; 35 | 36 | typedef struct { 37 | long nelem; 38 | int naxis; 39 | long naxes[MAXDIMS]; 40 | char *undef; 41 | union { 42 | double dbl; 43 | long lng; 44 | char log; 45 | char str[MAX_STRLEN]; 46 | double *dblptr; 47 | long *lngptr; 48 | char *logptr; 49 | char **strptr; 50 | void *ptr; 51 | } data; 52 | } lval; 53 | 54 | typedef struct Node { 55 | int operation; 56 | void (*DoOp)(struct Node *this); 57 | int nSubNodes; 58 | int SubNodes[MAXSUBS]; 59 | int type; 60 | lval value; 61 | } Node; 62 | 63 | typedef struct { 64 | fitsfile *def_fptr; 65 | int (*getData)( char *dataName, void *dataValue ); 66 | int (*loadData)( int varNum, long fRow, long nRows, 67 | void *data, char *undef ); 68 | 69 | int compressed; 70 | int timeCol; 71 | int parCol; 72 | int valCol; 73 | 74 | char *expr; 75 | int index; 76 | int is_eobuf; 77 | 78 | Node *Nodes; 79 | int nNodes; 80 | int nNodesAlloc; 81 | int resultNode; 82 | 83 | long firstRow; 84 | long nRows; 85 | 86 | int nCols; 87 | iteratorCol *colData; 88 | DataInfo *varData; 89 | PixelFilter *pixFilter; 90 | 91 | long firstDataRow; 92 | long nDataRows; 93 | long totalRows; 94 | 95 | int datatype; 96 | int hdutype; 97 | 98 | int status; 99 | } ParseData; 100 | 101 | typedef enum { 102 | rnd_fct = 1001, 103 | sum_fct, 104 | nelem_fct, 105 | sin_fct, 106 | cos_fct, 107 | tan_fct, 108 | asin_fct, 109 | acos_fct, 110 | atan_fct, 111 | sinh_fct, 112 | cosh_fct, 113 | tanh_fct, 114 | exp_fct, 115 | log_fct, 116 | log10_fct, 117 | sqrt_fct, 118 | abs_fct, 119 | atan2_fct, 120 | ceil_fct, 121 | floor_fct, 122 | round_fct, 123 | min1_fct, 124 | min2_fct, 125 | max1_fct, 126 | max2_fct, 127 | near_fct, 128 | circle_fct, 129 | box_fct, 130 | elps_fct, 131 | isnull_fct, 132 | defnull_fct, 133 | gtifilt_fct, 134 | regfilt_fct, 135 | ifthenelse_fct, 136 | row_fct, 137 | null_fct, 138 | median_fct, 139 | average_fct, 140 | stddev_fct, 141 | nonnull_fct, 142 | angsep_fct, 143 | gasrnd_fct, 144 | poirnd_fct, 145 | strmid_fct, 146 | strpos_fct, 147 | setnull_fct, 148 | gtiover_fct 149 | } funcOp; 150 | 151 | extern ParseData gParse; 152 | 153 | #ifdef __cplusplus 154 | extern "C" { 155 | #endif 156 | 157 | int ffparse(void); 158 | int fflex(void); 159 | void ffrestart(FILE*); 160 | 161 | void Evaluate_Parser( long firstRow, long nRows ); 162 | 163 | #ifdef __cplusplus 164 | } 165 | #endif 166 | -------------------------------------------------------------------------------- /winDumpExts.mak: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Generated NMAKE File, Based on winDumpExts.dsp 2 | !IF "$(CFG)" == "" 3 | CFG=Win32 Debug 4 | !MESSAGE No configuration specified. Defaulting to Win32 Debug. 5 | !ENDIF 6 | 7 | !IF "$(CFG)" != "Win32 Release" && "$(CFG)" != "Win32 Debug" 8 | !MESSAGE Invalid configuration "$(CFG)" specified. 9 | !MESSAGE You can specify a configuration when running NMAKE 10 | !MESSAGE by defining the macro CFG on the command line. For example: 11 | !MESSAGE 12 | !MESSAGE NMAKE /f "winDumpExts.mak" CFG="Win32 Debug" 13 | !MESSAGE 14 | !MESSAGE Possible choices for configuration are: 15 | !MESSAGE 16 | !MESSAGE "Win32 Release" (based on "Win32 (x86) Console Application") 17 | !MESSAGE "Win32 Debug" (based on "Win32 (x86) Console Application") 18 | !MESSAGE 19 | !ERROR An invalid configuration is specified. 20 | !ENDIF 21 | 22 | !IF "$(OS)" == "Windows_NT" 23 | NULL= 24 | !ELSE 25 | NULL=nul 26 | !ENDIF 27 | 28 | !IF "$(CFG)" == "Win32 Release" 29 | 30 | OUTDIR=.\Release 31 | INTDIR=.\Release 32 | # Begin Custom Macros 33 | OutDir=.\Release 34 | # End Custom Macros 35 | 36 | ALL : "$(OUTDIR)\winDumpExts.exe" 37 | 38 | 39 | CLEAN : 40 | -@erase "$(INTDIR)\vc60.idb" 41 | -@erase "$(INTDIR)\winDumpExts.obj" 42 | -@erase "$(OUTDIR)\winDumpExts.exe" 43 | 44 | "$(OUTDIR)" : 45 | if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" 46 | 47 | "$(INTDIR)" : 48 | if not exist "$(INTDIR)/$(NULL)" mkdir "$(INTDIR)" 49 | 50 | CPP=cl.exe 51 | CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\winDumpExts.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c 52 | 53 | .c{$(INTDIR)}.obj:: 54 | $(CPP) @<< 55 | $(CPP_PROJ) $< 56 | << 57 | 58 | .cpp{$(INTDIR)}.obj:: 59 | $(CPP) @<< 60 | $(CPP_PROJ) $< 61 | << 62 | 63 | .cxx{$(INTDIR)}.obj:: 64 | $(CPP) @<< 65 | $(CPP_PROJ) $< 66 | << 67 | 68 | .c{$(INTDIR)}.sbr:: 69 | $(CPP) @<< 70 | $(CPP_PROJ) $< 71 | << 72 | 73 | .cpp{$(INTDIR)}.sbr:: 74 | $(CPP) @<< 75 | $(CPP_PROJ) $< 76 | << 77 | 78 | .cxx{$(INTDIR)}.sbr:: 79 | $(CPP) @<< 80 | $(CPP_PROJ) $< 81 | << 82 | 83 | RSC=rc.exe 84 | BSC32=bscmake.exe 85 | BSC32_FLAGS=/nologo /o"$(OUTDIR)\winDumpExts.bsc" 86 | BSC32_SBRS= \ 87 | 88 | LINK32=link.exe 89 | LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\winDumpExts.pdb" /machine:I386 /out:"$(OUTDIR)\winDumpExts.exe" 90 | LINK32_OBJS= \ 91 | "$(INTDIR)\winDumpExts.obj" 92 | 93 | "$(OUTDIR)\winDumpExts.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) 94 | $(LINK32) @<< 95 | $(LINK32_FLAGS) $(LINK32_OBJS) 96 | << 97 | 98 | !ELSEIF "$(CFG)" == "Win32 Debug" 99 | 100 | OUTDIR=. 101 | INTDIR=.\Debug 102 | # Begin Custom Macros 103 | OutDir=. 104 | # End Custom Macros 105 | 106 | ALL : "$(OUTDIR)\winDumpExts.exe" 107 | 108 | 109 | CLEAN : 110 | -@erase "$(INTDIR)\vc60.idb" 111 | -@erase "$(INTDIR)\vc60.pdb" 112 | -@erase "$(INTDIR)\winDumpExts.obj" 113 | -@erase "$(OUTDIR)\winDumpExts.exe" 114 | -@erase "$(OUTDIR)\winDumpExts.ilk" 115 | -@erase "$(OUTDIR)\winDumpExts.pdb" 116 | 117 | "$(OUTDIR)" : 118 | if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" 119 | 120 | "$(INTDIR)" : 121 | if not exist "$(INTDIR)/$(NULL)" mkdir "$(INTDIR)" 122 | 123 | CPP=cl.exe 124 | CPP_PROJ=/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\winDumpExts.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c 125 | 126 | .c{$(INTDIR)}.obj:: 127 | $(CPP) @<< 128 | $(CPP_PROJ) $< 129 | << 130 | 131 | .cpp{$(INTDIR)}.obj:: 132 | $(CPP) @<< 133 | $(CPP_PROJ) $< 134 | << 135 | 136 | .cxx{$(INTDIR)}.obj:: 137 | $(CPP) @<< 138 | $(CPP_PROJ) $< 139 | << 140 | 141 | .c{$(INTDIR)}.sbr:: 142 | $(CPP) @<< 143 | $(CPP_PROJ) $< 144 | << 145 | 146 | .cpp{$(INTDIR)}.sbr:: 147 | $(CPP) @<< 148 | $(CPP_PROJ) $< 149 | << 150 | 151 | .cxx{$(INTDIR)}.sbr:: 152 | $(CPP) @<< 153 | $(CPP_PROJ) $< 154 | << 155 | 156 | RSC=rc.exe 157 | BSC32=bscmake.exe 158 | BSC32_FLAGS=/nologo /o"$(OUTDIR)\winDumpExts.bsc" 159 | BSC32_SBRS= \ 160 | 161 | LINK32=link.exe 162 | LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\winDumpExts.pdb" /debug /machine:I386 /out:"$(OUTDIR)\winDumpExts.exe" /pdbtype:sept 163 | LINK32_OBJS= \ 164 | "$(INTDIR)\winDumpExts.obj" 165 | 166 | "$(OUTDIR)\winDumpExts.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) 167 | $(LINK32) @<< 168 | $(LINK32_FLAGS) $(LINK32_OBJS) 169 | << 170 | 171 | !ENDIF 172 | 173 | 174 | !IF "$(NO_EXTERNAL_DEPS)" != "1" 175 | !IF EXISTS("winDumpExts.dep") 176 | !INCLUDE "winDumpExts.dep" 177 | !ELSE 178 | !MESSAGE Warning: cannot find "winDumpExts.dep" 179 | !ENDIF 180 | !ENDIF 181 | 182 | 183 | !IF "$(CFG)" == "Win32 Release" || "$(CFG)" == "Win32 Debug" 184 | SOURCE=.\winDumpExts.c 185 | 186 | "$(INTDIR)\winDumpExts.obj" : $(SOURCE) "$(INTDIR)" 187 | 188 | 189 | 190 | !ENDIF 191 | 192 | -------------------------------------------------------------------------------- /funpack.c: -------------------------------------------------------------------------------- 1 | /* FUNPACK 2 | * R. Seaman, NOAO 3 | * uses fits_img_compress by W. Pence, HEASARC 4 | */ 5 | 6 | #include "fitsio.h" 7 | #include "fpack.h" 8 | 9 | int main (int argc, char *argv[]) 10 | { 11 | fpstate fpvar; 12 | 13 | if (argc <= 1) { fu_usage (); fu_hint (); exit (-1); } 14 | 15 | fp_init (&fpvar); 16 | fu_get_param (argc, argv, &fpvar); 17 | 18 | if (fpvar.listonly) { 19 | fp_list (argc, argv, fpvar); 20 | 21 | } else { 22 | fp_preflight (argc, argv, FUNPACK, &fpvar); 23 | fp_loop (argc, argv, FUNPACK, fpvar); 24 | } 25 | 26 | exit (0); 27 | } 28 | 29 | int fu_get_param (int argc, char *argv[], fpstate *fpptr) 30 | { 31 | int iarg; 32 | char tile[SZ_STR]; 33 | 34 | if (fpptr->initialized != FP_INIT_MAGIC) { 35 | fp_msg ("Error: internal initialization error\n"); exit (-1); 36 | } 37 | 38 | tile[0] = 0; 39 | 40 | /* by default, .fz suffix characters to be deleted from compressed file */ 41 | fpptr->delete_suffix = 1; 42 | 43 | /* flags must come first and be separately specified 44 | */ 45 | for (iarg = 1; iarg < argc; iarg++) { 46 | if (argv[iarg][0] == '-' && strlen (argv[iarg]) == 2) { 47 | 48 | if (argv[iarg][1] == 'F') { 49 | fpptr->clobber++; 50 | fpptr->delete_suffix = 0; /* no suffix in this case */ 51 | 52 | } else if (argv[iarg][1] == 'D') { 53 | fpptr->delete_input++; 54 | 55 | } else if (argv[iarg][1] == 'P') { 56 | if (++iarg >= argc) { 57 | fu_usage (); fu_hint (); exit (-1); 58 | } else { 59 | strncpy (fpptr->prefix, argv[iarg], SZ_STR-1); 60 | fpptr->prefix[SZ_STR-1] = 0; 61 | } 62 | 63 | } else if (argv[iarg][1] == 'E') { 64 | if (++iarg >= argc) { 65 | fu_usage (); fu_hint (); exit (-1); 66 | } else { 67 | strncpy (fpptr->extname, argv[iarg], SZ_STR-1); 68 | fpptr->extname[SZ_STR-1]=0; 69 | } 70 | 71 | } else if (argv[iarg][1] == 'S') { 72 | fpptr->to_stdout++; 73 | 74 | } else if (argv[iarg][1] == 'L') { 75 | fpptr->listonly++; 76 | 77 | } else if (argv[iarg][1] == 'C') { 78 | fpptr->do_checksums = 0; 79 | 80 | } else if (argv[iarg][1] == 'H') { 81 | fu_help (); exit (0); 82 | 83 | } else if (argv[iarg][1] == 'V') { 84 | fp_version (); exit (0); 85 | 86 | } else if (argv[iarg][1] == 'Z') { 87 | fpptr->do_gzip_file++; 88 | 89 | } else if (argv[iarg][1] == 'v') { 90 | fpptr->verbose = 1; 91 | 92 | } else if (argv[iarg][1] == 'O') { 93 | if (++iarg >= argc) { 94 | fu_usage (); fu_hint (); exit (-1); 95 | } else { 96 | strncpy (fpptr->outfile, argv[iarg], SZ_STR-1); 97 | fpptr->outfile[SZ_STR-1]=0; 98 | } 99 | 100 | } else { 101 | fp_msg ("Error: unknown command line flag `"); 102 | fp_msg (argv[iarg]); fp_msg ("'\n"); 103 | fu_usage (); fu_hint (); exit (-1); 104 | } 105 | 106 | } else 107 | break; 108 | } 109 | 110 | if (fpptr->extname[0] && (fpptr->clobber || fpptr->delete_input)) { 111 | fp_msg ("Error: -E option may not be used with -F or -D\n"); 112 | fu_usage (); exit (-1); 113 | } 114 | 115 | if (fpptr->to_stdout && (fpptr->outfile[0] || fpptr->prefix[0]) ) { 116 | 117 | fp_msg ("Error: -S option may not be used with -P or -O\n"); 118 | fu_usage (); exit (-1); 119 | } 120 | 121 | if (fpptr->outfile[0] && fpptr->prefix[0] ) { 122 | fp_msg ("Error: -P and -O options may not be used together\n"); 123 | fu_usage (); exit (-1); 124 | } 125 | 126 | if (iarg >= argc) { 127 | fp_msg ("Error: no FITS files to uncompress\n"); 128 | fu_usage (); exit (-1); 129 | } else 130 | fpptr->firstfile = iarg; 131 | 132 | return(0); 133 | } 134 | 135 | int fu_usage (void) 136 | { 137 | fp_msg ("usage: funpack [-E ] [-P
] [-O ] [-Z] -v \n");
138 |         fp_msg ("more:   [-F] [-D] [-S] [-L] [-C] [-H] [-V] \n");
139 | 	return(0);
140 | }
141 | 
142 | int fu_hint (void)
143 | {
144 | 	fp_msg ("      `funpack -H' for help\n");
145 | 	return(0);
146 | }
147 | 
148 | int fu_help (void)
149 | {
150 | fp_msg ("funpack, decompress fpacked files.  Version ");
151 | fp_version ();
152 | fu_usage ();
153 | fp_msg ("\n");
154 | 
155 | fp_msg ("Flags must be separate and appear before filenames:\n");
156 | fp_msg (" -E  Unpack only the list of HDU names or numbers in the file.\n");
157 | fp_msg (" -P 
    Prepend 
 to create new output filenames.\n");
158 | fp_msg (" -O    Specify full output file name.\n");
159 | fp_msg (" -Z          Recompress the output file with host GZIP program.\n");
160 | fp_msg (" -F          Overwrite input file by output file with same name.\n");
161 | fp_msg (" -D          Delete input file after writing output.\n");
162 | fp_msg (" -S          Output uncompressed file to STDOUT file stream.\n");
163 | fp_msg (" -L          List contents, files unchanged.\n");
164 | 
165 | fp_msg (" -C          Don't update FITS checksum keywords.\n");
166 | 
167 | fp_msg (" -v          Verbose mode; list each file as it is processed.\n");
168 | fp_msg (" -H          Show this message.\n");
169 | fp_msg (" -V          Show version number.\n");
170 | 
171 | fp_msg (" \n       FITS files to unpack; enter '-' (a hyphen) to read from stdin.\n");
172 | fp_msg (" Refer to the fpack User's Guide for more extensive help.\n");
173 | 	return(0);
174 | }
175 | 


--------------------------------------------------------------------------------
/eval_tab.h:
--------------------------------------------------------------------------------
  1 | /* A Bison parser, made by GNU Bison 3.7.4.  */
  2 | 
  3 | /* Bison interface for Yacc-like parsers in C
  4 | 
  5 |    Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
  6 |    Inc.
  7 | 
  8 |    This program is free software: you can redistribute it and/or modify
  9 |    it under the terms of the GNU General Public License as published by
 10 |    the Free Software Foundation, either version 3 of the License, or
 11 |    (at your option) any later version.
 12 | 
 13 |    This program is distributed in the hope that it will be useful,
 14 |    but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 |    GNU General Public License for more details.
 17 | 
 18 |    You should have received a copy of the GNU General Public License
 19 |    along with this program.  If not, see .  */
 20 | 
 21 | /* As a special exception, you may create a larger work that contains
 22 |    part or all of the Bison parser skeleton and distribute that work
 23 |    under terms of your choice, so long as that work isn't itself a
 24 |    parser generator using the skeleton or a modified version thereof
 25 |    as a parser skeleton.  Alternatively, if you modify or redistribute
 26 |    the parser skeleton itself, you may (at your option) remove this
 27 |    special exception, which will cause the skeleton and the resulting
 28 |    Bison output files to be licensed under the GNU General Public
 29 |    License without this special exception.
 30 | 
 31 |    This special exception was added by the Free Software Foundation in
 32 |    version 2.2 of Bison.  */
 33 | 
 34 | /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
 35 |    especially those whose name start with FF_ or ff_.  They are
 36 |    private implementation details that can be changed or removed.  */
 37 | 
 38 | #ifndef FF_FF_Y_TAB_H_INCLUDED
 39 | # define FF_FF_Y_TAB_H_INCLUDED
 40 | /* Debug traces.  */
 41 | #ifndef FFDEBUG
 42 | # define FFDEBUG 0
 43 | #endif
 44 | #if FFDEBUG
 45 | extern int ffdebug;
 46 | #endif
 47 | 
 48 | /* Token kinds.  */
 49 | #ifndef FFTOKENTYPE
 50 | # define FFTOKENTYPE
 51 |   enum fftokentype
 52 |   {
 53 |     FFEMPTY = -2,
 54 |     FFEOF = 0,                     /* "end of file"  */
 55 |     FFerror = 256,                 /* error  */
 56 |     FFUNDEF = 257,                 /* "invalid token"  */
 57 |     BOOLEAN = 258,                 /* BOOLEAN  */
 58 |     LONG = 259,                    /* LONG  */
 59 |     DOUBLE = 260,                  /* DOUBLE  */
 60 |     STRING = 261,                  /* STRING  */
 61 |     BITSTR = 262,                  /* BITSTR  */
 62 |     FUNCTION = 263,                /* FUNCTION  */
 63 |     BFUNCTION = 264,               /* BFUNCTION  */
 64 |     IFUNCTION = 265,               /* IFUNCTION  */
 65 |     GTIFILTER = 266,               /* GTIFILTER  */
 66 |     GTIOVERLAP = 267,              /* GTIOVERLAP  */
 67 |     REGFILTER = 268,               /* REGFILTER  */
 68 |     COLUMN = 269,                  /* COLUMN  */
 69 |     BCOLUMN = 270,                 /* BCOLUMN  */
 70 |     SCOLUMN = 271,                 /* SCOLUMN  */
 71 |     BITCOL = 272,                  /* BITCOL  */
 72 |     ROWREF = 273,                  /* ROWREF  */
 73 |     NULLREF = 274,                 /* NULLREF  */
 74 |     SNULLREF = 275,                /* SNULLREF  */
 75 |     OR = 276,                      /* OR  */
 76 |     AND = 277,                     /* AND  */
 77 |     EQ = 278,                      /* EQ  */
 78 |     NE = 279,                      /* NE  */
 79 |     GT = 280,                      /* GT  */
 80 |     LT = 281,                      /* LT  */
 81 |     LTE = 282,                     /* LTE  */
 82 |     GTE = 283,                     /* GTE  */
 83 |     XOR = 284,                     /* XOR  */
 84 |     POWER = 285,                   /* POWER  */
 85 |     NOT = 286,                     /* NOT  */
 86 |     INTCAST = 287,                 /* INTCAST  */
 87 |     FLTCAST = 288,                 /* FLTCAST  */
 88 |     UMINUS = 289,                  /* UMINUS  */
 89 |     ACCUM = 290,                   /* ACCUM  */
 90 |     DIFF = 291                     /* DIFF  */
 91 |   };
 92 |   typedef enum fftokentype fftoken_kind_t;
 93 | #endif
 94 | /* Token kinds.  */
 95 | #define FFEMPTY -2
 96 | #define FFEOF 0
 97 | #define FFerror 256
 98 | #define FFUNDEF 257
 99 | #define BOOLEAN 258
100 | #define LONG 259
101 | #define DOUBLE 260
102 | #define STRING 261
103 | #define BITSTR 262
104 | #define FUNCTION 263
105 | #define BFUNCTION 264
106 | #define IFUNCTION 265
107 | #define GTIFILTER 266
108 | #define GTIOVERLAP 267
109 | #define REGFILTER 268
110 | #define COLUMN 269
111 | #define BCOLUMN 270
112 | #define SCOLUMN 271
113 | #define BITCOL 272
114 | #define ROWREF 273
115 | #define NULLREF 274
116 | #define SNULLREF 275
117 | #define OR 276
118 | #define AND 277
119 | #define EQ 278
120 | #define NE 279
121 | #define GT 280
122 | #define LT 281
123 | #define LTE 282
124 | #define GTE 283
125 | #define XOR 284
126 | #define POWER 285
127 | #define NOT 286
128 | #define INTCAST 287
129 | #define FLTCAST 288
130 | #define UMINUS 289
131 | #define ACCUM 290
132 | #define DIFF 291
133 | 
134 | /* Value type.  */
135 | #if ! defined FFSTYPE && ! defined FFSTYPE_IS_DECLARED
136 | union FFSTYPE
137 | {
138 | #line 199 "eval.y"
139 | 
140 |     int    Node;        /* Index of Node */
141 |     double dbl;         /* real value    */
142 |     long   lng;         /* integer value */
143 |     char   log;         /* logical value */
144 |     char   str[MAX_STRLEN];    /* string value  */
145 | 
146 | #line 147 "y.tab.h"
147 | 
148 | };
149 | typedef union FFSTYPE FFSTYPE;
150 | # define FFSTYPE_IS_TRIVIAL 1
151 | # define FFSTYPE_IS_DECLARED 1
152 | #endif
153 | 
154 | 
155 | extern FFSTYPE fflval;
156 | 
157 | int ffparse (void);
158 | 
159 | #endif /* !FF_FF_Y_TAB_H_INCLUDED  */
160 | 


--------------------------------------------------------------------------------
/iter_a.c:
--------------------------------------------------------------------------------
  1 | #include 
  2 | #include 
  3 | #include 
  4 | #include "fitsio.h"
  5 | 
  6 | /*
  7 |   This program illustrates how to use the CFITSIO iterator function.
  8 |   It reads and modifies the input 'iter_a.fit' file by computing a
  9 |   value for the 'rate' column as a function of the values in the other
 10 |   'counts' and 'time' columns.
 11 | */
 12 | main()
 13 | {
 14 |     extern flux_rate(); /* external work function is passed to the iterator */
 15 |     fitsfile *fptr;
 16 |     iteratorCol cols[3];  /* structure used by the iterator function */
 17 |     int n_cols;
 18 |     long rows_per_loop, offset;
 19 | 
 20 |     int status, nkeys, keypos, hdutype, ii, jj;
 21 |     char filename[]  = "iter_a.fit";     /* name of rate FITS file */
 22 | 
 23 |     status = 0; 
 24 | 
 25 |     fits_open_file(&fptr, filename, READWRITE, &status); /* open file */
 26 | 
 27 |     /* move to the desired binary table extension */
 28 |     if (fits_movnam_hdu(fptr, BINARY_TBL, "RATE", 0, &status) )
 29 |         fits_report_error(stderr, status);    /* print out error messages */
 30 | 
 31 |     n_cols  = 3;   /* number of columns */
 32 | 
 33 |     /* define input column structure members for the iterator function */
 34 |     fits_iter_set_by_name(&cols[0], fptr, "COUNTS", TLONG,  InputCol);
 35 |     fits_iter_set_by_name(&cols[1], fptr, "TIME",   TFLOAT, InputCol);
 36 |     fits_iter_set_by_name(&cols[2], fptr, "RATE",   TFLOAT, OutputCol);
 37 | 
 38 |     rows_per_loop = 0;  /* use default optimum number of rows */
 39 |     offset = 0;         /* process all the rows */
 40 | 
 41 |     /* apply the rate function to each row of the table */
 42 |     printf("Calling iterator function...%d\n", status);
 43 | 
 44 |     fits_iterate_data(n_cols, cols, offset, rows_per_loop,
 45 |                       flux_rate, 0L, &status);
 46 | 
 47 |     fits_close_file(fptr, &status);      /* all done */
 48 | 
 49 |     if (status)
 50 |         fits_report_error(stderr, status);  /* print out error messages */
 51 | 
 52 |     return(status);
 53 | }
 54 | /*--------------------------------------------------------------------------*/
 55 | int flux_rate(long totalrows, long offset, long firstrow, long nrows,
 56 |              int ncols, iteratorCol *cols, void *user_strct ) 
 57 | 
 58 | /*
 59 |    Sample iterator function that calculates the output flux 'rate' column
 60 |    by dividing the input 'counts' by the 'time' column.
 61 |    It also applies a constant deadtime correction factor if the 'deadtime'
 62 |    keyword exists.  Finally, this creates or updates the 'LIVETIME'
 63 |    keyword with the sum of all the individual integration times.
 64 | */
 65 | {
 66 |     int ii, status = 0;
 67 | 
 68 |     /* declare variables static to preserve their values between calls */
 69 |     static long *counts;
 70 |     static float *interval;
 71 |     static float *rate;
 72 |     static float deadtime, livetime; /* must preserve values between calls */
 73 | 
 74 |     /*--------------------------------------------------------*/
 75 |     /*  Initialization procedures: execute on the first call  */
 76 |     /*--------------------------------------------------------*/
 77 |     if (firstrow == 1)
 78 |     {
 79 |        if (ncols != 3)
 80 |            return(-1);  /* number of columns incorrect */
 81 | 
 82 |        if (fits_iter_get_datatype(&cols[0]) != TLONG  ||
 83 |            fits_iter_get_datatype(&cols[1]) != TFLOAT ||
 84 |            fits_iter_get_datatype(&cols[2]) != TFLOAT )
 85 |            return(-2);  /* bad data type */
 86 | 
 87 |        /* assign the input pointers to the appropriate arrays and null ptrs*/
 88 |        counts       = (long *)  fits_iter_get_array(&cols[0]);
 89 |        interval     = (float *) fits_iter_get_array(&cols[1]);
 90 |        rate         = (float *) fits_iter_get_array(&cols[2]);
 91 | 
 92 |        livetime = 0;  /* initialize the total integration time */
 93 | 
 94 |        /* try to get the deadtime keyword value */
 95 |        fits_read_key(cols[0].fptr, TFLOAT, "DEADTIME", &deadtime, '\0',
 96 |                      &status);
 97 |        if (status)
 98 |        {
 99 |            deadtime = 1.0;  /* default deadtime if keyword doesn't exist */
100 |        }
101 |        else if (deadtime < 0. || deadtime > 1.0)
102 |        {
103 |            return(-1);    /* bad deadtime value */
104 |        }
105 | 
106 |        printf("deadtime = %f\n", deadtime);
107 |     }
108 | 
109 |     /*--------------------------------------------*/
110 |     /*  Main loop: process all the rows of data */
111 |     /*--------------------------------------------*/
112 | 
113 |     /*  NOTE: 1st element of array is the null pixel value!  */
114 |     /*  Loop from 1 to nrows, not 0 to nrows - 1.  */
115 | 
116 |     /* this version tests for null values */
117 |     rate[0] = DOUBLENULLVALUE;   /* define the value that represents null */
118 | 
119 |     for (ii = 1; ii <= nrows; ii++)
120 |     {
121 |        if (counts[ii] == counts[0])   /*  undefined counts value? */
122 |        {
123 |            rate[ii] = DOUBLENULLVALUE;
124 |        }
125 |        else if (interval[ii] > 0.)
126 |        {
127 |            rate[ii] = counts[ii] / interval[ii] / deadtime;
128 |            livetime += interval[ii];  /* accumulate total integration time */
129 |        }
130 |        else
131 |            return(-2);  /* bad integration time */
132 |     }
133 | 
134 |     /*-------------------------------------------------------*/
135 |     /*  Clean up procedures:  after processing all the rows  */
136 |     /*-------------------------------------------------------*/
137 | 
138 |     if (firstrow + nrows - 1 == totalrows)
139 |     {
140 |         /*  update the LIVETIME keyword value */
141 | 
142 |         fits_update_key(cols[0].fptr, TFLOAT, "LIVETIME", &livetime, 
143 |                  "total integration time", &status);
144 |         printf("livetime = %f\n", livetime);
145 |    }
146 |     return(0);  /* return successful status */
147 | }
148 | 


--------------------------------------------------------------------------------
/grparser.h:
--------------------------------------------------------------------------------
  1 | /*		T E M P L A T E   P A R S E R   H E A D E R   F I L E
  2 | 		=====================================================
  3 | 
  4 | 		by Jerzy.Borkowski@obs.unige.ch
  5 | 
  6 | 		Integral Science Data Center
  7 | 		ch. d'Ecogia 16
  8 | 		1290 Versoix
  9 | 		Switzerland
 10 | 
 11 | 14-Oct-98: initial release
 12 | 16-Oct-98: reference to fitsio.h removed, also removed strings after #endif
 13 | 		directives to make gcc -Wall not to complain
 14 | 20-Oct-98: added declarations NGP_XTENSION_SIMPLE and NGP_XTENSION_FIRST
 15 | 24-Oct-98: prototype of ngp_read_line() function updated.
 16 | 22-Jan-99: prototype for ngp_set_extver() function added.
 17 | 20-Jun-2002 Wm Pence, added support for the HIERARCH keyword convention
 18 |             (changed NGP_MAX_NAME from (20) to FLEN_KEYWORD)
 19 | */
 20 | 
 21 | #ifndef	GRPARSER_H_INCLUDED
 22 | #define	GRPARSER_H_INCLUDED
 23 | 
 24 | #ifdef __cplusplus
 25 | extern "C" {
 26 | #endif
 27 | 
 28 | 	/* error codes  - now defined in fitsio.h */
 29 | 
 30 | 	/* common constants definitions */
 31 | 
 32 | #define	NGP_ALLOCCHUNK		(1000)
 33 | #define	NGP_MAX_INCLUDE		(10)			/* include file nesting limit */
 34 | #define	NGP_MAX_COMMENT		(80)			/* max size for comment */
 35 | #define	NGP_MAX_NAME		FLEN_KEYWORD		/* max size for KEYWORD (FITS limits it to 8 chars) */
 36 |                                                         /* except HIERARCH can have longer effective keyword names */
 37 | #define	NGP_MAX_STRING		(80)			/* max size for various strings */
 38 | #define	NGP_MAX_ARRAY_DIM	(999)			/* max. number of dimensions in array */
 39 | #define NGP_MAX_FNAME           (1000)                  /* max size of combined path+fname */
 40 | #define	NGP_MAX_ENVFILES	(10000)			/* max size of CFITSIO_INCLUDE_FILES env. variable */
 41 | 
 42 | #define	NGP_TOKEN_UNKNOWN	(-1)			/* token type unknown */
 43 | #define	NGP_TOKEN_INCLUDE	(0)			/* \INCLUDE token */
 44 | #define	NGP_TOKEN_GROUP		(1)			/* \GROUP token */
 45 | #define	NGP_TOKEN_END		(2)			/* \END token */
 46 | #define	NGP_TOKEN_XTENSION	(3)			/* XTENSION token */
 47 | #define	NGP_TOKEN_SIMPLE	(4)			/* SIMPLE token */
 48 | #define	NGP_TOKEN_EOF		(5)			/* End Of File pseudo token */
 49 | 
 50 | #define	NGP_TTYPE_UNKNOWN	(0)			/* undef (yet) token type - invalid to print/write to disk */
 51 | #define	NGP_TTYPE_BOOL		(1)			/* boolean, it is 'T' or 'F' */
 52 | #define	NGP_TTYPE_STRING	(2)			/* something withing "" or starting with letter */
 53 | #define	NGP_TTYPE_INT		(3)			/* starting with digit and not with '.' */
 54 | #define	NGP_TTYPE_REAL		(4)			/* digits + '.' */
 55 | #define	NGP_TTYPE_COMPLEX	(5)			/* 2 reals, separated with ',' */
 56 | #define	NGP_TTYPE_NULL		(6)			/* NULL token, format is : NAME = / comment */
 57 | #define	NGP_TTYPE_RAW		(7)			/* HISTORY/COMMENT/8SPACES + comment string without / */
 58 | 
 59 | #define	NGP_FOUND_EQUAL_SIGN	(1)			/* line contains '=' after keyword name */
 60 | 
 61 | #define	NGP_FORMAT_OK		(0)			/* line format OK */
 62 | #define	NGP_FORMAT_ERROR	(1)			/* line format error */
 63 | 
 64 | #define	NGP_NODE_INVALID	(0)			/* default node type - invalid (to catch errors) */
 65 | #define	NGP_NODE_IMAGE		(1)			/* IMAGE type */
 66 | #define	NGP_NODE_ATABLE		(2)			/* ASCII table type */
 67 | #define	NGP_NODE_BTABLE		(3)			/* BINARY table type */
 68 | 
 69 | #define	NGP_NON_SYSTEM_ONLY	(0)			/* save all keywords except NAXIS,BITPIX,etc.. */
 70 | #define	NGP_REALLY_ALL		(1)			/* save really all keywords */
 71 | 
 72 | #define	NGP_XTENSION_SIMPLE	(1)			/* HDU defined with SIMPLE T */
 73 | #define	NGP_XTENSION_FIRST	(2)			/* this is first extension in template */
 74 | 
 75 | #define	NGP_LINE_REREAD		(1)			/* reread line */
 76 | 
 77 | #define	NGP_BITPIX_INVALID	(-12345)		/* default BITPIX (to catch errors) */
 78 | 
 79 | 	/* common macro definitions */
 80 | 
 81 | #ifdef	NGP_PARSER_DEBUG_MALLOC
 82 | 
 83 | #define	ngp_alloc(x)		dal_malloc(x)
 84 | #define	ngp_free(x)		dal_free(x)
 85 | #define	ngp_realloc(x,y)	dal_realloc(x,y)
 86 | 
 87 | #else
 88 | 
 89 | #define	ngp_alloc(x)		malloc(x)
 90 | #define	ngp_free(x)		free(x)
 91 | #define	ngp_realloc(x,y)	realloc(x,y)
 92 | 
 93 | #endif
 94 | 
 95 | 	/* type definitions */
 96 | 
 97 | typedef struct NGP_RAW_LINE_STRUCT
 98 |       {	char	*line;
 99 | 	char	*name;
100 | 	char	*value;
101 | 	int	type;
102 | 	char	*comment;
103 | 	int	format;
104 | 	int	flags;
105 |       } NGP_RAW_LINE;
106 | 
107 | 
108 | typedef union NGP_TOKVAL_UNION
109 |       {	char	*s;		/* space allocated separately, be careful !!! */
110 | 	char	b;
111 | 	int	i;
112 | 	double	d;
113 | 	struct NGP_COMPLEX_STRUCT
114 | 	 { double re;
115 | 	   double im;
116 | 	 } c;			/* complex value */
117 |       } NGP_TOKVAL;
118 | 
119 | 
120 | typedef struct NGP_TOKEN_STRUCT
121 |       { int		type;
122 |         char		name[NGP_MAX_NAME];
123 |         NGP_TOKVAL	value;
124 |         char		comment[NGP_MAX_COMMENT];
125 |       } NGP_TOKEN;
126 | 
127 | 
128 | typedef struct NGP_HDU_STRUCT
129 |       {	int		tokcnt;
130 |         NGP_TOKEN	*tok;
131 |       } NGP_HDU;
132 | 
133 | 
134 | typedef struct NGP_TKDEF_STRUCT
135 |       {	char	*name;
136 | 	int	code;
137 |       } NGP_TKDEF;
138 | 
139 | 
140 | typedef struct NGP_EXTVER_TAB_STRUCT
141 |       {	char	*extname;
142 | 	int	version;
143 |       } NGP_EXTVER_TAB;
144 | 
145 | 
146 | 	/* globally visible variables declarations */
147 | 
148 | extern	NGP_RAW_LINE	ngp_curline;
149 | extern	NGP_RAW_LINE	ngp_prevline;
150 | 
151 | extern	int		ngp_extver_tab_size;
152 | extern	NGP_EXTVER_TAB	*ngp_extver_tab;
153 | 
154 | 
155 | 	/* globally visible functions declarations */
156 | 
157 | int	ngp_get_extver(char *extname, int *version);
158 | int	ngp_set_extver(char *extname, int version);
159 | int	ngp_delete_extver_tab(void);
160 | int	ngp_line_from_file(FILE *fp, char **p);
161 | int	ngp_free_line(void);
162 | int	ngp_free_prevline(void);
163 | int	ngp_read_line_buffered(FILE *fp);
164 | int	ngp_unread_line(void);
165 | int	ngp_extract_tokens(NGP_RAW_LINE *cl);
166 | int	ngp_include_file(char *fname);
167 | int	ngp_read_line(int ignore_blank_lines);
168 | int	ngp_keyword_is_write(NGP_TOKEN *ngp_tok);
169 | int     ngp_keyword_all_write(NGP_HDU *ngph, fitsfile *ffp, int mode);
170 | int	ngp_hdu_init(NGP_HDU *ngph);
171 | int	ngp_hdu_clear(NGP_HDU *ngph);
172 | int	ngp_hdu_insert_token(NGP_HDU *ngph, NGP_TOKEN *newtok);
173 | int	ngp_append_columns(fitsfile *ff, NGP_HDU *ngph, int aftercol);
174 | int	ngp_read_xtension(fitsfile *ff, int parent_hn, int simple_mode);
175 | int	ngp_read_group(fitsfile *ff, char *grpname, int parent_hn);
176 | 
177 | 		/* top level API function - now defined in fitsio.h */
178 | 
179 | #ifdef __cplusplus
180 | }
181 | #endif
182 | 
183 | #endif
184 | 


--------------------------------------------------------------------------------
/iter_b.f:
--------------------------------------------------------------------------------
  1 |       program f77iterate_b
  2 | 
  3 | C     external work function is passed to the iterator
  4 |       external str_iter
  5 | 
  6 |       integer ncols
  7 |       parameter (ncols=2)
  8 |       integer units(ncols), colnum(ncols), datatype(ncols)
  9 |       integer iotype(ncols), offset, rows_per_loop, status
 10 |       character*70 colname(ncols)
 11 | 
 12 |       integer iunit, blocksize
 13 |       character*80 fname
 14 | 
 15 | C     include f77.inc -------------------------------------
 16 | C     Codes for FITS extension types
 17 |       integer IMAGE_HDU, ASCII_TBL, BINARY_TBL
 18 |       parameter (
 19 |      &     IMAGE_HDU  = 0,
 20 |      &     ASCII_TBL  = 1,
 21 |      &     BINARY_TBL = 2  )
 22 | 
 23 | C     Codes for FITS table data types
 24 | 
 25 |       integer TBIT,TBYTE,TLOGICAL,TSTRING,TSHORT,TINT
 26 |       integer TFLOAT,TDOUBLE,TCOMPLEX,TDBLCOMPLEX
 27 |       parameter (
 28 |      &     TBIT        =   1,
 29 |      &     TBYTE       =  11,
 30 |      &     TLOGICAL    =  14,
 31 |      &     TSTRING     =  16,
 32 |      &     TSHORT      =  21,
 33 |      &     TINT        =  31,
 34 |      &     TFLOAT      =  42,
 35 |      &     TDOUBLE     =  82,
 36 |      &     TCOMPLEX    =  83,
 37 |      &     TDBLCOMPLEX = 163  )
 38 | 
 39 | C     Codes for iterator column types
 40 | 
 41 |       integer InputCol, InputOutputCol, OutputCol
 42 |       parameter (
 43 |      &     InputCol       = 0,
 44 |      &     InputOutputCol = 1,
 45 |      &     OutputCol      = 2  )
 46 | C     End of f77.inc -------------------------------------
 47 | 
 48 |       status = 0
 49 | 
 50 |       fname = 'iter_b.fit'
 51 |       iunit = 15
 52 | 
 53 | C     both columns are in the same FITS file
 54 |       units(1) = iunit
 55 |       units(2) = iunit
 56 | 
 57 | C     open the file and move to the correct extension
 58 |       call ftopen(iunit,fname,1,blocksize,status)
 59 |       call ftmnhd(iunit, BINARY_TBL, 'iter_test', 0, status)
 60 | 
 61 | C     define the desired columns by name
 62 |       colname(1) = 'Avalue'
 63 |       colname(2) = 'Lvalue'
 64 | 
 65 | C     leave column numbers undefined
 66 |       colnum(1) = 0
 67 |       colnum(2) = 0  
 68 | 
 69 | C     define the desired datatype for each column: TSTRING & TLOGICAL
 70 |       datatype(1) = TSTRING
 71 |       datatype(2) = TLOGICAL
 72 | 
 73 | C     define whether columns are input, input/output, or output only
 74 | C     Both in/out
 75 |       iotype(1) = InputOutputCol
 76 |       iotype(2) = InputOutputCol
 77 |  
 78 | C     use default optimum number of rows and process all the rows
 79 |       rows_per_loop = 0
 80 |       offset = 0
 81 | 
 82 | C     apply the  function to each row of the table
 83 |       print *,'Calling iterator function...', status
 84 | 
 85 |       call ftiter( ncols, units, colnum, colname, datatype, iotype,
 86 |      &      offset, rows_per_loop, str_iter, 0, status )
 87 | 
 88 |       call ftclos(iunit, status)
 89 | 
 90 | C     print out error messages if problem
 91 |       if (status.ne.0) call ftrprt('STDERR', status)
 92 |       stop
 93 |       end
 94 | 
 95 | C--------------------------------------------------------------------------
 96 | C
 97 | C   Sample iterator function.
 98 | C
 99 | C--------------------------------------------------------------------------
100 |       subroutine str_iter(totalrows, offset, firstrow, nrows, ncols,
101 |      &     units, colnum, datatype, iotype, repeat, status, 
102 |      &     userData, stringCol, logicalCol )
103 | 
104 |       integer totalrows,offset,firstrow,nrows,ncols,status
105 |       integer units(*),colnum(*),datatype(*),iotype(*),repeat(*)
106 |       integer userData
107 |       character*(*) stringCol(*)
108 |       logical logicalCol(*)
109 | 
110 |       integer ii
111 | 
112 | C     include f77.inc -------------------------------------
113 | C     Codes for FITS extension types
114 |       integer IMAGE_HDU, ASCII_TBL, BINARY_TBL
115 |       parameter (
116 |      &     IMAGE_HDU  = 0,
117 |      &     ASCII_TBL  = 1,
118 |      &     BINARY_TBL = 2  )
119 | 
120 | C     Codes for FITS table data types
121 | 
122 |       integer TBIT,TBYTE,TLOGICAL,TSTRING,TSHORT,TINT
123 |       integer TFLOAT,TDOUBLE,TCOMPLEX,TDBLCOMPLEX
124 |       parameter (
125 |      &     TBIT        =   1,
126 |      &     TBYTE       =  11,
127 |      &     TLOGICAL    =  14,
128 |      &     TSTRING     =  16,
129 |      &     TSHORT      =  21,
130 |      &     TINT        =  31,
131 |      &     TFLOAT      =  42,
132 |      &     TDOUBLE     =  82,
133 |      &     TCOMPLEX    =  83,
134 |      &     TDBLCOMPLEX = 163  )
135 | 
136 | C     Codes for iterator column types
137 | 
138 |       integer InputCol, InputOutputCol, OutputCol
139 |       parameter (
140 |      &     InputCol       = 0,
141 |      &     InputOutputCol = 1,
142 |      &     OutputCol      = 2  )
143 | C     End of f77.inc -------------------------------------
144 | 
145 |       if (status .ne. 0) return
146 | 
147 | C    --------------------------------------------------------
148 | C      Initialization procedures: execute on the first call  
149 | C    --------------------------------------------------------
150 |       if (firstrow .eq. 1) then
151 |          if (ncols .ne. 2) then
152 |             status = -1
153 |             return
154 |          endif
155 |          
156 |          if (datatype(1).ne.TSTRING .or. datatype(2).ne.TLOGICAL) then
157 |             status = -2
158 |             return
159 |          endif
160 |          
161 |          print *,'Total rows, No. rows = ',totalrows, nrows
162 |          
163 |       endif
164 |       
165 | C     -------------------------------------------
166 | C       Main loop: process all the rows of data 
167 | C     -------------------------------------------
168 |       
169 | C     NOTE: 1st element of array is the null pixel value!
170 | C     Loop over elements 2 to nrows+1, not 1 to nrows.
171 |       
172 |       do 10 ii=2,nrows+1
173 |          print *, stringCol(ii), logicalCol(ii)
174 |          if( logicalCol(ii) ) then
175 |             logicalCol(ii) = .false.
176 |             stringCol(ii) = 'changed to false'
177 |          else
178 |             logicalCol(ii) = .true.
179 |             stringCol(ii) = 'changed to true'
180 |          endif
181 |  10   continue
182 |       
183 | C     -------------------------------------------------------
184 | C     Clean up procedures:  after processing all the rows  
185 | C     -------------------------------------------------------
186 |       
187 |       if (firstrow + nrows - 1 .eq. totalrows) then
188 | C     no action required in this case
189 |       endif
190 |       
191 |       return
192 |       end
193 |       
194 | 


--------------------------------------------------------------------------------
/iter_c.c:
--------------------------------------------------------------------------------
  1 | #include 
  2 | #include 
  3 | #include 
  4 | #include "fitsio.h"
  5 | 
  6 | /*
  7 |     This example program illustrates how to use the CFITSIO iterator function.
  8 | 
  9 |     This program creates a 2D histogram of the X and Y columns of an event
 10 |     list.  The 'main' routine just creates the empty new image, then executes
 11 |     the 'writehisto' work function by calling the CFITSIO iterator function.
 12 | 
 13 |     'writehisto' opens the FITS event list that contains the X and Y columns.
 14 |     It then calls a second work function, calchisto, (by recursively calling
 15 |     the CFITSIO iterator function) which actually computes the 2D histogram.
 16 | */
 17 | 
 18 | /*   Globally defined parameters */
 19 | 
 20 | long xsize = 480; /* size of the histogram image */
 21 | long ysize = 480;
 22 | long xbinsize = 32;
 23 | long ybinsize = 32;
 24 | 
 25 | main()
 26 | {
 27 |     extern writehisto();  /* external work function passed to the iterator */
 28 |     extern long xsize, ysize;  /* size of image */
 29 | 
 30 |     fitsfile *fptr;
 31 |     iteratorCol cols[1];
 32 |     int n_cols, status = 0;
 33 |     long n_per_loop, offset, naxes[2];
 34 |     char filename[]  = "histoimg.fit";     /* name of FITS image */
 35 | 
 36 |     remove(filename);   /* delete previous version of the file if it exists */
 37 |     fits_create_file(&fptr, filename, &status);  /* create new output image */
 38 | 
 39 |     naxes[0] = xsize;
 40 |     naxes[1] = ysize;
 41 |     fits_create_img(fptr, LONG_IMG, 2, naxes, &status); /* create primary HDU */
 42 | 
 43 |     n_cols  = 1;   /* number of columns */
 44 | 
 45 |     /* define input column structure members for the iterator function */
 46 |     fits_iter_set_by_name(&cols[0], fptr, " ", TLONG, OutputCol);
 47 | 
 48 |     n_per_loop = -1;  /* force whole array to be passed at one time */
 49 |     offset = 0;       /* don't skip over any pixels */
 50 | 
 51 |     /* execute the function to create and write the 2D histogram */
 52 |     printf("Calling writehisto iterator work function... %d\n", status);
 53 | 
 54 |     fits_iterate_data(n_cols, cols, offset, n_per_loop,
 55 |                       writehisto, 0L, &status);
 56 | 
 57 |     fits_close_file(fptr, &status);      /* all done; close the file */
 58 | 
 59 |     if (status)
 60 |         fits_report_error(stderr, status);  /* print out error messages */
 61 |     else
 62 |         printf("Program completed successfully.\n");
 63 | 
 64 |     return(status);
 65 | }
 66 | /*--------------------------------------------------------------------------*/
 67 | int writehisto(long totaln, long offset, long firstn, long nvalues,
 68 |              int narrays, iteratorCol *histo, void *userPointer)
 69 | /*
 70 |    Iterator work function that writes out the 2D histogram.
 71 |    The histogram values are calculated by another work function, calchisto.
 72 | 
 73 |    This routine is executed only once since nvalues was forced to = totaln.
 74 | */
 75 | {
 76 |     extern calchisto();  /* external function called by the iterator */
 77 |     long *histogram;
 78 |     fitsfile *tblptr;
 79 |     iteratorCol cols[2];
 80 |     int n_cols, status = 0;
 81 |     long rows_per_loop, rowoffset;
 82 |     char filename[]  = "iter_c.fit";     /* name of FITS table */
 83 | 
 84 |     /* do sanity checking of input values */
 85 |     if (totaln != nvalues)
 86 |         return(-1);  /* whole image must be passed at one time */
 87 | 
 88 |     if (narrays != 1)
 89 |         return(-2);  /* number of images is incorrect */
 90 | 
 91 |     if (fits_iter_get_datatype(&histo[0]) != TLONG)
 92 |         return(-3);  /* input array has wrong data type */
 93 | 
 94 |     /* assign the FITS array pointer to the global histogram pointer */
 95 |     histogram = (long *) fits_iter_get_array(&histo[0]);
 96 | 
 97 |     /* open the file and move to the table containing the X and Y columns */
 98 |     fits_open_file(&tblptr, filename, READONLY, &status);
 99 |     fits_movnam_hdu(tblptr, BINARY_TBL, "EVENTS", 0, &status);
100 |     if (status)
101 |        return(status);
102 |    
103 |     n_cols = 2; /* number of columns */
104 | 
105 |     /* define input column structure members for the iterator function */
106 |     fits_iter_set_by_name(&cols[0], tblptr, "X", TLONG,  InputCol);
107 |     fits_iter_set_by_name(&cols[1], tblptr, "Y", TLONG, InputCol);
108 | 
109 |     rows_per_loop = 0;  /* take default number of rows per interation */
110 |     rowoffset = 0;     
111 | 
112 |     /* calculate the histogram */
113 |     printf("Calling calchisto iterator work function... %d\n", status);
114 | 
115 |     fits_iterate_data(n_cols, cols, rowoffset, rows_per_loop,
116 |                       calchisto, histogram, &status);
117 | 
118 |     fits_close_file(tblptr, &status);      /* all done */
119 |     return(status);
120 | }
121 | /*--------------------------------------------------------------------------*/
122 | int calchisto(long totalrows, long offset, long firstrow, long nrows,
123 |              int ncols, iteratorCol *cols, void *userPointer)
124 | 
125 | /*
126 |    Interator work function that calculates values for the 2D histogram.
127 | */
128 | {
129 |     extern long xsize, ysize, xbinsize, ybinsize;
130 |     long ii, ihisto, xbin, ybin;
131 |     static long *xcol, *ycol, *histogram;  /* static to preserve values */
132 | 
133 |     /*--------------------------------------------------------*/
134 |     /*  Initialization procedures: execute on the first call  */
135 |     /*--------------------------------------------------------*/
136 |     if (firstrow == 1)
137 |     {
138 |         /* do sanity checking of input values */
139 |        if (ncols != 2)
140 |          return(-3);  /* number of arrays is incorrect */
141 | 
142 |        if (fits_iter_get_datatype(&cols[0]) != TLONG ||
143 |            fits_iter_get_datatype(&cols[1]) != TLONG)
144 |          return(-4);  /* wrong datatypes */
145 | 
146 |        /* assign the input array points to the X and Y arrays */
147 |        xcol = (long *) fits_iter_get_array(&cols[0]);
148 |        ycol = (long *) fits_iter_get_array(&cols[1]);
149 |        histogram = (long *) userPointer;
150 | 
151 |        /* initialize the histogram image pixels = 0 */
152 |        for (ii = 0; ii <= xsize * ysize; ii++)
153 |            histogram[ii] = 0L;
154 |     }
155 | 
156 |     /*------------------------------------------------------------------*/
157 |     /*  Main loop: increment the 2D histogram at position of each event */
158 |     /*------------------------------------------------------------------*/
159 | 
160 |     for (ii = 1; ii <= nrows; ii++) 
161 |     {
162 |         xbin = xcol[ii] / xbinsize;
163 |         ybin = ycol[ii] / ybinsize;
164 | 
165 |         ihisto = ( ybin * xsize ) + xbin + 1;
166 |         histogram[ihisto]++;
167 |     }
168 | 
169 |     return(0);
170 | }
171 | 
172 | 


--------------------------------------------------------------------------------
/Makefile.in:
--------------------------------------------------------------------------------
  1 | #
  2 | # Makefile for cfitsio library:
  3 | #
  4 | # Oct-96 : original version by 
  5 | #
  6 | #       JDD/WDP
  7 | #       NASA GSFC
  8 | #       Oct 1996
  9 | #
 10 | # 25-Jan-01 : removed conditional drvrsmem.c compilation because this
 11 | #             is now handled within the source file itself.
 12 | # 09-Mar-98 : modified to conditionally compile drvrsmem.c. Also
 13 | # changes to target all (deleted clean), added DEFS, LIBS, added
 14 | # DEFS to .c.o, added SOURCES_SHMEM and MY_SHMEM, expanded getcol*
 15 | # and putcol* in SOURCES, modified OBJECTS, mv changed to /bin/mv
 16 | # (to bypass aliasing), cp changed to /bin/cp, add smem and
 17 | # testprog targets. See also changes and comments in configure.in
 18 | 
 19 | 
 20 | # Default library name:
 21 | PACKAGE		= cfitsio
 22 | 
 23 | # CFITSIO version numbers:
 24 | CFITSIO_MAJOR   = @CFITSIO_MAJOR@
 25 | CFITSIO_MINOR	= @CFITSIO_MINOR@
 26 | CFITSIO_MICRO   = @CFITSIO_MICRO@
 27 | CFITSIO_SONAME	= @CFITSIO_SONAME@
 28 | 
 29 | prefix		= @prefix@
 30 | exec_prefix	= @exec_prefix@
 31 | CFITSIO_BIN	= ${DESTDIR}@bindir@
 32 | CFITSIO_LIB	= ${DESTDIR}@libdir@
 33 | CFITSIO_INCLUDE	= ${DESTDIR}@includedir@
 34 | INSTALL_DIRS	= ${DESTDIR}@INSTALL_ROOT@ ${CFITSIO_INCLUDE} ${CFITSIO_LIB} ${CFITSIO_LIB}/pkgconfig
 35 | 
 36 | 
 37 | SHELL =		/bin/sh
 38 | ARCHIVE =	@ARCHIVE@
 39 | RANLIB =	@RANLIB@
 40 | CC =		@CC@
 41 | CFLAGS =	@CFLAGS@
 42 | CPPFLAGS =	@CPPFLAGS@
 43 | SSE_FLAGS =	@SSE_FLAGS@
 44 | FC =		@FC@
 45 | LDFLAGS =	@LDFLAGS@
 46 | LDFLAGS_BIN =	@LDFLAGS_BIN@
 47 | DEFS =		@DEFS@
 48 | LIBS =		@LIBS@
 49 | LIBS_CURL =	@LIBS_CURL@
 50 | FLEX =		flex
 51 | BISON =		bison
 52 | 
 53 | SHLIB_LD =	@SHLIB_LD@
 54 | SHLIB_SUFFIX =	@SHLIB_SUFFIX@
 55 | CFITSIO_SHLIB =	@CFITSIO_SHLIB@
 56 | CFITSIO_SHLIB_SONAME = @CFITSIO_SHLIB_SONAME@
 57 | 
 58 | 
 59 | CORE_SOURCES = 	buffers.c cfileio.c checksum.c drvrfile.c drvrmem.c \
 60 | 		drvrnet.c drvrsmem.c editcol.c edithdu.c eval_l.c \
 61 | 		eval_y.c eval_f.c fitscore.c getcol.c getcolb.c getcold.c getcole.c \
 62 | 		getcoli.c getcolj.c getcolk.c getcoll.c getcols.c getcolsb.c \
 63 | 		getcoluk.c getcolui.c getcoluj.c getkey.c group.c grparser.c \
 64 | 		histo.c iraffits.c \
 65 | 		modkey.c putcol.c putcolb.c putcold.c putcole.c putcoli.c \
 66 | 		putcolj.c putcolk.c putcoluk.c putcoll.c putcols.c putcolsb.c \
 67 | 		putcolu.c putcolui.c putcoluj.c putkey.c region.c scalnull.c \
 68 | 		swapproc.c wcssub.c wcsutil.c imcompress.c quantize.c ricecomp.c \
 69 | 		pliocomp.c fits_hcompress.c fits_hdecompress.c \
 70 | 		simplerng.c @GSIFTP_SRC@
 71 | 
 72 | ZLIB_SOURCES =	zcompress.c zuncompress.c
 73 | 
 74 | SOURCES = ${CORE_SOURCES} ${ZLIB_SOURCES} @F77_WRAPPERS@
 75 | 
 76 | OBJECTS = 	${SOURCES:.c=.o}
 77 | 
 78 | CORE_OBJECTS = 	${CORE_SOURCES:.c=.o} ${ZLIB_SOURCES:.c=.o}
 79 | 
 80 | 
 81 | FITSIO_SRC =	f77_wrap1.c f77_wrap2.c f77_wrap3.c f77_wrap4.c
 82 | 
 83 | # ============ description of all targets =============
 84 | #       -  <<-- ignore error code
 85 | 
 86 | all:
 87 | 		@if [ "x${FC}" = x ]; then \
 88 | 			${MAKE} all-nofitsio; \
 89 | 		else \
 90 | 			${MAKE} stand_alone; \
 91 | 		fi
 92 | 
 93 | all-nofitsio:
 94 | 		${MAKE} stand_alone "FITSIO_SRC="
 95 | 
 96 | stand_alone:	lib${PACKAGE}.a shared
 97 | 
 98 | lib${PACKAGE}.a:	${OBJECTS}
 99 | 		${ARCHIVE} $@ ${OBJECTS}; \
100 | 		${RANLIB} $@;
101 | 
102 | shared: lib${PACKAGE}${SHLIB_SUFFIX}
103 | 
104 | lib${PACKAGE}${SHLIB_SUFFIX}: ${OBJECTS}
105 | 		${SHLIB_LD} ${LDFLAGS} -o ${CFITSIO_SHLIB} ${OBJECTS} -lm ${LIBS_CURL} ${LIBS}
106 | 		@if [ "x${CFITSIO_SHLIB_SONAME}" != x ]; then \
107 | 			ln -sf ${CFITSIO_SHLIB} ${CFITSIO_SHLIB_SONAME}; \
108 | 			ln -sf ${CFITSIO_SHLIB_SONAME} $@; \
109 | 		fi
110 | 
111 | install:	lib${PACKAGE}.a ${INSTALL_DIRS}
112 | 		@for lib in lib${PACKAGE}.a lib${PACKAGE}${SHLIB_SUFFIX} \
113 | 				${CFITSIO_SHLIB} ${CFITSIO_SHLIB_SONAME}; do \
114 | 		    if [ -f $$lib ]; then \
115 | 			echo "/bin/cp -a $$lib ${CFITSIO_LIB}"; \
116 | 			/bin/cp -a $$lib ${CFITSIO_LIB}; \
117 | 		    fi; \
118 | 		done
119 | 		/bin/cp fitsio.h fitsio2.h longnam.h drvrsmem.h ${CFITSIO_INCLUDE}
120 | 		/bin/cp cfitsio.pc ${CFITSIO_LIB}/pkgconfig
121 | 		@for task in ${FPACK_UTILS} ${UTILS}; do \
122 | 		    if [ -f $$task ]; then \
123 | 			if [ ! -d ${CFITSIO_BIN} ]; then mkdir -p ${CFITSIO_BIN}; fi; \
124 | 			echo "/bin/cp $$task ${CFITSIO_BIN}"; \
125 | 			/bin/cp $$task ${CFITSIO_BIN}; \
126 | 		    fi; \
127 | 		done
128 | 
129 | .c.o:
130 | 		${CC} -c -o ${ eval_l.c1
171 | 		# Note workaround for yyfree=fffree conflict
172 | 		/bin/sed -e 's/yy/ff/g' -e 's/YY/FF/g' eval_l.c1 -e 's/fffree/yyfffree/g' > eval_l.c
173 | 		/bin/rm -f eval_l.c1
174 | 		${BISON} -d -v -y eval.y
175 | 		/bin/sed -e 's/yy/ff/g' -e 's/YY/FF/g' y.tab.c > eval_y.c
176 | 		/bin/sed -e 's/yy/ff/g' -e 's/YY/FF/g' y.tab.h > eval_tab.h
177 | 		/bin/rm -f y.tab.c y.tab.h
178 | 
179 | clean:
180 | 	-	/bin/rm -rf *.o zlib/*.o *.dSYM lib${PACKAGE}* y.output so_locations \
181 | 		${UTILS} ${FPACK_UTILS} testprog.fit testf77
182 | 
183 | distclean:	clean
184 | 	-	/bin/rm -f Makefile cfitsio.pc config.log config.status configure.lineno
185 | 
186 | # Make target which outputs the list of the .o contained in the cfitsio lib
187 | # usefull to build a single big shared library containing Tcl/Tk and other
188 | # extensions.  used for the Tcl Plugin. 
189 | 
190 | cfitsioLibObjs:
191 | 	@echo ${CORE_OBJECTS}
192 | 
193 | cfitsioLibSrcs:
194 | 	@echo ${SOURCES}
195 | 
196 | # This target actually builds the objects needed for the lib in the above
197 | # case
198 | objs: ${CORE_OBJECTS}
199 | 
200 | ${INSTALL_DIRS}:
201 | 	@if [ ! -d $@ ]; then mkdir -p $@; fi
202 | 


--------------------------------------------------------------------------------
/drvrsmem.h:
--------------------------------------------------------------------------------
  1 | /*		S H A R E D   M E M O R Y   D R I V E R
  2 | 		=======================================
  3 | 
  4 | 		  by Jerzy.Borkowski@obs.unige.ch
  5 | 
  6 | 09-Mar-98 : initial version 1.0 released
  7 | 23-Mar-98 : shared_malloc now accepts new handle as an argument
  8 | */
  9 | 
 10 | 
 11 | #include 		/* this is necessary for Solaris/Linux */
 12 | #include 
 13 | #include 
 14 | 
 15 | #ifdef _AIX
 16 | #include 
 17 | #else
 18 | #include 
 19 | #endif
 20 | 
 21 | 		/* configuration parameters */
 22 | 
 23 | #define	SHARED_MAXSEG	(16)		/* maximum number of shared memory blocks */
 24 | 
 25 | #define	SHARED_KEYBASE	(14011963)	/* base for shared memory keys, may be overriden by getenv */
 26 | #define	SHARED_FDNAME	("/tmp/.shmem-lockfile") /* template for lock file name */
 27 | 
 28 | #define	SHARED_ENV_KEYBASE ("SHMEM_LIB_KEYBASE") /* name of environment variable */
 29 | #define	SHARED_ENV_MAXSEG ("SHMEM_LIB_MAXSEG")	/* name of environment variable */
 30 | 
 31 | 		/* useful constants */
 32 | 
 33 | #define	SHARED_RDONLY	(0)		/* flag for shared_(un)lock, lock for read */
 34 | #define	SHARED_RDWRITE	(1)		/* flag for shared_(un)lock, lock for write */
 35 | #define	SHARED_WAIT	(0)		/* flag for shared_lock, block if cannot lock immediate */
 36 | #define	SHARED_NOWAIT	(2)		/* flag for shared_lock, fail if cannot lock immediate */
 37 | #define	SHARED_NOLOCK	(0x100)		/* flag for shared_validate function */
 38 | 
 39 | #define	SHARED_RESIZE	(4)		/* flag for shared_malloc, object is resizeable */
 40 | #define	SHARED_PERSIST	(8)		/* flag for shared_malloc, object is not deleted after last proc detaches */
 41 | 
 42 | #define	SHARED_INVALID	(-1)		/* invalid handle for semaphore/shared memory */
 43 | 
 44 | #define	SHARED_EMPTY	(0)		/* entries for shared_used table */
 45 | #define	SHARED_USED	(1)
 46 | 
 47 | #define	SHARED_GRANUL	(16384)		/* granularity of shared_malloc allocation = phys page size, system dependent */
 48 | 
 49 | 
 50 | 
 51 | 		/* checkpoints in shared memory segments - might be omitted */
 52 | 
 53 | #define	SHARED_ID_0	('J')		/* first byte of identifier in BLKHEAD */
 54 | #define	SHARED_ID_1	('B')		/* second byte of identifier in BLKHEAD */
 55 | 
 56 | #define	BLOCK_REG	(0)		/* value for tflag member of BLKHEAD */
 57 | #define	BLOCK_SHARED	(1)		/* value for tflag member of BLKHEAD */
 58 | 
 59 | 		/* generic error codes */
 60 | 
 61 | #define	SHARED_OK	(0)
 62 | 
 63 | #define	SHARED_ERR_MIN_IDX	SHARED_BADARG
 64 | #define	SHARED_ERR_MAX_IDX	SHARED_NORESIZE
 65 | 
 66 | 
 67 | #define	DAL_SHM_FREE	(0)
 68 | #define	DAL_SHM_USED	(1)
 69 | 
 70 | #define	DAL_SHM_ID0	('D')
 71 | #define	DAL_SHM_ID1	('S')
 72 | #define	DAL_SHM_ID2	('M')
 73 | 
 74 | #define	DAL_SHM_SEGHEAD_ID	(0x19630114)
 75 | 
 76 | 
 77 | 
 78 | 		/* data types */
 79 | 
 80 | /* BLKHEAD object is placed at the beginning of every memory segment (both
 81 |   shared and regular) to allow automatic recognition of segments type */
 82 | 
 83 | typedef union
 84 |       { struct BLKHEADstruct
 85 | 	      {	char	ID[2];		/* ID = 'JB', just as a checkpoint */
 86 | 		char	tflag;		/* is it shared memory or regular one ? */
 87 | 		int	handle;		/* this is not necessary, used only for non-resizeable objects via ptr */
 88 | 	      } s;
 89 | 	double	d;			/* for proper alignment on every machine */
 90 |       } BLKHEAD;
 91 | 
 92 | typedef void *SHARED_P;			/* generic type of shared memory pointer */
 93 | 
 94 | typedef	struct SHARED_GTABstruct	/* data type used in global table */
 95 |       {	int	sem;			/* access semaphore (1 field): process count */
 96 | 	int	semkey;			/* key value used to generate semaphore handle */
 97 | 	int	key;			/* key value used to generate shared memory handle (realloc changes it) */
 98 | 	int	handle;			/* handle of shared memory segment */
 99 | 	int	size;			/* size of shared memory segment */
100 | 	int	nprocdebug;		/* attached proc counter, helps remove zombie segments */
101 | 	char	attr;			/* attributes of shared memory object */
102 |       } SHARED_GTAB;
103 | 
104 | typedef	struct SHARED_LTABstruct	/* data type used in local table */
105 |       {	BLKHEAD	*p;			/* pointer to segment (may be null) */
106 | 	int	tcnt;			/* number of threads in this process attached to segment */
107 | 	int	lkcnt;			/* >=0 <- number of read locks, -1 - write lock */
108 | 	long	seekpos;		/* current pointer position, read/write/seek operations change it */
109 |       } SHARED_LTAB;
110 | 
111 | 
112 | 	/* system dependent definitions */
113 | 
114 | #ifndef HAVE_FLOCK_T
115 | typedef struct flock flock_t;
116 | #define HAVE_FLOCK_T
117 | #endif
118 | 
119 | #ifndef HAVE_UNION_SEMUN
120 | union semun
121 |       {	int val;
122 | 	struct semid_ds *buf;
123 | 	unsigned short *array;
124 |       };
125 | #define HAVE_UNION_SEMUN
126 | #endif
127 | 
128 | 
129 | typedef struct DAL_SHM_SEGHEAD_STRUCT	DAL_SHM_SEGHEAD;
130 | 
131 | struct DAL_SHM_SEGHEAD_STRUCT
132 |       {	int	ID;			/* ID for debugging */
133 | 	int	h;			/* handle of sh. mem */
134 | 	int	size;			/* size of data area */
135 | 	int	nodeidx;		/* offset of root object (node struct typically) */
136 |       };
137 | 
138 | 		/* API routines */
139 | 
140 | #ifdef __cplusplus
141 | extern "C" {
142 | #endif
143 | 
144 | void	shared_cleanup(void);			/* must be called at exit/abort */
145 | int	shared_init(int debug_msgs);		/* must be called before any other shared memory routine */
146 | int	shared_recover(int id);			/* try to recover dormant segment(s) after applic crash */
147 | int	shared_malloc(long size, int mode, int newhandle);	/* allocate n-bytes of shared memory */
148 | int	shared_attach(int idx);			/* attach to segment given index to table */
149 | int	shared_free(int idx);			/* release shared memory */
150 | SHARED_P shared_lock(int idx, int mode);	/* lock segment for reading */
151 | SHARED_P shared_realloc(int idx, long newsize);	/* reallocate n-bytes of shared memory (ON LOCKED SEGMENT ONLY) */
152 | int	shared_size(int idx);			/* get size of attached shared memory segment (ON LOCKED SEGMENT ONLY) */
153 | int	shared_attr(int idx);			/* get attributes of attached shared memory segment (ON LOCKED SEGMENT ONLY) */
154 | int	shared_set_attr(int idx, int newattr);	/* set attributes of attached shared memory segment (ON LOCKED SEGMENT ONLY) */
155 | int	shared_unlock(int idx);			/* unlock segment (ON LOCKED SEGMENT ONLY) */
156 | int	shared_set_debug(int debug_msgs);	/* set/reset debug mode */
157 | int	shared_set_createmode(int mode);	/* set/reset debug mode */
158 | int	shared_list(int id);			/* list segment(s) */
159 | int	shared_uncond_delete(int id);		/* uncondintionally delete (NOWAIT operation) segment(s) */
160 | int	shared_getaddr(int id, char **address);	/* get starting address of FITS file in segment */
161 | 
162 | int	smem_init(void);
163 | int	smem_shutdown(void);
164 | int	smem_setoptions(int options);
165 | int	smem_getoptions(int *options);
166 | int	smem_getversion(int *version);
167 | int	smem_open(char *filename, int rwmode, int *driverhandle);
168 | int	smem_create(char *filename, int *driverhandle);
169 | int	smem_close(int driverhandle);
170 | int	smem_remove(char *filename);
171 | int	smem_size(int driverhandle, LONGLONG *size);
172 | int	smem_flush(int driverhandle);
173 | int	smem_seek(int driverhandle, LONGLONG offset);
174 | int	smem_read(int driverhandle, void *buffer, long nbytes);
175 | int	smem_write(int driverhandle, void *buffer, long nbytes);
176 | 
177 | #ifdef __cplusplus
178 | }
179 | #endif
180 | 


--------------------------------------------------------------------------------
/iter_a.f:
--------------------------------------------------------------------------------
  1 |       program f77iterate_a
  2 | 
  3 |       external flux_rate
  4 |       integer ncols
  5 |       parameter (ncols=3)
  6 |       integer units(ncols), colnum(ncols), datatype(ncols)
  7 |       integer iotype(ncols), offset, rows_per_loop, status
  8 |       character*70 colname(ncols)
  9 |       integer iunit, blocksize
 10 |       character*80 fname
 11 | 
 12 | C     include f77.inc -------------------------------------
 13 | C     Codes for FITS extension types
 14 |       integer IMAGE_HDU, ASCII_TBL, BINARY_TBL
 15 |       parameter (
 16 |      &     IMAGE_HDU  = 0,
 17 |      &     ASCII_TBL  = 1,
 18 |      &     BINARY_TBL = 2  )
 19 | 
 20 | C     Codes for FITS table data types
 21 | 
 22 |       integer TBIT,TBYTE,TLOGICAL,TSTRING,TSHORT,TINT
 23 |       integer TFLOAT,TDOUBLE,TCOMPLEX,TDBLCOMPLEX
 24 |       parameter (
 25 |      &     TBIT        =   1,
 26 |      &     TBYTE       =  11,
 27 |      &     TLOGICAL    =  14,
 28 |      &     TSTRING     =  16,
 29 |      &     TSHORT      =  21,
 30 |      &     TINT        =  31,
 31 |      &     TFLOAT      =  42,
 32 |      &     TDOUBLE     =  82,
 33 |      &     TCOMPLEX    =  83,
 34 |      &     TDBLCOMPLEX = 163  )
 35 | 
 36 | C     Codes for iterator column types
 37 | 
 38 |       integer InputCol, InputOutputCol, OutputCol
 39 |       parameter (
 40 |      &     InputCol       = 0,
 41 |      &     InputOutputCol = 1,
 42 |      &     OutputCol      = 2  )
 43 | C     End of f77.inc -------------------------------------
 44 | 
 45 | 
 46 |       iunit = 15
 47 | 
 48 |       units(1) = iunit
 49 |       units(2) = iunit
 50 |       units(3) = iunit
 51 | 
 52 | C open the file
 53 |       fname = 'iter_a.fit'
 54 |       call ftopen(iunit,fname,1,blocksize,status)
 55 | 
 56 | C move to the HDU containing the rate table
 57 |       call ftmnhd(iunit, BINARY_TBL, 'RATE', 0, status)
 58 | 
 59 | C Select iotypes for column data
 60 |       iotype(1) = InputCol
 61 |       iotype(2) = InputCol
 62 |       iotype(3) = OutputCol
 63 | 
 64 | C Select desired datatypes for column data
 65 |       datatype(1) = TINT
 66 |       datatype(2) = TFLOAT
 67 |       datatype(3) = TFLOAT
 68 | 
 69 | C find the column number corresponding to each column
 70 |       call ftgcno( iunit, 0, 'counts', colnum(1), status )
 71 |       call ftgcno( iunit, 0, 'time', colnum(2), status )
 72 |       call ftgcno( iunit, 0, 'rate', colnum(3), status )
 73 | 
 74 | C use default optimum number of rows
 75 |       rows_per_loop = 0
 76 |       offset = 0
 77 | 
 78 | C apply the rate function to each row of the table
 79 |       print *, 'Calling iterator function...', status
 80 | 
 81 | C although colname is not being used, still need to send a string
 82 | C array in the function
 83 |       call ftiter( ncols, units, colnum, colname, datatype, iotype,
 84 |      &      offset, rows_per_loop, flux_rate, 3, status )
 85 | 
 86 |       call ftclos(iunit, status)
 87 |       stop
 88 |       end
 89 | 
 90 | C***************************************************************************
 91 | C   Sample iterator function that calculates the output flux 'rate' column
 92 | C   by dividing the input 'counts' by the 'time' column.
 93 | C   It also applies a constant deadtime correction factor if the 'deadtime'
 94 | C   keyword exists.  Finally, this creates or updates the 'LIVETIME'
 95 | C   keyword with the sum of all the individual integration times.
 96 | C***************************************************************************
 97 |       subroutine flux_rate(totalrows, offset, firstrow, nrows, ncols,
 98 |      &     units, colnum, datatype, iotype, repeat, status, userData,
 99 |      &     counts, interval, rate )
100 | 
101 |       integer totalrows, offset, firstrow, nrows, ncols
102 |       integer units(ncols), colnum(ncols), datatype(ncols)
103 |       integer iotype(ncols), repeat(ncols)
104 |       integer userData
105 | 
106 | C     include f77.inc -------------------------------------
107 | C     Codes for FITS extension types
108 |       integer IMAGE_HDU, ASCII_TBL, BINARY_TBL
109 |       parameter (
110 |      &     IMAGE_HDU  = 0,
111 |      &     ASCII_TBL  = 1,
112 |      &     BINARY_TBL = 2  )
113 | 
114 | C     Codes for FITS table data types
115 | 
116 |       integer TBIT,TBYTE,TLOGICAL,TSTRING,TSHORT,TINT
117 |       integer TFLOAT,TDOUBLE,TCOMPLEX,TDBLCOMPLEX
118 |       parameter (
119 |      &     TBIT        =   1,
120 |      &     TBYTE       =  11,
121 |      &     TLOGICAL    =  14,
122 |      &     TSTRING     =  16,
123 |      &     TSHORT      =  21,
124 |      &     TINT        =  31,
125 |      &     TFLOAT      =  42,
126 |      &     TDOUBLE     =  82,
127 |      &     TCOMPLEX    =  83,
128 |      &     TDBLCOMPLEX = 163  )
129 | 
130 | C     Codes for iterator column types
131 | 
132 |       integer InputCol, InputOutputCol, OutputCol
133 |       parameter (
134 |      &     InputCol       = 0,
135 |      &     InputOutputCol = 1,
136 |      &     OutputCol      = 2  )
137 | C     End of f77.inc -------------------------------------
138 | 
139 |       integer counts(*)
140 |       real interval(*),rate(*)
141 | 
142 |       integer ii, status
143 |       character*80 comment
144 | 
145 | C**********************************************************************
146 | C  must preserve these values between calls
147 |       real deadtime, livetime
148 |       common /fluxblock/ deadtime, livetime
149 | C**********************************************************************
150 | 
151 |       if (status .ne. 0) return
152 | 
153 | C    --------------------------------------------------------
154 | C      Initialization procedures: execute on the first call  
155 | C    --------------------------------------------------------
156 |       if (firstrow .eq. 1) then
157 |          if (ncols .ne. 3) then
158 | C     wrong number of columns
159 |             status = -1
160 |             return
161 |          endif
162 | 
163 |          if (datatype(1).ne.TINT .or. datatype(2).ne.TFLOAT .or.
164 |      &        datatype(3).ne.TFLOAT ) then
165 | C     bad data type
166 |             status = -2
167 |             return
168 |          endif
169 | 
170 | C     try to get the deadtime keyword value
171 |          call ftgkye( units(1), 'DEADTIME', deadtime, comment, status )
172 | 
173 |          if (status.ne.0) then
174 | C     default deadtime if keyword doesn't exist
175 |             deadtime = 1.0
176 |             status = 0
177 |          elseif (deadtime .lt. 0.0 .or. deadtime .gt. 1.0) then
178 | C     bad deadtime value
179 |             status = -3
180 |             return
181 |          endif
182 | 
183 |          print *, 'deadtime = ', deadtime
184 | 
185 |          livetime = 0.0
186 |       endif
187 | 
188 | C    --------------------------------------------
189 | C      Main loop: process all the rows of data
190 | C    --------------------------------------------
191 |       
192 | C     NOTE: 1st element of array is the null pixel value!
193 | C     Loop over elements 2 to nrows+1, not 1 to nrows.
194 |       
195 | C     this version ignores null values
196 | 
197 | C     set the output null value to zero to ignore nulls */
198 |       rate(1) = 0.0
199 |       do 10 ii = 2,nrows+1
200 |          if ( interval(ii) .gt. 0.0) then
201 |            rate(ii) = counts(ii) / interval(ii) / deadtime
202 |            livetime = livetime + interval(ii)
203 |         else
204 | C     Nonsensical negative time interval
205 |            status = -3
206 |            return
207 |         endif
208 |  10   continue
209 | 
210 | C    -------------------------------------------------------
211 | C      Clean up procedures:  after processing all the rows  
212 | C    -------------------------------------------------------
213 | 
214 |       if (firstrow + nrows - 1 .eq. totalrows) then
215 | C     update the LIVETIME keyword value
216 | 
217 |          call ftukye( units(1),'LIVETIME', livetime, 3,
218 |      &        'total integration time', status )
219 |          print *,'livetime = ', livetime
220 | 
221 |       endif
222 |  
223 |       return
224 |       end
225 | 


--------------------------------------------------------------------------------
/fpack.h:
--------------------------------------------------------------------------------
  1 | /* used by FPACK and FUNPACK
  2 |  * R. Seaman, NOAO
  3 |  * W. Pence, NASA/GSFC
  4 |  */
  5 | 
  6 | #include 
  7 | #include 
  8 | #include 
  9 | 
 10 | /* not needed any more */
 11 | /* #include  */
 12 | /* #include  */
 13 | /* #include  */
 14 | 
 15 | #define	FPACK_VERSION	"1.7.0 (Dec 2013)"
 16 | /*
 17 | VERSION	History
 18 | 
 19 | 1.7.0 (Dec 2013)
 20 |     - extensive changes to the binary table compression method.  All types
 21 |       of binary table columns, including variable length array columns are
 22 |       now supported.  The command line table compression flag has been changed
 23 |       to "-table" instead of "-BETAtable", and a new "-tableonly" flag has
 24 |       been introduced to only compress the binary tables in the input files(s)
 25 |       and not the image HDUs.
 26 | 1.6.1 (Mar 2013)
 27 |     - numerous changes to the BETAtable compression method used to compress
 28 |       binary tables
 29 |     - added support for compression 'steering' keywords that specify the
 30 |       desired compression parameters that should be used when compressing
 31 |       that particular HDU, thus overriding the fpack command line parameter
 32 |       values.
 33 |     
 34 | 1.6.0 (June 2012)
 35 |     - Fixed behavior of the "rename" function on Windows platforms so that
 36 |       it will clobber/delete an existing file before renaming a file to 
 37 |       that name (the rename command behaves differently on POSIX and non-POSIX
 38 |       environments).
 39 | 
 40 | 1.6.0 (February 2011)
 41 |     - Added full support for compressing and uncompressing FITS binary tables
 42 |       using a newly proposed format convention.  This is intended only for
 43 |       further feasibility studies, and is not recommended for use with publicly
 44 |       distributed FITS files.
 45 |     - Use the minimum of the MAD 2nd, 3rd, and 5th order values as a more
 46 |       conservative extimate of the noise when quantizing floating point images.
 47 |     - Enhanced the tile compression routines so that a tile that contains all
 48 |       NaN pixel values will be compressed.
 49 |     - When uncompressing an image that was originally in a FITS primary array,
 50 |       funpack will also append any new keywords that were written into the 
 51 |       primary array of the compressed FITS file after the file was compressed.
 52 |     - Added support for the GZIP_2 algorithm, which shuffles the bytes in the
 53 |       pixel values prior to compressing them with gzip.      
 54 | 1.5.1 (December 2010) Added prototype, mainly hidden, support for compressing 
 55 |       binary tables.  
 56 | 1.5.0 (August 2010) Added the -i2f option to lossy compress integer images.
 57 | 1.4.0 (Jan 2010) Reduced the default value for the q floating point image 
 58 |       quantization parameter from 16 to 4.  This results in about 50% better
 59 |       compression (from about 4.6x to 6.4) with no lost of significant information 
 60 |       (with the new subtractive dithering enhancement).  Replaced the code for
 61 |       generating temporary filenames to make the code more portable (to Windows). 
 62 |       Replaced calls to the unix 'access' and 'stat' functions with more portable
 63 |       code.   When unpacking a file, write it first to a temporary file, then
 64 |       rename it when finished, so that other tasks cannot try to read the file
 65 |       before it is complete.
 66 | 1.3.0 (Oct 2009) added randomization to the dithering pattern so that
 67 |       the same pattern is not used for every image; also added an option
 68 |       for losslessly compressing floating point images with GZIP for test 
 69 |       purposes (not recommended for general use).  Also added support for
 70 |       reading the input FITS file from the stdin file streams.
 71 | 1.2.0 (Sept 2009) added subtractive dithering feature (in CFITSIO) when
 72 |       quantizing floating point images; When packing an IRAF .imh + .pix image,
 73 |       the file name is changed to FILE.fits.fz, and if the original file is
 74 |       deleted, then both the .imh and .pix files are deleted.
 75 | 1.1.4 (May 2009) added -E option to funpack to unpack a list of HDUs
 76 | 1.1.3 (March 2009)  minor modifications to the content and format of the -T report
 77 | 1.1.2 (September 2008)
 78 | */
 79 | 
 80 | #define	FP_INIT_MAGIC	42
 81 | #define	FPACK		0
 82 | #define	FUNPACK		1
 83 | 
 84 | /* changed from 16 in Jan. 2010 */
 85 | #define	DEF_QLEVEL	4.  
 86 | 
 87 | #define	DEF_HCOMP_SCALE	 0.
 88 | #define	DEF_HCOMP_SMOOTH 0
 89 | #define	DEF_RESCALE_NOISE 0
 90 | 
 91 | #define	SZ_STR		513
 92 | #define	SZ_CARD		81
 93 | 
 94 | 
 95 | typedef struct
 96 | {
 97 | 	int	comptype;
 98 | 	float	quantize_level;
 99 | 	int     no_dither;
100 | 	int     dither_offset;
101 | 	int     dither_method;
102 | 	float	scale;
103 | 	float	rescale_noise;
104 | 	int	smooth;
105 | 	int	int_to_float;
106 | 	float	n3ratio;
107 | 	float	n3min;
108 | 	long	ntile[MAX_COMPRESS_DIM];
109 | 
110 | 	int	to_stdout;
111 | 	int	listonly;
112 | 	int	clobber;
113 | 	int	delete_input;
114 | 	int	do_not_prompt;
115 | 	int	do_checksums;
116 | 	int	do_gzip_file;
117 | 	int     do_images;  
118 | 	int     do_tables;  
119 | 	int	test_all;
120 | 	int	verbose;
121 | 
122 | 	char	prefix[SZ_STR];
123 | 	char	extname[SZ_STR];
124 | 	int	delete_suffix;
125 | 	char	outfile[SZ_STR];
126 | 	int	firstfile;
127 | 
128 | 	int	initialized;
129 | 	int	preflight_checked;
130 | } fpstate;
131 | 
132 | typedef struct
133 | {
134 | 	int	n_nulls;
135 | 	double	minval;
136 | 	double 	maxval;
137 | 	double	mean;
138 | 	double	sigma;
139 | 	double	noise1;
140 | 	double	noise2;
141 | 	double	noise3;
142 | 	double	noise5;
143 | } imgstats;
144 | 
145 | int fp_get_param (int argc, char *argv[], fpstate *fpptr);
146 | void abort_fpack(int sig);
147 | void fp_abort_output (fitsfile *infptr, fitsfile *outfptr, int stat); 
148 | int fp_usage (void);
149 | int fp_help (void);
150 | int fp_hint (void); 
151 | int fp_init (fpstate *fpptr);
152 | int fp_list (int argc, char *argv[], fpstate fpvar);
153 | int fp_info (char *infits);
154 | int fp_info_hdu (fitsfile *infptr);
155 | int fp_preflight (int argc, char *argv[], int unpack, fpstate *fpptr);
156 | int fp_loop (int argc, char *argv[], int unpack, fpstate fpvar);
157 | int fp_pack (char *infits, char *outfits, fpstate fpvar, int *islossless);
158 | int fp_unpack (char *infits, char *outfits, fpstate fpvar);
159 | int fp_test (char *infits, char *outfits, char *outfits2, fpstate fpvar);
160 | int fp_pack_hdu (fitsfile *infptr, fitsfile *outfptr, fpstate fpvar, 
161 |     int *islossless, int *status);
162 | int fp_unpack_hdu (fitsfile *infptr, fitsfile *outfptr, fpstate fpvar, int *status);
163 | int fits_read_image_speed (fitsfile *infptr, float *whole_elapse, 
164 |     float *whole_cpu, float *row_elapse, float *row_cpu, int *status);
165 | int fp_test_hdu (fitsfile *infptr, fitsfile *outfptr, fitsfile *outfptr2, 
166 | 	fpstate fpvar, int *status);
167 | int fp_test_table (fitsfile *infptr, fitsfile *outfptr, fitsfile *outfptr2, 
168 | 	fpstate fpvar, int *status);
169 | int marktime(int *status);
170 | int gettime(float *elapse, float *elapscpu, int *status);
171 | int fits_read_image_speed (fitsfile *infptr, float *whole_elapse, 
172 |     float *whole_cpu, float *row_elapse, float *row_cpu, int *status);
173 | 
174 | int fp_i2stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status);
175 | int fp_i4stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status);
176 | int fp_r4stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status);
177 | int fp_i2rescale(fitsfile *infptr, int naxis, long *naxes, double rescale,
178 |     fitsfile *outfptr, int *status);
179 | int fp_i4rescale(fitsfile *infptr, int naxis, long *naxes, double rescale,
180 |     fitsfile *outfptr, int *status);
181 |     
182 | int fp_msg (char *msg);
183 | int fp_version (void);
184 | int fp_noop (void);
185 | 
186 | int fu_get_param (int argc, char *argv[], fpstate *fpptr);
187 | int fu_usage (void);
188 | int fu_hint (void);
189 | int fu_help (void);
190 | 


--------------------------------------------------------------------------------
/pliocomp.c:
--------------------------------------------------------------------------------
  1 | /* stdlib is needed for the abs function */
  2 | #include 
  3 | /*
  4 |    The following prototype code was provided by Doug Tody, NRAO, for
  5 |    performing conversion between pixel arrays and line lists.  The
  6 |    compression technique is used in IRAF.
  7 | */
  8 | int pl_p2li (int *pxsrc, int xs, short *lldst, int npix);
  9 | int pl_l2pi (short *ll_src, int xs, int *px_dst, int npix);
 10 | 
 11 | 
 12 | /*
 13 |  * PL_P2L -- Convert a pixel array to a line list.  The length of the list is
 14 |  * returned as the function value.
 15 |  *
 16 |  * Translated from the SPP version using xc -f, f2c.  8Sep99 DCT.
 17 |  */
 18 | 
 19 | #ifndef min
 20 | #define min(a,b)        (((a)<(b))?(a):(b))
 21 | #endif
 22 | #ifndef max
 23 | #define max(a,b)        (((a)>(b))?(a):(b))
 24 | #endif
 25 | 
 26 | int pl_p2li (int *pxsrc, int xs, short *lldst, int npix)
 27 | /* int *pxsrc;                      input pixel array */
 28 | /* int xs;                          starting index in pxsrc (?) */
 29 | /* short *lldst;                    encoded line list */
 30 | /* int npix;                        number of pixels to convert */
 31 | {
 32 |     /* System generated locals */
 33 |     int ret_val, i__1, i__2, i__3;
 34 | 
 35 |     /* Local variables */
 36 |     int zero, v, x1, hi, ip, dv, xe, np, op, iz, nv = 0, pv, nz;
 37 | 
 38 |     /* Parameter adjustments */
 39 |     --lldst;
 40 |     --pxsrc;
 41 | 
 42 |     /* Function Body */
 43 |     if (! (npix <= 0)) {
 44 |         goto L110;
 45 |     }
 46 |     ret_val = 0;
 47 |     goto L100;
 48 | L110:
 49 |     lldst[3] = -100;
 50 |     lldst[2] = 7;
 51 |     lldst[1] = 0;
 52 |     lldst[6] = 0;
 53 |     lldst[7] = 0;
 54 |     xe = xs + npix - 1;
 55 |     op = 8;
 56 |     zero = 0;
 57 | /* Computing MAX */
 58 |     i__1 = zero, i__2 = pxsrc[xs];
 59 |     pv = max(i__1,i__2);
 60 |     x1 = xs;
 61 |     iz = xs;
 62 |     hi = 1;
 63 |     i__1 = xe;
 64 |     for (ip = xs; ip <= i__1; ++ip) {
 65 |         if (! (ip < xe)) {
 66 |             goto L130;
 67 |         }
 68 | /* Computing MAX */
 69 |         i__2 = zero, i__3 = pxsrc[ip + 1];
 70 |         nv = max(i__2,i__3);
 71 |         if (! (nv == pv)) {
 72 |             goto L140;
 73 |         }
 74 |         goto L120;
 75 | L140:
 76 |         if (! (pv == 0)) {
 77 |             goto L150;
 78 |         }
 79 |         pv = nv;
 80 |         x1 = ip + 1;
 81 |         goto L120;
 82 | L150:
 83 |         goto L131;
 84 | L130:
 85 |         if (! (pv == 0)) {
 86 |             goto L160;
 87 |         }
 88 |         x1 = xe + 1;
 89 | L160:
 90 | L131:
 91 |         np = ip - x1 + 1;
 92 |         nz = x1 - iz;
 93 |         if (! (pv > 0)) {
 94 |             goto L170;
 95 |         }
 96 |         dv = pv - hi;
 97 |         if (! (dv != 0)) {
 98 |             goto L180;
 99 |         }
100 |         hi = pv;
101 |         if (! (abs(dv) > 4095)) {
102 |             goto L190;
103 |         }
104 |         lldst[op] = (short) ((pv & 4095) + 4096);
105 |         ++op;
106 |         lldst[op] = (short) (pv / 4096);
107 |         ++op;
108 |         goto L191;
109 | L190:
110 |         if (! (dv < 0)) {
111 |             goto L200;
112 |         }
113 |         lldst[op] = (short) (-dv + 12288);
114 |         goto L201;
115 | L200:
116 |         lldst[op] = (short) (dv + 8192);
117 | L201:
118 |         ++op;
119 |         if (! (np == 1 && nz == 0)) {
120 |             goto L210;
121 |         }
122 |         v = lldst[op - 1];
123 |         lldst[op - 1] = (short) (v | 16384);
124 |         goto L91;
125 | L210:
126 | L191:
127 | L180:
128 | L170:
129 |         if (! (nz > 0)) {
130 |             goto L220;
131 |         }
132 | L230:
133 |         if (! (nz > 0)) {
134 |             goto L232;
135 |         }
136 |         lldst[op] = (short) min(4095,nz);
137 |         ++op;
138 | /* L231: */
139 |         nz += -4095;
140 |         goto L230;
141 | L232:
142 |         if (! (np == 1 && pv > 0)) {
143 |             goto L240;
144 |         }
145 |         lldst[op - 1] = (short) (lldst[op - 1] + 20481);
146 |         goto L91;
147 | L240:
148 | L220:
149 | L250:
150 |         if (! (np > 0)) {
151 |             goto L252;
152 |         }
153 |         lldst[op] = (short) (min(4095,np) + 16384);
154 |         ++op;
155 | /* L251: */
156 |         np += -4095;
157 |         goto L250;
158 | L252:
159 | L91:
160 |         x1 = ip + 1;
161 |         iz = x1;
162 |         pv = nv;
163 | L120:
164 |         ;
165 |     }
166 | /* L121: */
167 |     lldst[4] = (short) ((op - 1) % 32768);
168 |     lldst[5] = (short) ((op - 1) / 32768);
169 |     ret_val = op - 1;
170 |     goto L100;
171 | L100:
172 |     return ret_val;
173 | } /* plp2li_ */
174 | 
175 | /*
176 |  * PL_L2PI -- Translate a PLIO line list into an integer pixel array.
177 |  * The number of pixels output (always npix) is returned as the function
178 |  * value.
179 |  *
180 |  * Translated from the SPP version using xc -f, f2c.  8Sep99 DCT.
181 |  */
182 | 
183 | int pl_l2pi (short *ll_src, int xs, int *px_dst, int npix)
184 | /* short *ll_src;                   encoded line list */
185 | /* int xs;                          starting index in ll_src */
186 | /* int *px_dst;                    output pixel array */
187 | /* int npix;                       number of pixels to convert */
188 | {
189 |     /* System generated locals */
190 |     int ret_val, i__1, i__2;
191 | 
192 |     /* Local variables */
193 |     int data, sw0001, otop, i__, lllen, i1, i2, x1, x2, ip, xe, np,
194 |              op, pv, opcode, llfirt;
195 |     int skipwd;
196 | 
197 |     /* Parameter adjustments */
198 |     --px_dst;
199 |     --ll_src;
200 | 
201 |     /* Function Body */
202 |     if (! (ll_src[3] > 0)) {
203 |         goto L110;
204 |     }
205 |     lllen = ll_src[3];
206 |     llfirt = 4;
207 |     goto L111;
208 | L110:
209 |     lllen = (ll_src[5] << 15) + ll_src[4];
210 |     llfirt = ll_src[2] + 1;
211 | L111:
212 |     if (! (npix <= 0 || lllen <= 0)) {
213 |         goto L120;
214 |     }
215 |     ret_val = 0;
216 |     goto L100;
217 | L120:
218 |     xe = xs + npix - 1;
219 |     skipwd = 0;
220 |     op = 1;
221 |     x1 = 1;
222 |     pv = 1;
223 |     i__1 = lllen;
224 |     for (ip = llfirt; ip <= i__1; ++ip) {
225 |         if (! skipwd) {
226 |             goto L140;
227 |         }
228 |         skipwd = 0;
229 |         goto L130;
230 | L140:
231 |         opcode = ll_src[ip] / 4096;
232 |         data = ll_src[ip] & 4095;
233 |         sw0001 = opcode;
234 |         goto L150;
235 | L160:
236 |         x2 = x1 + data - 1;
237 |         i1 = max(x1,xs);
238 |         i2 = min(x2,xe);
239 |         np = i2 - i1 + 1;
240 |         if (! (np > 0)) {
241 |             goto L170;
242 |         }
243 |         otop = op + np - 1;
244 |         if (! (opcode == 4)) {
245 |             goto L180;
246 |         }
247 |         i__2 = otop;
248 |         for (i__ = op; i__ <= i__2; ++i__) {
249 |             px_dst[i__] = pv;
250 | /* L190: */
251 |         }
252 | /* L191: */
253 |         goto L181;
254 | L180:
255 |         i__2 = otop;
256 |         for (i__ = op; i__ <= i__2; ++i__) {
257 |             px_dst[i__] = 0;
258 | /* L200: */
259 |         }
260 | /* L201: */
261 |         if (! (opcode == 5 && i2 == x2)) {
262 |             goto L210;
263 |         }
264 |         px_dst[otop] = pv;
265 | L210:
266 | L181:
267 |         op = otop + 1;
268 | L170:
269 |         x1 = x2 + 1;
270 |         goto L151;
271 | L220:
272 |         pv = (ll_src[ip + 1] << 12) + data;
273 |         skipwd = 1;
274 |         goto L151;
275 | L230:
276 |         pv += data;
277 |         goto L151;
278 | L240:
279 |         pv -= data;
280 |         goto L151;
281 | L250:
282 |         pv += data;
283 |         goto L91;
284 | L260:
285 |         pv -= data;
286 | L91:
287 |         if (! (x1 >= xs && x1 <= xe)) {
288 |             goto L270;
289 |         }
290 |         px_dst[op] = pv;
291 |         ++op;
292 | L270:
293 |         ++x1;
294 |         goto L151;
295 | L150:
296 |         ++sw0001;
297 |         if (sw0001 < 1 || sw0001 > 8) {
298 |             goto L151;
299 |         }
300 |         switch ((int)sw0001) {
301 |             case 1:  goto L160;
302 |             case 2:  goto L220;
303 |             case 3:  goto L230;
304 |             case 4:  goto L240;
305 |             case 5:  goto L160;
306 |             case 6:  goto L160;
307 |             case 7:  goto L250;
308 |             case 8:  goto L260;
309 |         }
310 | L151:
311 |         if (! (x1 > xe)) {
312 |             goto L280;
313 |         }
314 |         goto L131;
315 | L280:
316 | L130:
317 |         ;
318 |     }
319 | L131:
320 |     i__1 = npix;
321 |     for (i__ = op; i__ <= i__1; ++i__) {
322 |         px_dst[i__] = 0;
323 | /* L290: */
324 |     }
325 | /* L291: */
326 |     ret_val = npix;
327 |     goto L100;
328 | L100:
329 |     return ret_val;
330 | } /* pll2pi_ */
331 | 
332 | 


--------------------------------------------------------------------------------
/swapproc.c:
--------------------------------------------------------------------------------
  1 | /*  This file, swapproc.c, contains general utility routines that are      */
  2 | /*  used by other FITSIO routines to swap bytes.                           */
  3 | 
  4 | /*  The FITSIO software was written by William Pence at the High Energy    */
  5 | /*  Astrophysic Science Archive Research Center (HEASARC) at the NASA      */
  6 | /*  Goddard Space Flight Center.                                           */
  7 | 
  8 | /* The fast SSE2 and SSSE3 functions were provided by Julian Taylor, ESO */
  9 | 
 10 | #include 
 11 | #include 
 12 | #include "fitsio2.h"
 13 | 
 14 | /* bswap builtin is available since GCC 4.3 */
 15 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
 16 | #define HAVE_BSWAP
 17 | #endif
 18 | 
 19 | #ifdef __SSSE3__
 20 | #include 
 21 | /* swap 16 bytes according to mask, values must be 16 byte aligned */
 22 | static inline void swap_ssse3(char * values, __m128i mask)
 23 | {
 24 |     __m128i v = _mm_load_si128((__m128i *)values);
 25 |     __m128i s = _mm_shuffle_epi8(v, mask);
 26 |     _mm_store_si128((__m128i*)values, s);
 27 | }
 28 | #endif
 29 | #ifdef __SSE2__
 30 | #include 
 31 | /* swap 8 shorts, values must be 16 byte aligned
 32 |  * faster than ssse3 variant for shorts */
 33 | static inline void swap2_sse2(char * values)
 34 | {
 35 |     __m128i r1 = _mm_load_si128((__m128i *)values);
 36 |     __m128i r2 = r1;
 37 |     r1 = _mm_srli_epi16(r1, 8);
 38 |     r2 = _mm_slli_epi16(r2, 8);
 39 |     r1 = _mm_or_si128(r1, r2);
 40 |     _mm_store_si128((__m128i*)values, r1);
 41 | }
 42 | /* the three shuffles required for 4 and 8 byte variants make
 43 |  * SSE2 slower than bswap */
 44 | 
 45 | 
 46 | /* get number of elements to peel to reach alignment */
 47 | static inline size_t get_peel(void * addr, size_t esize, size_t nvals,
 48 |                               size_t alignment)
 49 | {
 50 |     const size_t offset = (size_t)addr % alignment;
 51 |     size_t peel = offset ? (alignment - offset) / esize : 0;
 52 |     peel = nvals < peel ? nvals : peel;
 53 |     return peel;
 54 | }
 55 | #endif
 56 | 
 57 | /*--------------------------------------------------------------------------*/
 58 | static void ffswap2_slow(short *svalues, long nvals)
 59 | {
 60 |     register long ii;
 61 |     unsigned short * usvalues;
 62 | 
 63 |     usvalues = (unsigned short *) svalues;
 64 | 
 65 |     for (ii = 0; ii < nvals; ii++)
 66 |     {
 67 |         usvalues[ii] = (usvalues[ii]>>8) | (usvalues[ii]<<8);
 68 |     }
 69 | }
 70 | /*--------------------------------------------------------------------------*/
 71 | #if __SSE2__
 72 | void ffswap2(short *svalues,  /* IO - pointer to shorts to be swapped    */
 73 |              long nvals)     /* I  - number of shorts to be swapped     */
 74 | /*
 75 |   swap the bytes in the input short integers: ( 0 1 -> 1 0 )
 76 | */
 77 | {
 78 |     if ((long)svalues % 2 != 0) { /* should not happen */
 79 |         ffswap2_slow(svalues, nvals);
 80 |         return;
 81 |     }
 82 | 
 83 |     long ii;
 84 |     size_t peel = get_peel((void*)&svalues[0], sizeof(svalues[0]), nvals, 16);
 85 | 
 86 |     ffswap2_slow(svalues, peel);
 87 |     for (ii = peel; ii < (nvals - peel - (nvals - peel) % 8); ii+=8) {
 88 |         swap2_sse2((char*)&svalues[ii]);
 89 |     }
 90 |     ffswap2_slow(&svalues[ii], nvals - ii);
 91 | }
 92 | #else
 93 | void ffswap2(short *svalues,  /* IO - pointer to shorts to be swapped    */
 94 |              long nvals)     /* I  - number of shorts to be swapped     */
 95 | /*
 96 |   swap the bytes in the input 4-byte integer: ( 0 1 2 3 -> 3 2 1 0 )
 97 | */
 98 | {
 99 |     ffswap2_slow(svalues, nvals);
100 | }
101 | #endif
102 | /*--------------------------------------------------------------------------*/
103 | static void ffswap4_slow(INT32BIT *ivalues, long nvals)
104 | {
105 |     register long ii;
106 | 
107 | #if defined(HAVE_BSWAP)
108 |     for (ii = 0; ii < nvals; ii++)
109 |     {
110 |         ivalues[ii] = __builtin_bswap32(ivalues[ii]);
111 |     }
112 | #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
113 |     /* intrinsic byte swapping function in Microsoft Visual C++ 8.0 and later */
114 |     unsigned int* uivalues = (unsigned int *) ivalues;
115 | 
116 |     /* intrinsic byte swapping function in Microsoft Visual C++ */
117 |     for (ii = 0; ii < nvals; ii++)
118 |     {
119 |         uivalues[ii] = _byteswap_ulong(uivalues[ii]);
120 |     }
121 | #else
122 |     char *cvalues, tmp;
123 | 
124 |     for (ii = 0; ii < nvals; ii++)
125 |     {
126 |         cvalues = (char *)&ivalues[ii];
127 |         tmp = cvalues[0];
128 |         cvalues[0] = cvalues[3];
129 |         cvalues[3] = tmp;
130 |         tmp = cvalues[1];
131 |         cvalues[1] = cvalues[2];
132 |         cvalues[2] = tmp;
133 |     }
134 | #endif
135 | }
136 | /*--------------------------------------------------------------------------*/
137 | #ifdef __SSSE3__
138 | void ffswap4(INT32BIT *ivalues,  /* IO - pointer to INT*4 to be swapped    */
139 |                  long nvals)     /* I  - number of floats to be swapped     */
140 | /*
141 |   swap the bytes in the input 4-byte integer: ( 0 1 2 3 -> 3 2 1 0 )
142 | */
143 | {
144 |     if ((long)ivalues % 4 != 0) { /* should not happen */
145 |         ffswap4_slow(ivalues, nvals);
146 |         return;
147 |     }
148 | 
149 |     long ii;
150 |     const __m128i cmask4 = _mm_set_epi8(12, 13, 14, 15,
151 |                                         8, 9, 10, 11,
152 |                                         4, 5, 6, 7,
153 |                                         0, 1, 2 ,3);
154 |     size_t peel = get_peel((void*)&ivalues[0], sizeof(ivalues[0]), nvals, 16);
155 |     ffswap4_slow(ivalues, peel);
156 |     for (ii = peel; ii < (nvals - peel - (nvals - peel) % 4); ii+=4) {
157 |         swap_ssse3((char*)&ivalues[ii], cmask4);
158 |     }
159 |     ffswap4_slow(&ivalues[ii], nvals - ii);
160 | }
161 | #else
162 | void ffswap4(INT32BIT *ivalues,  /* IO - pointer to INT*4 to be swapped    */
163 |                  long nvals)     /* I  - number of floats to be swapped     */
164 | /*
165 |   swap the bytes in the input 4-byte integer: ( 0 1 2 3 -> 3 2 1 0 )
166 | */
167 | {
168 |     ffswap4_slow(ivalues, nvals);
169 | }
170 | #endif
171 | /*--------------------------------------------------------------------------*/
172 | static void ffswap8_slow(double *dvalues, long nvals)
173 | {
174 |     register long ii;
175 | #ifdef HAVE_BSWAP
176 |     LONGLONG * llvalues = (LONGLONG*)dvalues;
177 | 
178 |     for (ii = 0; ii < nvals; ii++) {
179 |         llvalues[ii] = __builtin_bswap64(llvalues[ii]);
180 |     }
181 | #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
182 |     /* intrinsic byte swapping function in Microsoft Visual C++ 8.0 and later */
183 |     unsigned __int64 * llvalues = (unsigned __int64 *) dvalues;
184 | 
185 |     for (ii = 0; ii < nvals; ii++)
186 |     {
187 |         llvalues[ii] = _byteswap_uint64(llvalues[ii]);
188 |     }
189 | #else
190 |     register char *cvalues;
191 |     register char temp;
192 | 
193 |     cvalues = (char *) dvalues;      /* copy the pointer value */
194 | 
195 |     for (ii = 0; ii < nvals*8; ii += 8)
196 |     {
197 |         temp = cvalues[ii];
198 |         cvalues[ii] = cvalues[ii+7];
199 |         cvalues[ii+7] = temp;
200 | 
201 |         temp = cvalues[ii+1];
202 |         cvalues[ii+1] = cvalues[ii+6];
203 |         cvalues[ii+6] = temp;
204 | 
205 |         temp = cvalues[ii+2];
206 |         cvalues[ii+2] = cvalues[ii+5];
207 |         cvalues[ii+5] = temp;
208 | 
209 |         temp = cvalues[ii+3];
210 |         cvalues[ii+3] = cvalues[ii+4];
211 |         cvalues[ii+4] = temp;
212 |     }
213 | #endif
214 | }
215 | /*--------------------------------------------------------------------------*/
216 | #ifdef __SSSE3__
217 | void ffswap8(double *dvalues,  /* IO - pointer to doubles to be swapped     */
218 |              long nvals)       /* I  - number of doubles to be swapped      */
219 | /*
220 |   swap the bytes in the input doubles: ( 01234567  -> 76543210 )
221 | */
222 | {
223 |     if ((long)dvalues % 8 != 0) { /* should not happen on amd64 */
224 |         ffswap8_slow(dvalues, nvals);
225 |         return;
226 |     }
227 | 
228 |     long ii;
229 |     const __m128i cmask8 = _mm_set_epi8(8, 9, 10, 11, 12, 13, 14, 15,
230 |                                         0, 1, 2 ,3, 4, 5, 6, 7);
231 |     size_t peel = get_peel((void*)&dvalues[0], sizeof(dvalues[0]), nvals, 16);
232 |     ffswap8_slow(dvalues, peel);
233 |     for (ii = peel; ii < (nvals - peel - (nvals - peel) % 2); ii+=2) {
234 |         swap_ssse3((char*)&dvalues[ii], cmask8);
235 |     }
236 |     ffswap8_slow(&dvalues[ii], nvals - ii);
237 | }
238 | #else
239 | void ffswap8(double *dvalues,  /* IO - pointer to doubles to be swapped     */
240 |              long nvals)       /* I  - number of doubles to be swapped      */
241 | /*
242 |   swap the bytes in the input doubles: ( 01234567  -> 76543210 )
243 | */
244 | {
245 |     ffswap8_slow(dvalues, nvals);
246 | }
247 | #endif
248 | 


--------------------------------------------------------------------------------
/README.win:
--------------------------------------------------------------------------------
  1 | Instructions on building and using CFITSIO on Windows platforms
  2 | for C programmers using Microsoft Visual Studio or Borland C++.
  3 | 
  4 | These instructions for building the CFITSIO library under Windows use
  5 | the CMake build system that is available from http://www.cmake.org.
  6 | 
  7 | ===============================================================================
  8 | 
  9 | 1.  Build the CFITSIO dll library
 10 | 
 11 |   a. If CMAKE is not already installed on your machine, download it
 12 |      from  http://www.cmake.org.  It is recommended that you choose the
 13 |      "Add CMake to the system PATH for current user" option during the
 14 |      installation setup process for convenience when running CMake later on.
 15 | 
 16 |   b. Install ZLIB: The compression library "zlib" is required in
 17 |      order to build CFITSIO.  Visit their site at
 18 | 
 19 |        https://zlib.net
 20 | 
 21 |      to download the latest distribution.  Unpack it, then build and
 22 |      install it from a parallel directory, for example:
 23 | 
 24 |        mkdir zlib.build
 25 |        cd zlib.build
 26 |        cmake ..\zlib-1.2.11 -DCMAKE_INSTALL_PREFIX=c:\Users\myname\zlib
 27 |        cmake --build . --config Release
 28 |        cmake --install .
 29 | 
 30 |      The cmake comands below will use the path "c:\Users\myname\zlib"
 31 |      as an example for the installed zlib location.
 32 | 
 33 |   c. Unzip the CFITSIO .zip file (e.g. cfit-4.0.0.zip) that was obtained from
 34 |      the CFITSIO Web site (http://heasarc.gsfc.nasa.gov/fitsio). This will
 35 |      create a new \cfitsio-4.0.0 subdirectory that contains the source code
 36 |      and documentation files.  It also contains a CMakeLists.txt file
 37 |      that will be used during the CMake build process.
 38 | 
 39 |   d. Open the Visual Studio Command Prompt window, likely using a desktop
 40 |      icon with this same name, (or the equivalent Borland command window)
 41 |      and cd (change directory) into the parent directory that is one level
 42 |      above the directory containing the CFITSIO source files that was
 43 |      created in the previous step.
 44 | 
 45 |   e. Create a new subdirectory (for example, "cfitsio.build"), and cd
 46 |      into it with the following commands:
 47 | 
 48 |      mkdir cfitsio.build
 49 |      cd cfitsio.build
 50 | 
 51 |      When using Visual Studio, all the files that are generated during
 52 |      the CMake process will be created in or under this subdirectory.
 53 | 
 54 |   f. Create the CMake files necessary for the build:
 55 | 
 56 |      To use the default Visual Studio compilers and architecture,
 57 |      simply run (for example):
 58 | 
 59 |      cmake ..\cfitsio-4.0.0 -DCMAKE_PREFIX_PATH=c:\Users\myname\zlib
 60 | 
 61 |      Alternatively, you can specify the name of a CMake Generator
 62 |      using the "-G" flag:
 63 | 
 64 |      cmake -G "" ..\cfitsio-4.0.0 -DCMAKE_PREFIX_PATH=c:\Users\myname\zlib
 65 | 
 66 |      Where the string "" designates your choice
 67 |      of compiler. Some possible options are:
 68 | 
 69 |      "Visual Studio 16 2019"
 70 |      "Visual Studio 16 2019" -A Win32    (for 32-bit builds)
 71 |      "Visual Studio 15 2017 Win64"
 72 |      "Visual Studio 15 2017"             (for 32-bit builds)
 73 |      "Visual Studio 15 2017" -A Win32    (for 32-bit builds)
 74 |      "MinGW Makefiles"
 75 |      "Borland Makefiles"
 76 |      "NMake Makefiles"
 77 | 
 78 |      You can see a list of all the available CMake Generators by
 79 |      executing the command
 80 | 
 81 |         cmake /?
 82 | 
 83 |      Note that these names are case-sensitive and must be entered
 84 |      exactly as displayed.
 85 | 
 86 |      Note that the "..\cfitsio-4.0.0" argument gives the relative
 87 |      path to the directory that contains the CFITSIO source files
 88 |      and the CMakeLists.txt file.
 89 | 
 90 |      Some other optional flags are available to use during this
 91 |      step, using this format:
 92 | 
 93 |      cmake -G  ..\cfitsio-4.0.0 -D