├── .gitattributes ├── iter_a.fit ├── iter_c.fit ├── testf77.std ├── vari.fits ├── testprog.std ├── iter_image.fit ├── cmake ├── cfitsioConfig.cmake ├── vcpkg.json └── portfile.cmake ├── cfitsio.pc.in ├── cfitsio.pc.cmake ├── testprog.tpt ├── m4 ├── ltversion.m4 ├── ltsugar.m4 ├── ax_cfitsio.m4 └── lt~obsolete.m4 ├── drvrgsiftp.h ├── f77.inc ├── simplerng.h ├── .gitignore ├── licenses └── License.txt ├── .github └── workflows │ ├── ci.yml │ ├── codeql.yml │ └── documentation.yml ├── README.MacOS ├── group.h ├── region.h ├── utilities ├── fitscopy.c ├── smem.c ├── iter_image.c ├── iter_var.c ├── funpack.c ├── fpack.h ├── fverify.h └── fvrf_file.c ├── README_OLD.win ├── cfitsio.xcodeproj └── project.pbxproj ├── cookbook.out ├── sample.tpl ├── iter_b.c ├── vmsieee.c ├── winDumpExts.mak ├── README.md ├── eval_tab.h ├── iter_a.c ├── Makefile.am ├── cfitsio.spec ├── grparser.h ├── iter_b.f ├── iter_c.c ├── eval_defs.h ├── drvrsmem.h ├── iter_a.f ├── pliocomp.c ├── config └── missing ├── swapproc.c └── README.win /.gitattributes: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /iter_a.fit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HEASARC/cfitsio/HEAD/iter_a.fit -------------------------------------------------------------------------------- /iter_c.fit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HEASARC/cfitsio/HEAD/iter_c.fit -------------------------------------------------------------------------------- /testf77.std: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HEASARC/cfitsio/HEAD/testf77.std -------------------------------------------------------------------------------- /vari.fits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HEASARC/cfitsio/HEAD/vari.fits -------------------------------------------------------------------------------- /testprog.std: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HEASARC/cfitsio/HEAD/testprog.std -------------------------------------------------------------------------------- /iter_image.fit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HEASARC/cfitsio/HEAD/iter_image.fit -------------------------------------------------------------------------------- /cmake/cfitsioConfig.cmake: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/cfitsioTargets.cmake") 2 | -------------------------------------------------------------------------------- /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: @PACKAGE_VERSION@ 10 | Libs: -L${libdir} -lcfitsio 11 | Libs.private: @LIBS_CURL@ @LIBS@ -lm 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /cmake/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cfitsio", 3 | "version": "4.6.2", 4 | "homepage": "https://heasarc.gsfc.nasa.gov/fitsio/fitsio.html", 5 | "description": "CFITSIO - A FITS File Subroutine Library.", 6 | "dependencies": [ 7 | { 8 | "name" : "vcpkg-cmake", 9 | "host" : true 10 | }, 11 | { 12 | "name" : "vcpkg-cmake-config", 13 | "host" : true 14 | }, 15 | "bzip2", 16 | "zlib" 17 | ] 18 | } -------------------------------------------------------------------------------- /cfitsio.pc.cmake: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir="@CMAKE_INSTALL_FULL_LIBDIR@" 4 | includedir="@CMAKE_INSTALL_FULL_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 11 | Libs.private: @PKG_CONFIG_LIBS@ -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 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2011-2019, 2021-2024 Free Software Foundation, 4 | # Inc. 5 | # Written by Scott James Remnant, 2004 6 | # 7 | # This file is free software; the Free Software Foundation gives 8 | # unlimited permission to copy and/or distribute it, with or without 9 | # modifications, as long as this notice is preserved. 10 | 11 | # @configure_input@ 12 | 13 | # serial 4441 ltversion.m4 14 | # This file is part of GNU Libtool 15 | 16 | m4_define([LT_PACKAGE_VERSION], [2.5.4]) 17 | m4_define([LT_PACKAGE_REVISION], [2.5.4]) 18 | 19 | AC_DEFUN([LTVERSION_VERSION], 20 | [macro_version='2.5.4' 21 | macro_revision='2.5.4' 22 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 23 | _LT_DECL(, macro_revision, 0) 24 | ]) 25 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Misc 46 | *~ 47 | *.cache 48 | *.log 49 | *.pc 50 | *.status 51 | *.xcodeproj/project.xcworkspace 52 | *.xcodeproj/xcuserdata 53 | .deps/ 54 | .libs/ 55 | libtool 56 | utilities/.deps/ 57 | utilities/.dirstamp 58 | .vscode/ 59 | build/ 60 | include/ 61 | *.lis 62 | 63 | 64 | # Kernel Module Compile Results 65 | *.mod* 66 | *.cmd 67 | .tmp_versions/ 68 | modules.order 69 | Module.symvers 70 | Mkfile.old 71 | dkms.conf 72 | 73 | # CFITSIO misc 74 | Makefile 75 | config.log 76 | config.status 77 | cfitsio.pc 78 | cookbook 79 | fitscopy 80 | fitsverify 81 | fpack 82 | funpack 83 | imcopy 84 | smem 85 | speed 86 | testprog 87 | iter_a 88 | iter_b 89 | iter_c 90 | iter_image 91 | iter_var 92 | testf77 93 | testprog.fit 94 | -------------------------------------------------------------------------------- /licenses/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 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test 2 | 3 | on: 4 | push: 5 | branches: [main, develop] 6 | pull_request: 7 | branches: [main, develop] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build-default: 14 | runs-on: ${{ matrix.os }} 15 | continue-on-error: true 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest] # Define multiple runners to use 20 | steps: 21 | - uses: actions/checkout@v4 22 | - run: echo "Running on ${{ matrix.os }}" 23 | 24 | - name: Update packages and install dependencies 25 | run: | 26 | sudo apt-get update 27 | sudo apt-get install -y build-essential libtool autoconf automake libcurl4-openssl-dev libbz2-dev 28 | if: matrix.os == 'ubuntu-latest' || matrix.os == 'ubuntu-24.04-arm' 29 | 30 | - name: Configure all defaults 31 | run: ./configure 32 | 33 | - name: Make with defaults (no reentrant) 34 | run: | 35 | make 36 | 37 | - name: Test 38 | run: | 39 | make testprog 40 | ./testprog > testprog.lis 41 | diff testprog.lis testprog.out 42 | cmp testprog.fit testprog.std 43 | 44 | - name: Cookbook 45 | run: | 46 | ./cookbook > cookbook.lis 47 | diff cookbook.lis cookbook.out 48 | 49 | - name: Speed 50 | run: | 51 | ./speed 52 | 53 | - name: Configure with optional features 54 | run: | 55 | make distclean 56 | ./configure --enable-curl --enable-reentrant --with-bzip2 --with-zlib-check 57 | 58 | - name: Make with optional features 59 | run: make 60 | 61 | - name: Test 62 | run: | 63 | make testprog 64 | ./testprog > testprog.lis 65 | diff testprog.lis testprog.out 66 | cmp testprog.fit testprog.std 67 | 68 | 69 | # - name: Iterators 70 | # run: | 71 | # ./iter_a 72 | # ./iter_b 73 | # ./iter_c 74 | # ./iter_var 75 | # ./iter_image 76 | 77 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------- 42 | To install CFITSIO using conda: 43 | --------------------------------------------------------------------- 44 | 45 | If you have conda installed, you may install CFITSIO simply with 46 | the command 47 | 48 | $ conda install cfitsio 49 | 50 | For more information, please visit: 51 | 52 | https://github.com/conda-forge/cfitsio-feedstock 53 | 54 | --------------------------------------------------------------------- 55 | To build CFITSIO using the XCode GUI: 56 | --------------------------------------------------------------------- 57 | 58 | - tar xzf cfitsio3370.tar.gz (or whatever version this is) 59 | - cd cfitsio/ 60 | 61 | - Start Xcode and open cfitsio.xcodeproj/project.pbxproj, 62 | or just "open" the file from a terminal command line, 63 | 64 | $ open cfitsio.xcodeproj/project.pbxproj 65 | 66 | and this will start up XCode for you. 67 | 68 | - Press the Build (or "Play") button in the upper left 69 | corner of the GUI. 70 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /utilities/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 | -------------------------------------------------------------------------------- /utilities/smem.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) 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 %p %.30s\n", id, status, (void *) address, address); 75 | } 76 | return(0); 77 | } 78 | -------------------------------------------------------------------------------- /cmake/portfile.cmake: -------------------------------------------------------------------------------- 1 | # vcpkg-cfitsio provides CMake targets: 2 | # 3 | # Basic usage is: 4 | # 5 | # find_package(cfitsio REQUIRED) 6 | # target_link_libraries(${PROJECT_NAME} PRIVATE CFITSIO::cfitsio) 7 | # 8 | # Notes: 9 | # This is built as a static library. The Windows build does not use pthreads, so you will need to provide your own locking around use of the library. 10 | 11 | vcpkg_check_linkage(ONLY_STATIC_LIBRARY) 12 | 13 | vcpkg_from_github( 14 | OUT_SOURCE_PATH SOURCE_PATH 15 | REPO HEASARC/cfitsio 16 | REF cfitsio-${VERSION} 17 | SHA512 b33c27070b311a831c2a40780549966ef3cc36b7052efd2fe8e44ce07061d9ed8297a822153cc6365469824aaec61c307f6d37adeae79e8b51ca620876b4733a 18 | HEAD_REF main 19 | ) 20 | 21 | set (options 22 | "-DUSE_BZIP2=ON " 23 | "-DUSE_CURL=OFF " 24 | "-DTESTS=OFF " 25 | "-DUTILS=OFF" 26 | ) 27 | if(VCPKG_TARGET_IS_WINDOWS) 28 | set (options "${options}; -DUSE_PTHREADS=OFF") 29 | else() 30 | set (options "${options}; -DUSE_PTHREADS=ON") 31 | endif() 32 | 33 | message ("****************************************************************") 34 | message ("Setting build options: " ${options}) 35 | message ("****************************************************************") 36 | 37 | vcpkg_cmake_configure( 38 | SOURCE_PATH "${SOURCE_PATH}" 39 | OPTIONS ${options} 40 | ) 41 | 42 | vcpkg_cmake_install() 43 | 44 | vcpkg_copy_pdbs() 45 | 46 | vcpkg_fixup_pkgconfig() 47 | # 48 | # cfitsio puts its cmake files into /lib/cmake/cfitsio, but vcpkg doesn't want 49 | # them there, causing error messages: 50 | # 1> [CMake] D:\Github\DSS\./vcpkg_overlay_ports\cfitsio\portfile.cmake: warning: This port installs the following CMake files in places CMake files are not expected. CMake files should be installed in ${CURRENT_PACKAGES_DIR}/share/${PORT}. To suppress this message, add set(VCPKG_POLICY_SKIP_MISPLACED_CMAKE_FILES_CHECK enabled) 51 | # 1> [CMake] D:\Github\DSS\build\vcpkg_installed\vcpkg\pkgs\cfitsio_x64-windows-static-md: note: the files are relative to ${CURRENT_PACKAGES_DIR} here 52 | # 1> [CMake] note: lib/cmake/cfitsio/cfitsioConfig.cmake 53 | # 1> [CMake] note: lib/cmake/cfitsio/cfitsioConfigVersion.cmake 54 | # 1> [CMake] note: lib/cmake/cfitsio/cfitsioTargets-release.cmake 55 | # 1> [CMake] note: lib/cmake/cfitsio/cfitsioTargets.cmake 56 | # 1> [CMake] note: debug/lib/cmake/cfitsio/cfitsioConfig.cmake 57 | # 1> [CMake] note: debug/lib/cmake/cfitsio/cfitsioConfigVersion.cmake 58 | # 1> [CMake] note: debug/lib/cmake/cfitsio/cfitsioTargets-debug.cmsake 59 | # 1> [CMake] note: debug/lib/cmake/cfitsio/cfitsioTargets.cmake 60 | # 61 | # So tell vcpkg to fix this for us. 62 | # 63 | vcpkg_cmake_config_fixup(CONFIG_PATH "lib/cmake/${PORT}") 64 | 65 | file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") 66 | 67 | file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") 68 | vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/licenses/License.txt") 69 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # See https://codeql.github.com/ for details on CodeQL. 2 | # 3 | name: "CodeQL" 4 | 5 | on: 6 | push: 7 | branches: [ "develop", "main" ] 8 | pull_request: 9 | # The branches below must be a subset of the branches above 10 | branches: [ "develop", "main" ] 11 | schedule: 12 | - cron: '30 10 * * 2' 13 | 14 | jobs: 15 | analyze: 16 | name: Analyze 17 | # Runner size impacts CodeQL analysis time. To learn more, please see: 18 | # - https://gh.io/recommended-hardware-resources-for-running-codeql 19 | # - https://gh.io/supported-runners-and-hardware-resources 20 | # - https://gh.io/using-larger-runners 21 | # Consider using larger runners for possible analysis time improvements. 22 | runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} 23 | timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} 24 | permissions: 25 | actions: read 26 | contents: read 27 | security-events: write 28 | 29 | strategy: 30 | fail-fast: false 31 | matrix: 32 | language: [ 'c-cpp' ] 33 | # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] 34 | # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both 35 | # Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both 36 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 37 | 38 | steps: 39 | - name: Checkout repository 40 | uses: actions/checkout@v4 41 | 42 | # Initializes the CodeQL tools for scanning. 43 | - name: Initialize CodeQL 44 | uses: github/codeql-action/init@v3 45 | with: 46 | languages: ${{ matrix.language }} 47 | # If you wish to specify custom queries, you can do so here or in a config file. 48 | # By default, queries listed here will override any specified in a config file. 49 | # Prefix the list here with "+" to use these queries and those in the config file. 50 | 51 | # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 52 | # queries: security-extended,security-and-quality 53 | 54 | - name: Install dependencies 55 | run: sudo apt-get -o Acquire::Retries=3 update && sudo apt-get -o Acquire::Retries=3 -y install build-essential zlib1g-dev libffi-dev make cmake apt-file software-properties-common libssl-dev build-essential autotools-dev automake autoconf libtool pkgconf gcc gfortran g++ 56 | 57 | - name: Build CFITSIO 58 | run: | 59 | autoreconf -f -i 60 | ./configure 61 | CFLAGS="-Wp,-D_GLIBCXX_ASSERTIONS" 62 | export CFLAGS 63 | CXXFLAGS="-Wp,-D_GLIBCXX_ASSERTIONS" 64 | export CXXFLAGS 65 | gcc --version 66 | make 67 | make install 68 | 69 | - name: Perform CodeQL Analysis 70 | uses: github/codeql-action/analyze@v3 71 | with: 72 | category: "/language:${{matrix.language}}" 73 | -------------------------------------------------------------------------------- /utilities/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 dividing 9 | all the pixel values by a factor of 10 (DESTROYING THE ORIGINAL IMAGE!!!) 10 | */ 11 | int main(int argc, char *argv[]) 12 | { 13 | /* external work function is passed to the iterator: */ 14 | extern int div_image(long totalrows, long offset, long firstrow, 15 | long nrows, int ncols, iteratorCol *cols, void *user_strct); 16 | fitsfile *fptr; 17 | iteratorCol cols[3]; /* structure used by the iterator function */ 18 | int n_cols =1; 19 | long rows_per_loop =0 , /* use default optimum number of rows */ 20 | offset =0; /* process all the rows */ 21 | 22 | int status=0, nkeys, keypos, hdutype, ii, jj; 23 | char filename[] = "iter_image.fit"; /* name of image FITS file */ 24 | 25 | fits_open_file(&fptr, filename, READWRITE, &status); /* open file */ 26 | 27 | /* define input column structure members for the iterator function */ 28 | fits_iter_set_file(&cols[0], fptr); 29 | fits_iter_set_iotype(&cols[0], InputOutputCol); 30 | fits_iter_set_datatype(&cols[0], 0); 31 | 32 | /* apply the div_image function to each row of the image */ 33 | printf("Calling iterator function...%d\n", status); 34 | 35 | fits_iterate_data(n_cols, cols, offset, rows_per_loop, 36 | div_image, 0L, &status); 37 | 38 | fits_close_file(fptr, &status); /* all done */ 39 | 40 | if (status) 41 | fits_report_error(stderr, status); /* print out error messages */ 42 | 43 | return status; 44 | } 45 | /*--------------------------------------------------------------------------*/ 46 | int div_image(long totalrows, long offset, long firstrow, long nrows, 47 | int ncols, iteratorCol *cols, void *user_strct ) 48 | 49 | /* 50 | Sample iterator function that takes all pixel values of the image 51 | and divides each individually by 100. 52 | */ 53 | { 54 | int status = 0; 55 | 56 | /* declare variables static to preserve their values between calls */ 57 | static int *counts; 58 | 59 | /*--------------------------------------------------------*/ 60 | /* Initialization procedures: execute on the first call */ 61 | /*--------------------------------------------------------*/ 62 | if (firstrow == 1) 63 | { 64 | if (ncols != 1) 65 | return(-1); /* number of columns incorrect */ 66 | 67 | /* assign the input pointers to the appropriate arrays and null ptrs*/ 68 | counts = (int *) fits_iter_get_array(&cols[0]); 69 | } 70 | 71 | /*--------------------------------------------*/ 72 | /* Main loop: process all the rows of data */ 73 | /*--------------------------------------------*/ 74 | 75 | /* NOTE: 1st element of array is the null pixel value! */ 76 | /* Loop from 1 to nrows, not 0 to nrows - 1. */ 77 | 78 | for (int ii = 1; ii <= nrows; ii++) 79 | { 80 | counts[ii] /= 10 ; 81 | } 82 | printf("firstrows, nrows = %ld %ld\n", firstrow, nrows); 83 | 84 | return(0); /* return successful status */ 85 | } 86 | -------------------------------------------------------------------------------- /utilities/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 the input 'vari.fits' file, moves to the binary 9 | table in the "COMPRESSED_IMAGE" extension, and prints the 10 | float-values in the column COMPRESSED_DATA. 11 | */ 12 | int main(int argc, char *argv[]) 13 | { 14 | /* external work function is passed to the iterator */ 15 | extern int flux_rate(long totalrows, long offset, long firstrow, 16 | long nrows, int ncols, iteratorCol *cols, void *user_strct); 17 | fitsfile *fptr; 18 | iteratorCol cols[3]; /* structure used by the iterator function */ 19 | int n_cols=1; /* number of columns */ 20 | long rows_per_loop, offset; 21 | 22 | int status, nkeys, keypos, hdutype, ii, jj; 23 | char filename[] = "vari.fits"; /* name of rate FITS file */ 24 | 25 | status = 0; 26 | 27 | fits_open_file(&fptr, filename, READWRITE, &status); /* open file */ 28 | 29 | /* move to the desired binary table extension */ 30 | if (fits_movnam_hdu(fptr, BINARY_TBL, "COMPRESSED_IMAGE", 0, &status) ) 31 | fits_report_error(stderr, status); /* print out error messages */ 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 prints the values (assumed to be 58 | of type float). 59 | */ 60 | { 61 | /* declare variables static to preserve their values between calls */ 62 | static float *counts; 63 | 64 | /*--------------------------------------------------------*/ 65 | /* Initialization procedures: execute on the first call */ 66 | /*--------------------------------------------------------*/ 67 | if (firstrow == 1) 68 | { 69 | 70 | printf("Datatype of column = %d\n",fits_iter_get_datatype(&cols[0])); 71 | 72 | /* assign the input pointers to the appropriate arrays and null ptrs*/ 73 | counts = (float *) fits_iter_get_array(&cols[0]); 74 | 75 | } 76 | 77 | /*--------------------------------------------*/ 78 | /* Main loop: process all the rows of data */ 79 | /*--------------------------------------------*/ 80 | 81 | /* NOTE: 1st element of array is the null pixel value! */ 82 | /* Loop from 1 to nrows, not 0 to nrows - 1. */ 83 | 84 | 85 | for (int ii = 1; ii <= nrows; ii++) 86 | { 87 | long repeat = fits_iter_get_repeat(&cols[0]); 88 | printf("repeat = %ld, %f\n", repeat, counts[ii]); 89 | } 90 | 91 | 92 | return(0); /* return successful status */ 93 | } 94 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /cookbook.out: -------------------------------------------------------------------------------- 1 | Header listing for HDU #1: 2 | SIMPLE = T / file does conform to FITS standard 3 | BITPIX = 16 / number of bits per data pixel 4 | NAXIS = 2 / number of data axes 5 | NAXIS1 = 300 / length of data axis 1 6 | NAXIS2 = 200 / length of data axis 2 7 | EXTEND = T / FITS dataset may contain extensions 8 | COMMENT FITS (Flexible Image Transport System) format is defined in 'Astronomy 9 | COMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H 10 | BZERO = 32768 / offset data range to that of unsigned short 11 | BSCALE = 1 / default scaling factor 12 | EXPOSURE= 1500 / Total Exposure Time 13 | END 14 | 15 | Header listing for HDU #2: 16 | XTENSION= 'TABLE ' / ASCII table extension 17 | BITPIX = 8 / 8-bit ASCII characters 18 | NAXIS = 2 / 2-dimensional ASCII table 19 | NAXIS1 = 20 / width of table in characters 20 | NAXIS2 = 6 / number of rows in table 21 | PCOUNT = 0 / no group parameters (required keyword) 22 | GCOUNT = 1 / one data group (required keyword) 23 | TFIELDS = 3 / number of fields in each row 24 | TTYPE1 = 'Planet ' / label for field 1 25 | TBCOL1 = 1 / beginning column of field 1 26 | TFORM1 = 'A8 ' / Fortran-77 format of field 27 | TTYPE2 = 'Diameter' / label for field 2 28 | TBCOL2 = 10 / beginning column of field 2 29 | TFORM2 = 'I6 ' / Fortran-77 format of field 30 | TUNIT2 = 'km ' / physical unit of field 31 | TTYPE3 = 'Density ' / label for field 3 32 | TBCOL3 = 17 / beginning column of field 3 33 | TFORM3 = 'F4.2 ' / Fortran-77 format of field 34 | TUNIT3 = 'g/cm ' / physical unit of field 35 | EXTNAME = 'PLANETS_ASCII' / name of this ASCII table extension 36 | END 37 | 38 | Header listing for HDU #3: 39 | XTENSION= 'BINTABLE' / binary table extension 40 | BITPIX = 8 / 8-bit bytes 41 | NAXIS = 2 / 2-dimensional binary table 42 | NAXIS1 = 16 / width of table in bytes 43 | NAXIS2 = 6 / number of rows in table 44 | PCOUNT = 0 / size of special data area 45 | GCOUNT = 1 / one data group (required keyword) 46 | TFIELDS = 3 / number of fields in each row 47 | TTYPE1 = 'Planet ' / label for field 1 48 | TFORM1 = '8A ' / data format of field: ASCII Character 49 | TTYPE2 = 'Diameter' / label for field 2 50 | TFORM2 = '1J ' / data format of field: 4-byte INTEGER 51 | TUNIT2 = 'km ' / physical unit of field 52 | TTYPE3 = 'Density ' / label for field 3 53 | TFORM3 = '1E ' / data format of field: 4-byte REAL 54 | TUNIT3 = 'g/cm ' / physical unit of field 55 | EXTNAME = 'PLANETS_Binary' / name of this binary table extension 56 | END 57 | 58 | 59 | Min and max image pixels = 0, 498 60 | 61 | Reading ASCII table in HDU 2: 62 | Row Planet Diameter Density 63 | 1 Mercury 4880 5.10 64 | 2 Venus 12112 5.30 65 | 3 Earth 12742 5.52 66 | 4 Mars 6800 3.94 67 | 5 Jupiter 143000 1.33 68 | 6 Saturn 121000 0.69 69 | 70 | Reading binary table in HDU 3: 71 | Row Planet Diameter Density 72 | 1 Mercury 4880 5.10 73 | 2 Venus 12112 5.30 74 | 3 Earth 12742 5.52 75 | 4 Mars 6800 3.94 76 | 5 Jupiter 143000 1.33 77 | 6 Saturn 121000 0.69 78 | 79 | All the cfitsio cookbook routines ran successfully. 80 | -------------------------------------------------------------------------------- /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 | int main() 13 | { 14 | extern int 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 = %ld %ld\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 | -------------------------------------------------------------------------------- /.github/workflows/documentation.yml: -------------------------------------------------------------------------------- 1 | name: Build Documentation 2 | 3 | on: 4 | push: 5 | branches: [main, develop] 6 | paths: 7 | - 'docs/**' 8 | pull_request: 9 | branches: [main, develop] 10 | paths: 11 | - 'docs/**' 12 | release: 13 | types: [published] 14 | workflow_dispatch: 15 | 16 | 17 | jobs: 18 | 19 | # Using the default ubuntu runner 20 | Build-Documentation-Runner: 21 | runs-on: ubuntu-latest 22 | permissions: 23 | contents: write # Needed for release uploads 24 | 25 | steps: 26 | 27 | - name: Set up Git repository 28 | uses: actions/checkout@v4 29 | 30 | # We need texlive and latex2html for the tex files 31 | # pandoc for the markdown files 32 | # gh CLI is needed to upload to a release. it's pre-installed on ubuntu-latest runners 33 | - name: Install dependencies 34 | run: | 35 | sudo apt-get update -y 36 | sudo apt-get install -y texlive-latex-base texlive-latex-extra texlive-fonts-recommended latex2html pandoc 37 | 38 | # our latex files have \usepackage{html} because we create webpages on our systems 39 | - name: Find and link html.sty for Ubuntu TeXLive 40 | run: | 41 | # Find where Ubuntu's TeXLive expects files 42 | TEXMF_DIR=$(kpsewhich -var-value TEXMFLOCAL) 43 | echo "TEXMF local directory: $TEXMF_DIR" 44 | 45 | # Create directory and link files 46 | sudo mkdir -p "$TEXMF_DIR/tex/latex/html/" 47 | sudo ln -sf /usr/share/texmf/tex/latex/html/html.sty "$TEXMF_DIR/tex/latex/html/html.sty" 48 | sudo ln -sf /usr/share/texmf/tex/latex/html/hthtml.sty "$TEXMF_DIR/tex/latex/html/hthtml.sty" 49 | 50 | # Refresh TeX database 51 | sudo mktexlsr 52 | 53 | # Verify it worked 54 | kpsewhich html.sty || echo "html.sty still not found" 55 | 56 | - name: Extract versions from TeX files 57 | id: get_versions 58 | run: | 59 | CFITSIO_VERSION=$(grep -oP '{\\Large Version \K[^\\\\}]*' docs/cfitsio.tex | sed -e 's/[ \t]*//g') 60 | echo "Found cfitsio version: $CFITSIO_VERSION" 61 | echo "cfitsio_version=$CFITSIO_VERSION" >> $GITHUB_OUTPUT 62 | 63 | FITSIO_VERSION=$(grep -oP '{\\Large Version \K[^\\\\}]*' docs/fitsio.tex | sed -e 's/[ \t]*//g') 64 | echo "Found fitsio version: $FITSIO_VERSION" 65 | echo "fitsio_version=$FITSIO_VERSION" >> $GITHUB_OUTPUT 66 | 67 | - name: Build all PDFs 68 | run: | 69 | cd docs 70 | echo "Building cfitsio.tex..." 71 | pdflatex cfitsio.tex 72 | pdflatex cfitsio.tex # Run twice for references 73 | 74 | echo "Building fitsio.tex..." 75 | pdflatex fitsio.tex 76 | pdflatex fitsio.tex # Run twice for references 77 | 78 | echo "Building quick.tex..." 79 | pdflatex quick.tex 80 | pdflatex quick.tex # Run twice for references 81 | 82 | echo "Building fpackguide.md..." 83 | pandoc fpackguide.md -V linkcolor=blue -o fpackguide.pdf 84 | 85 | 86 | # Rename with version numbers 87 | - name: Rename PDFs with versions 88 | run: | 89 | cd docs 90 | mv cfitsio.pdf cfitsio-v${{ steps.get_versions.outputs.cfitsio_version }}.pdf 91 | mv fitsio.pdf fitsio-v${{ steps.get_versions.outputs.fitsio_version }}.pdf 92 | echo "Created PDFs:" 93 | ls -la *.pdf 94 | 95 | # save the artifacts to the Workflow output 96 | - name: Upload Artifacts 97 | uses: actions/upload-artifact@v4 98 | with: 99 | name: documentation-output 100 | path: | 101 | docs/*.pdf 102 | 103 | # add to any Release created 104 | - name: Upload PDF to release 105 | if: github.event_name == 'release' 106 | run: | 107 | gh release upload ${{ github.ref_name }} \ 108 | docs/cfitsio-v${{ steps.get_versions.outputs.cfitsio_version }}.pdf \ 109 | docs/fitsio-v${{ steps.get_versions.outputs.fitsio_version }}.pdf \ 110 | docs/quick.pdf \ 111 | docs/fpackguide.pdf 112 | env: 113 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /m4/ltsugar.m4: -------------------------------------------------------------------------------- 1 | # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004-2005, 2007-2008, 2011-2019, 2021-2024 Free Software 4 | # Foundation, Inc. 5 | # Written by Gary V. Vaughan, 2004 6 | # 7 | # This file is free software; the Free Software Foundation gives 8 | # unlimited permission to copy and/or distribute it, with or without 9 | # modifications, as long as this notice is preserved. 10 | 11 | # serial 6 ltsugar.m4 12 | 13 | # This is to help aclocal find these macros, as it can't see m4_define. 14 | AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) 15 | 16 | 17 | # lt_join(SEP, ARG1, [ARG2...]) 18 | # ----------------------------- 19 | # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their 20 | # associated separator. 21 | # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier 22 | # versions in m4sugar had bugs. 23 | m4_define([lt_join], 24 | [m4_if([$#], [1], [], 25 | [$#], [2], [[$2]], 26 | [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) 27 | m4_define([_lt_join], 28 | [m4_if([$#$2], [2], [], 29 | [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) 30 | 31 | 32 | # lt_car(LIST) 33 | # lt_cdr(LIST) 34 | # ------------ 35 | # Manipulate m4 lists. 36 | # These macros are necessary as long as will still need to support 37 | # Autoconf-2.59, which quotes differently. 38 | m4_define([lt_car], [[$1]]) 39 | m4_define([lt_cdr], 40 | [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], 41 | [$#], 1, [], 42 | [m4_dquote(m4_shift($@))])]) 43 | m4_define([lt_unquote], $1) 44 | 45 | 46 | # lt_append(MACRO-NAME, STRING, [SEPARATOR]) 47 | # ------------------------------------------ 48 | # Redefine MACRO-NAME to hold its former content plus 'SEPARATOR''STRING'. 49 | # Note that neither SEPARATOR nor STRING are expanded; they are appended 50 | # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). 51 | # No SEPARATOR is output if MACRO-NAME was previously undefined (different 52 | # than defined and empty). 53 | # 54 | # This macro is needed until we can rely on Autoconf 2.62, since earlier 55 | # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. 56 | m4_define([lt_append], 57 | [m4_define([$1], 58 | m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) 59 | 60 | 61 | 62 | # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) 63 | # ---------------------------------------------------------- 64 | # Produce a SEP delimited list of all paired combinations of elements of 65 | # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list 66 | # has the form PREFIXmINFIXSUFFIXn. 67 | # Needed until we can rely on m4_combine added in Autoconf 2.62. 68 | m4_define([lt_combine], 69 | [m4_if(m4_eval([$# > 3]), [1], 70 | [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl 71 | [[m4_foreach([_Lt_prefix], [$2], 72 | [m4_foreach([_Lt_suffix], 73 | ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, 74 | [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) 75 | 76 | 77 | # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) 78 | # ----------------------------------------------------------------------- 79 | # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited 80 | # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. 81 | m4_define([lt_if_append_uniq], 82 | [m4_ifdef([$1], 83 | [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], 84 | [lt_append([$1], [$2], [$3])$4], 85 | [$5])], 86 | [lt_append([$1], [$2], [$3])$4])]) 87 | 88 | 89 | # lt_dict_add(DICT, KEY, VALUE) 90 | # ----------------------------- 91 | m4_define([lt_dict_add], 92 | [m4_define([$1($2)], [$3])]) 93 | 94 | 95 | # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) 96 | # -------------------------------------------- 97 | m4_define([lt_dict_add_subkey], 98 | [m4_define([$1($2:$3)], [$4])]) 99 | 100 | 101 | # lt_dict_fetch(DICT, KEY, [SUBKEY]) 102 | # ---------------------------------- 103 | m4_define([lt_dict_fetch], 104 | [m4_ifval([$3], 105 | m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), 106 | m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) 107 | 108 | 109 | # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) 110 | # ----------------------------------------------------------------- 111 | m4_define([lt_if_dict_fetch], 112 | [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], 113 | [$5], 114 | [$6])]) 115 | 116 | 117 | # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) 118 | # -------------------------------------------------------------- 119 | m4_define([lt_dict_filter], 120 | [m4_if([$5], [], [], 121 | [lt_join(m4_quote(m4_default([$4], [[, ]])), 122 | lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), 123 | [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl 124 | ]) 125 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CFITSIO Interface Library 2 | 3 | CFITSIO is a library of ANSI C routines for reading and writing FITS format data files. A set of Fortran-callable wrapper routines are also included for the convenience of Fortran programmers. This README file gives a brief summary of how to build and test CFITSIO, but the latest and most complete information may be found in the "docs" folder in the CFITSIO User's Guide: 4 | 5 | ### User Guides for C programmers 6 | * `cfitsio.tex` (LaTeX source file) 7 | * `cfitsio.ps` (PostScript file) 8 | * `cfitsio.pdf` (Portable Document Format) 9 | 10 | ### User Guides for Fortran programmers 11 | * `fitsio.tex` (LaTeX source file) 12 | * `fitsio.ps` (PostScript file) 13 | * `fitsio.pdf` (Portable Document Format) 14 | 15 | ### Quick Start Guide 16 | * `quick.tex` (LaTeX source file) 17 | * `quick.ps` (PostScript file) 18 | * `quick.pdf` (Portable Document Format) 19 | 20 | ## Building CFITSIO 21 | 22 | The CFITSIO code (contained in `*.c` source files and several `*.h` header files) should compile and run on most Unix platforms without modification. The standard way to build the library on Unix systems is the usual GNU-like approach, i.e. by first typing 23 | 24 | ```bash 25 | % ./configure [--prefix=/target/installation/path] 26 | ``` 27 | 28 | at the operating system prompt. Type `./configure` and not simply `configure` to ensure that the configure script in the current directory is run and not some other system-wide configure script. The optional `prefix` argument to configure gives the path to the directory where the CFITSIO library and include files should be installed via the later `make install` command. For example, 29 | 30 | ```bash 31 | % ./configure --prefix=/usr1/local 32 | ``` 33 | 34 | will cause the later `make install` command to copy the library file(s) to `/usr1/local/lib` and the necessary header files to `/usr1/local/include` (assuming of course that the process has permission to write to these directories). 35 | 36 | All the available configure options can be seen by entering the command 37 | 38 | ```bash 39 | % ./configure --help 40 | ``` 41 | 42 | The configure command customizes the Makefile for a particular system, so after it has been run, type 43 | 44 | ```bash 45 | % make 46 | ``` 47 | 48 | at the prompt, and this will compile the source files and build the library (static `libcfitsio.a` as well as the shared version `libcfitsio.so|.dylib`) and the helper utilities (`fpack`, `funpack`, `fitscopy`, `imcopy`, et al.) and test program (`testprog`). To copy the library, header files, and utilities to the chosen install location, type this command: 49 | 50 | ```bash 51 | % make install 52 | ``` 53 | 54 | When installing in /usr/local on Linux and some other systems, it may be necessary to rebuild the linker cache by running: 55 | 56 | ```bash 57 | % sudo ldconfig 58 | ``` 59 | 60 | Alternatively, the library and utilities may be built on many systems using the CMake program. Specific instructions for using CMake on Windows platforms can be found in the `README.win` file, but for Unix systems (e.g., Linux or macOS) the procedure should be similar to the following: 61 | 62 | While in the CFITSIO source code directory: 63 | 64 | ```bash 65 | % mkdir cmbuild 66 | % cd cmbuild 67 | % cmake -G "Unix Makefiles" .. 68 | % cmake --build . 69 | % cmake --install . [--prefix /usr/local] 70 | ``` 71 | 72 | Where the final step uses an optional installation prefix. 73 | 74 | Additional options for installing CFITSIO on macOS via third-party package managers or the XCode GUI can be found in the `README.MacOS` file. 75 | 76 | 77 | ## Testing CFITSIO 78 | 79 | The CFITSIO library may be tested by building and running the `testprog.c` program that is included with the release (in the `utilities` folder). On Unix systems, type: 80 | 81 | ```bash 82 | % make testprog 83 | % ./testprog > testprog.lis 84 | % diff testprog.lis testprog.out 85 | % cmp testprog.fit testprog.std 86 | ``` 87 | 88 | The `testprog` program should produce a FITS file called `testprog.fit` that is identical to the `testprog.std` FITS file included in this release. The diagnostic messages (which were piped to the file `testprog.lis` in the Unix example) should be identical to the listing contained in the file `testprog.out`. The `diff` and `cmp` commands shown above should not report any differences in the files. 89 | 90 | ## Using CFITSIO 91 | 92 | The CFITSIO User's Guide, contained in the files mentioned above, provides detailed documentation about how to build and use the CFITSIO library. It contains a description of every user-callable routine in the CFITSIO interface. 93 | 94 | The `cookbook.c` file in the utilities folder provides some sample routines for performing common operations on various types of FITS files. Programmers are urged to examine these routines for recommended programming practices when using CFITSIO. Users are free to copy or modify these routines for their own purposes. 95 | 96 | Any problem reports or suggestions for improvements are welcome and should be sent to the CFITSIO/CCFITS help desk at: 97 | 98 | [ccfits@heasarc.gsfc.nasa.gov](mailto:ccfits@heasarc.gsfc.nasa.gov) 99 | 100 | ------------------------------------------------------------------------- 101 | William D. Pence 102 | HEASARC, NASA/GSFC 103 | -------------------------------------------------------------------------------- /utilities/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.8.2.  */
  2 | 
  3 | /* Bison interface for Yacc-like parsers in C
  4 | 
  5 |    Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 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 YY_ or yy_.  They are
 36 |    private implementation details that can be changed or removed.  */
 37 | 
 38 | #ifndef YY_FITS_PARSER_YY_EVAL_TAB_H_INCLUDED
 39 | # define YY_FITS_PARSER_YY_EVAL_TAB_H_INCLUDED
 40 | /* Debug traces.  */
 41 | #ifndef FITS_PARSER_YYDEBUG
 42 | # if defined YYDEBUG
 43 | #if YYDEBUG
 44 | #   define FITS_PARSER_YYDEBUG 1
 45 | #  else
 46 | #   define FITS_PARSER_YYDEBUG 0
 47 | #  endif
 48 | # else /* ! defined YYDEBUG */
 49 | #  define FITS_PARSER_YYDEBUG 0
 50 | # endif /* ! defined YYDEBUG */
 51 | #endif  /* ! defined FITS_PARSER_YYDEBUG */
 52 | #if FITS_PARSER_YYDEBUG
 53 | extern int fits_parser_yydebug;
 54 | #endif
 55 | 
 56 | /* Token kinds.  */
 57 | #ifndef FITS_PARSER_YYTOKENTYPE
 58 | # define FITS_PARSER_YYTOKENTYPE
 59 |   enum fits_parser_yytokentype
 60 |   {
 61 |     FITS_PARSER_YYEMPTY = -2,
 62 |     FITS_PARSER_YYEOF = 0,         /* "end of file"  */
 63 |     FITS_PARSER_YYerror = 256,     /* error  */
 64 |     FITS_PARSER_YYUNDEF = 257,     /* "invalid token"  */
 65 |     BOOLEAN = 258,                 /* BOOLEAN  */
 66 |     LONG = 259,                    /* LONG  */
 67 |     DOUBLE = 260,                  /* DOUBLE  */
 68 |     STRING = 261,                  /* STRING  */
 69 |     BITSTR = 262,                  /* BITSTR  */
 70 |     FUNCTION = 263,                /* FUNCTION  */
 71 |     BFUNCTION = 264,               /* BFUNCTION  */
 72 |     IFUNCTION = 265,               /* IFUNCTION  */
 73 |     GTIFILTER = 266,               /* GTIFILTER  */
 74 |     GTIOVERLAP = 267,              /* GTIOVERLAP  */
 75 |     GTIFIND = 268,                 /* GTIFIND  */
 76 |     REGFILTER = 269,               /* REGFILTER  */
 77 |     COLUMN = 270,                  /* COLUMN  */
 78 |     BCOLUMN = 271,                 /* BCOLUMN  */
 79 |     SCOLUMN = 272,                 /* SCOLUMN  */
 80 |     BITCOL = 273,                  /* BITCOL  */
 81 |     ROWREF = 274,                  /* ROWREF  */
 82 |     NULLREF = 275,                 /* NULLREF  */
 83 |     SNULLREF = 276,                /* SNULLREF  */
 84 |     OR = 277,                      /* OR  */
 85 |     AND = 278,                     /* AND  */
 86 |     EQ = 279,                      /* EQ  */
 87 |     NE = 280,                      /* NE  */
 88 |     GT = 281,                      /* GT  */
 89 |     LT = 282,                      /* LT  */
 90 |     LTE = 283,                     /* LTE  */
 91 |     GTE = 284,                     /* GTE  */
 92 |     XOR = 285,                     /* XOR  */
 93 |     POWER = 286,                   /* POWER  */
 94 |     NOT = 287,                     /* NOT  */
 95 |     INTCAST = 288,                 /* INTCAST  */
 96 |     FLTCAST = 289,                 /* FLTCAST  */
 97 |     UMINUS = 290,                  /* UMINUS  */
 98 |     ACCUM = 291,                   /* ACCUM  */
 99 |     DIFF = 292                     /* DIFF  */
100 |   };
101 |   typedef enum fits_parser_yytokentype fits_parser_yytoken_kind_t;
102 | #endif
103 | 
104 | /* Value type.  */
105 | #if ! defined FITS_PARSER_YYSTYPE && ! defined FITS_PARSER_YYSTYPE_IS_DECLARED
106 | union FITS_PARSER_YYSTYPE
107 | {
108 | #line 212 "eval.y"
109 | 
110 |     int    Node;        /* Index of Node */
111 |     double dbl;         /* real value    */
112 |     long   lng;         /* integer value */
113 |     char   log;         /* logical value */
114 |     char   str[MAX_STRLEN];    /* string value  */
115 | 
116 | #line 117 "eval_tab.h"
117 | 
118 | };
119 | typedef union FITS_PARSER_YYSTYPE FITS_PARSER_YYSTYPE;
120 | # define FITS_PARSER_YYSTYPE_IS_TRIVIAL 1
121 | # define FITS_PARSER_YYSTYPE_IS_DECLARED 1
122 | #endif
123 | 
124 | 
125 | 
126 | 
127 | int fits_parser_yyparse (yyscan_t scanner, ParseData *lParse);
128 | 
129 | 
130 | #endif /* !YY_FITS_PARSER_YY_EVAL_TAB_H_INCLUDED  */
131 | 


--------------------------------------------------------------------------------
/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 | int main()
 13 | {
 14 |     extern int 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 | 


--------------------------------------------------------------------------------
/Makefile.am:
--------------------------------------------------------------------------------
  1 | ## Process this file with automake to produce Makefile.in
  2 | #
  3 | # CFITSIO Makefile.am
  4 | #
  5 | # Author: B.Irby (NASA/GSFC), based on the previous CFITSIO Makefile.in
  6 | 
  7 | lib_LTLIBRARIES = libcfitsio.la
  8 | 
  9 | # Dummary library to compile single object file with SSE flags
 10 | noinst_LTLIBRARIES = libcfitsio_swapproc.la
 11 | 
 12 | # Shared library version suffixes generated by libtool, used below
 13 | # for symbolic links:
 14 | soname_version = @version_info@
 15 | soname_version_lnx = ${soname_version}.0.0
 16 | 
 17 | include_HEADERS = fitsio.h fitsio2.h longnam.h drvrsmem.h \
 18 | 	cfortran.h f77_wrap.h region.h
 19 | 
 20 | F77_WRAPPERS = f77_wrap1.c f77_wrap2.c f77_wrap3.c f77_wrap4.c
 21 | 
 22 | GSIFTP_SRC = drvrgsiftp.c
 23 | 
 24 | LIBS = @LIBS@
 25 | LIBS_CURL = @LIBS_CURL@
 26 | 
 27 | libcfitsio_la_SOURCES =	\
 28 | 	buffers.c \
 29 | 	cfileio.c \
 30 | 	checksum.c \
 31 | 	drvrfile.c \
 32 | 	drvrmem.c \
 33 | 	drvrnet.c \
 34 | 	drvrsmem.c \
 35 | 	editcol.c \
 36 | 	edithdu.c \
 37 | 	eval_l.c \
 38 | 	eval_y.c \
 39 | 	eval_f.c \
 40 | 	fitscore.c \
 41 | 	getcol.c \
 42 | 	getcolb.c \
 43 | 	getcold.c \
 44 | 	getcole.c \
 45 | 	getcoli.c \
 46 | 	getcolj.c \
 47 | 	getcolk.c \
 48 | 	getcoll.c \
 49 | 	getcols.c \
 50 | 	getcolsb.c \
 51 | 	getcoluk.c \
 52 | 	getcolui.c \
 53 | 	getcoluj.c \
 54 | 	getkey.c \
 55 | 	group.c \
 56 | 	grparser.c \
 57 | 	histo.c \
 58 | 	iraffits.c \
 59 | 	modkey.c \
 60 | 	putcol.c \
 61 | 	putcolb.c \
 62 | 	putcold.c \
 63 | 	putcole.c \
 64 | 	putcoli.c \
 65 | 	putcolj.c \
 66 | 	putcolk.c \
 67 | 	putcoluk.c \
 68 | 	putcoll.c \
 69 | 	putcols.c \
 70 | 	putcolsb.c \
 71 | 	putcolu.c \
 72 | 	putcolui.c \
 73 | 	putcoluj.c \
 74 | 	putkey.c \
 75 | 	region.c \
 76 | 	scalnull.c \
 77 | 	wcssub.c \
 78 | 	wcsutil.c \
 79 | 	imcompress.c \
 80 | 	quantize.c \
 81 | 	ricecomp.c \
 82 | 	pliocomp.c \
 83 | 	fits_hcompress.c \
 84 | 	fits_hdecompress.c \
 85 | 	simplerng.c \
 86 | 	zcompress.c \
 87 | 	zuncompress.c
 88 | 
 89 | if !NOFORTRAN
 90 | libcfitsio_la_SOURCES += $(F77_WRAPPERS)
 91 | endif
 92 | 
 93 | if !NOGSIFTP
 94 | libcfitsio_la_SOURCES += ${GSIFTP_SRC}
 95 | endif
 96 | 
 97 | libcfitsio_la_CFLAGS = $(AM_CFLAGS) @DEFS@
 98 | libcfitsio_la_LIBADD = -lm ${LIBS_CURL} ${LIBS} libcfitsio_swapproc.la
 99 | libcfitsio_la_LDFLAGS = -version-info @version_info@
100 | 
101 | libcfitsio_swapproc_la_CFLAGS = $(libcfitsio_la_CFLAGS) @SSE_FLAGS@
102 | libcfitsio_swapproc_la_SOURCES = swapproc.c
103 | 
104 | pkgconfigdir = $(libdir)/pkgconfig
105 | pkgconfig_DATA = cfitsio.pc
106 | 
107 | # Add symbolic links for compatibility with older configuration:
108 | install-exec-hook:
109 | 	@cd $(DESTDIR)$(libdir); \
110 | 	if test -f "lib${PACKAGE_NAME}.so.${soname_version_lnx}" -a \
111 | 		! -f lib${PACKAGE_NAME}.so.${soname_version}.${PACKAGE_VERSION}; then \
112 | 	    $(LN_S) lib${PACKAGE_NAME}.so.${soname_version_lnx} \
113 | 		    lib${PACKAGE_NAME}.so.${soname_version}.${PACKAGE_VERSION}; \
114 | 	fi; \
115 | 	if test -f "lib${PACKAGE_NAME}.${soname_version}.dylib" -a \
116 | 		! -f lib${PACKAGE_NAME}.${soname_version}.${PACKAGE_VERSION}.dylib; then \
117 | 	    $(LN_S) lib${PACKAGE_NAME}.${soname_version}.dylib \
118 | 		    lib${PACKAGE_NAME}.${soname_version}.${PACKAGE_VERSION}.dylib; \
119 | 	fi
120 | 
121 | # UTILITIES: =============================================================
122 | 
123 | #SUBDIRS = utilities
124 | 
125 | AUTOMAKE_OPTIONS = subdir-objects
126 | 
127 | bin_PROGRAMS = \
128 | 	cookbook \
129 | 	fitscopy \
130 | 	fitsverify \
131 | 	fpack \
132 | 	funpack \
133 | 	imcopy \
134 | 	smem \
135 | 	speed
136 | 
137 | cookbook_SOURCES = utilities/cookbook.c
138 | 
139 | fitscopy_SOURCES = utilities/fitscopy.c
140 | 
141 | fitsverify_CFLAGS = -DSTANDALONE
142 | fitsverify_SOURCES = utilities/ftverify.c utilities/fvrf_data.c \
143 | 		     utilities/fvrf_file.c utilities/fvrf_head.c \
144 | 		     utilities/fvrf_key.c utilities/fvrf_misc.c
145 | 
146 | fpack_SOURCES = utilities/fpack.c utilities/fpackutil.c
147 | fpack_LDADD = -lm ${LDADD}
148 | 
149 | funpack_SOURCES = utilities/funpack.c utilities/fpackutil.c
150 | funpack_LDADD = -lm ${LDADD}
151 | 
152 | imcopy_SOURCES = utilities/imcopy.c
153 | 
154 | smem_SOURCES = utilities/smem.c
155 | 
156 | speed_SOURCES = utilities/speed.c
157 | 
158 | testprog_SOURCES = utilities/testprog.c
159 | 
160 | LDADD = libcfitsio.la ${LIBS}
161 | 
162 | noinst_PROGRAMS = testprog
163 | 
164 | if !NOFORTRAN
165 | 
166 | noinst_PROGRAMS+= testf77
167 | testf77_SOURCES = utilities/testf77.f
168 | 
169 | endif
170 | 
171 | if BUILD_ITER
172 | 
173 | noinst_PROGRAMS+= iter_image iter_var
174 | iter_image_SOURCES = utilities/iter_image.c
175 | iter_var_SOURCES = utilities/iter_var.c
176 | 
177 | endif
178 | 
179 | # eval: ==================================================================
180 | 
181 | FLEX =		flex
182 | BISON =		bison
183 | 
184 | # Tested with bison 3.8 and flex 2.6.4
185 | eval:		# Rebuild eval_* files from flex/bison source
186 | 		${FLEX} -o eval_l.c eval.l 
187 | 		${BISON} -o eval_y.c --header=eval_tab.h eval.y
188 | 
189 | # Distribution: ==========================================================
190 | 
191 | 
192 | EXTRA_DIST = $(F77_WRAPPERS) ${GSIFTP_SRC} \
193 | 	docs licenses \
194 | 	README.md README.MacOS README.win \
195 | 	cfitsio.pc.cmake cfitsio.pc.in \
196 | 	cfitsio-config.cmake.in cfitsio-config-version.cmake.in \
197 | 	cfitsio.xcodeproj \
198 | 	CMakeLists.txt \
199 | 	eval.l eval.y \
200 | 	iter_a.f iter_a.fit iter_b.f iter_b.fit iter_c.f iter_c.fit \
201 | 	sample.tpl \
202 | 	testf77.out testf77.std \
203 | 	testprog.out testprog.std testprog.tpt
204 | # windumpexts.c
205 | # winDumpExts.mak
206 | 
207 | # clean: =================================================================
208 | 
209 | CLEANFILES = testprog.fit testf77.fit atestfil.fit btestfil.fit y.output
210 | 
211 | # HEASoft packages fitsTcl and POW need a list of all .o files: ==========
212 | 
213 | cfitsioLibObjs:
214 | 	@echo ${libcfitsio_la_SOURCES:.c=.o} ${libcfitsio_swapproc_la_SOURCES:.c=.o}
215 | 


--------------------------------------------------------------------------------
/cfitsio.spec:
--------------------------------------------------------------------------------
  1 | #
  2 | # RPM spec file for package cfitsio
  3 | # (i.e. support to build packages on RedHat systems like openSUSE, Fedora,
  4 | # CentOS, AlmaLinux and others).
  5 | #
  6 | # Typical use is to copy the tar.gz file into the SOURCES directory
  7 | # of the RPM root directory and the spec-file into the SPECS directory,
  8 | # to install with the package manager (zypper, dnf,...) the required
  9 | # packages
 10 | #   zypper install libcurl-devel zlib-devel automake autoconf
 11 | #   cp cfitsio-4.6.2.tar.gz ..../SOURCES
 12 | #   cp cfitsio.spec ..../SPECS
 13 | # and to call rpmbuild:
 14 | #   rpmbuild -ba cfitsio.spec
 15 | # The result will then be available in the RPMS directory of the RPM root.
 16 | #
 17 | # Richard J. Mathar (2025-06-20)
 18 | #
 19 | 
 20 | 
 21 | %define tar_ver 4.6.3
 22 | %define so_ver 10
 23 | Name:           cfitsio
 24 | Version:        4.6.3
 25 | Release:        0
 26 | Summary:        Library for manipulating FITS data files
 27 | License:        ISC
 28 | URL:            https://heasarc.gsfc.nasa.gov/fitsio/
 29 | Source0:        https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/%{name}-%{tar_ver}.tar.gz
 30 | BuildRequires:  gcc-fortran
 31 | BuildRequires:  libcurl-devel
 32 | BuildRequires:  pkgconfig
 33 | BuildRequires:  zlib-devel
 34 | BuildRequires:  automake
 35 | BuildRequires:  autoconf
 36 | BuildRequires:  libtool
 37 | 
 38 | %description
 39 | CFITSIO is a library of C and Fortran subroutines for reading and writing data
 40 | files in FITS (Flexible Image Transport System) data format. CFITSIO provides
 41 | simple high-level routines for reading and writing FITS files that insulate the
 42 | programmer from the internal complexities of the FITS format. CFITSIO also
 43 | provides many advanced features for manipulating and filtering the information
 44 | in FITS files.
 45 | 
 46 | This package contains some FITS image compression and decompression utilities.
 47 | 
 48 | %package devel
 49 | Summary:        Headers required when building programs against cfitsio library
 50 | Requires:       libcfitsio%{so_ver} = %{version}
 51 | Requires:       pkgconfig
 52 | %if 0%{?centos_version} != 700
 53 | Suggests:       cfitsio-devel-doc = %{version}
 54 | %endif
 55 | # libcfitsio-devel was last used in openSUSE 13.1 (version 3.350)
 56 | Provides:       libcfitsio-devel = %{version}
 57 | Obsoletes:      libcfitsio-devel <= 3.350
 58 | 
 59 | %description devel
 60 | This package contains headers required when building programs against cfitsio
 61 | library.
 62 | 
 63 | %package devel-doc
 64 | Summary:        Documentation for the cfitsio library
 65 | # libcfitsio-doc was last used in openSUSE 12.1 (version 3.280)
 66 | Obsoletes:      libcfitsio-doc <= 3.280
 67 | # libcfitsio-devel-doc was last used in openSUSE 13.1 (version 3.350)
 68 | Provides:       libcfitsio-devel-doc = %{version}
 69 | Obsoletes:      libcfitsio-devel-doc <= 3.350
 70 | 
 71 | %description devel-doc
 72 | This package contains documentation for the cfitsio library.
 73 | 
 74 | %package -n libcfitsio%{so_ver}
 75 | Summary:        Library for manipulating FITS data files
 76 | 
 77 | %description -n libcfitsio%{so_ver}
 78 | CFITSIO is a library of C and Fortran subroutines for reading and writing data
 79 | files in FITS (Flexible Image Transport System) data format. CFITSIO provides
 80 | simple high-level routines for reading and writing FITS files that insulate the
 81 | programmer from the internal complexities of the FITS format. CFITSIO also
 82 | provides many advanced features for manipulating and filtering the information
 83 | in FITS files.
 84 | 
 85 | %prep
 86 | %setup -q -n %{name}-%{tar_ver}
 87 | 
 88 | %build
 89 | # lines below contain fixes for pkgconfig file bnc#546004, some of them are already fixed by upstream
 90 | # so please drop them if they are not needed (in next round of updates)
 91 | # Add include dir, multithreading support, zlib dependency
 92 | sed -i 's|Cflags: -I${includedir}|Cflags: -D_REENTRANT -I${includedir} -I${includedir}/%{name}|' cfitsio.pc.in
 93 | sed -i 's|@LIBS@ -lm|@LIBS@ -lz -lm|' cfitsio.pc.in
 94 | # fixes complaints of fedora 35 opensuse build service: avoid -Wl,rpath flags
 95 | sed -i 's|-Wl,-rpath,|-L|' configure.ac
 96 | sed -i 's|@rpath/||' configure.ac
 97 | autoreconf -i -f -s
 98 | 
 99 | 
100 | %configure --enable-reentrant --docdir=%{_docdir}/%{name} --includedir=%{_includedir}/%{name}
101 | 
102 | %{make_build}
103 | make fpack %{?_smp_mflags}
104 | make funpack %{?_smp_mflags}
105 | 
106 | %check
107 | # testsuite
108 | # On openSUSE 15.6 this fails with an error concerning invalid libc.so.6
109 | # ELF headers; try to recover by piping everything through the colon command
110 | make testprog %{?_smp_mflags}
111 | LD_LIBRARY_PATH=. ./testprog > testprog.lis || :
112 | diff testprog.lis testprog.out || :
113 | cmp testprog.fit testprog.std || :
114 | 
115 | %install
116 | mkdir -p %{buildroot}%{_licensedir}/%{name}
117 | mkdir -p %{buildroot}%{_docdir}/%{name}
118 | make DESTDIR=%{buildroot} CFITSIO_INCLUDE=%{buildroot}%{_includedir}/%{name} install
119 | install licenses/License.txt %{buildroot}%{_licensedir}/cfitsio
120 | install -t %{buildroot}%{_docdir}/cfitsio docs/*.pdf docs/*.doc
121 | 
122 | # Remove static libraries
123 | rm -f %{buildroot}%{_libdir}/libcfitsio.a
124 | # do not distribute libtool files
125 | rm %{buildroot}/%{_libdir}/libcfitsio.la
126 | # do not distribute cookbook and speed (too ambiguous names)
127 | rm %{buildroot}%{_bindir}/{cookbook,speed,smem}
128 | 
129 | %post -n libcfitsio%{so_ver} -p /sbin/ldconfig
130 | %postun -n libcfitsio%{so_ver} -p /sbin/ldconfig
131 | 
132 | %files
133 | %doc %{_docdir}/cfitsio/fpackguide.pdf
134 | %license %{_licensedir}/cfitsio/License.txt
135 | %{_bindir}/fpack
136 | %{_bindir}/funpack
137 | %{_bindir}/fitscopy
138 | %{_bindir}/fitsverify
139 | %{_bindir}/imcopy
140 | 
141 | %files devel
142 | %{_includedir}/%{name}/
143 | %{_libdir}/libcfitsio.so
144 | %{_libdir}/pkgconfig/cfitsio.pc
145 | 
146 | %files devel-doc
147 | %doc %{_docdir}/cfitsio/{cfitsio.pdf,cfortran.doc,fitsio.doc,fitsio.pdf,quick.pdf}
148 | 
149 | %files -n libcfitsio%{so_ver}
150 | %{_libdir}/libcfitsio.so.%{so_ver}*
151 | 
152 | %changelog
153 | 


--------------------------------------------------------------------------------
/m4/ax_cfitsio.m4:
--------------------------------------------------------------------------------
  1 | # ===========================================================================
  2 | #        https://www.gnu.org/software/autoconf-archive/ax_cfitsio.html
  3 | # ===========================================================================
  4 | #
  5 | # SYNOPSIS
  6 | #
  7 | #   AX_CFITSIO
  8 | #
  9 | # DESCRIPTION
 10 | #
 11 | #   This macro searches for the headers and libraries of the cfitsio library
 12 | #   of https://heasarc.gsfc.nasa.gov/fitsio/fitsio.html that typically have
 13 | #   been installed with package names like cfitsio-devel or libcfitsio-dev
 14 | #   on Linux operating systems.
 15 | #
 16 | #   If compilation of the test program works, the macro AC_SUBST's the
 17 | #   variables CFITSIO_LDFLAGS -L flags with the library directory,
 18 | #   CFITSIO_LIBS with the -l flag of the library and CFITSIO_CFLAGS with the
 19 | #   -I flag of the include directory.
 20 | #
 21 | #   If the m4-variable CFITSIO_HOME is set, the name of that directory is
 22 | #   given preference in the search order to find the (binary) library and
 23 | #   include directory.
 24 | #
 25 | #   If configure is called with the option --with-cfitsio=, this
 26 | #   directory overrides the standard search directories and /lib and
 27 | #   /include are the only points where cfitsio is searched after. A
 28 | #   further fine-tuning is separately available with the configure options
 29 | #   --with-cfitsio-include= and/or --with-cfitsio-libdir= which
 30 | #   override only the default search list of directories for the
 31 | #   header-files or libraries.
 32 | #
 33 | #   For most compilations one would run separately
 34 | #
 35 | #     AC_CHECK_HEADERS([fitsio.h],[],AC_MSG_WARN([Warning: Could  not find cfitsio header fitsio.h ... ])])
 36 | #
 37 | #   to define (or not to define) HAVE_FITSIO_H; this is not included here.
 38 | #
 39 | # LICENSE
 40 | #
 41 | #   Copyright (c) 2025 Richard J. Mathar 
 42 | #
 43 | #   Copying and distribution of this file, with or without modification, are
 44 | #   permitted in any medium without royalty provided the copyright notice
 45 | #   and this notice are preserved. This file is offered as-is, without any
 46 | #   warranty.
 47 | 
 48 | #serial 5
 49 | 
 50 | AC_DEFUN([AX_CFITSIO],
 51 | [
 52 |    ac_with_cfitsio=no
 53 |    dnl ${build_cpu} is only known if LT_INIT was used...
 54 |    dnl 'uname -i' returns unknown on Fedora, even if it is x86_64
 55 |    AC_CANONICAL_HOST
 56 |    if test $host_cpu = "x86_64"; then
 57 |       ac_search_lib_path="$CFITSIO_HOME/lib64 $CFITSIO_HOME/lib /usr/lib64 /usr/lib/x86_64-linux-gnu /usr/local/lib64 /opt/lib64 /opt/local/lib64 /usr/lib"
 58 |    else
 59 |       ac_search_lib_path="$CFITSIO_HOME/lib /usr/lib /usr/local/lib /opt/opencv/lib /opt/local/lib /usr/lib/i386-linux-gnu /usr/lib64"
 60 |    fi
 61 |    ac_search_include_path="$CFITSIO_HOME/include /usr/include/cfitsio/ /usr/include  /usr/local/include /opt/include"
 62 | 
 63 |    AC_ARG_WITH(cfitsio,
 64 |       [AS_HELP_STRING([--with-cfitsio=DIR], [root directory of cfitsio installation])],
 65 |       ac_with_cfitsio=$withval
 66 |       if test "x${ac_with_cfitsio}" != xyes && test "x${ac_with_cfitsio}" != xno; then
 67 |            ac_cfitsio_include="$withval/include"
 68 |            ac_cfitsio_libdir="$withval/lib"
 69 |       fi
 70 |    )
 71 | 
 72 |    AC_ARG_WITH([cfitsio-include],
 73 |       [AS_HELP_STRING([--with-cfitsio-include=DIR], [cfitsio header files are in DIR])],
 74 |       ac_with_cfitsio=$withval
 75 |       if test "x${ac_with_cfitsio}" != xyes && test "x${ac_with_cfitsio}" != xno; then
 76 |            ac_cfitsio_include="$withval"
 77 |       fi
 78 |    )
 79 | 
 80 |    AC_ARG_WITH([cfitsio-libdir],
 81 |       [AS_HELP_STRING([--with-cfitsio-libdir=DIR], [The cfitsio library is in DIR])],
 82 |       ac_with_cfitsio=$withval
 83 |       if test "x${ac_with_cfitsio}" != xyes && test "x${ac_with_cfitsio}" != xno; then
 84 |            ac_cfitsio_libdir="$withval"
 85 |       fi
 86 |    )
 87 | 
 88 |    if test "x${ac_cfitsio_libdir}" == "x"; then
 89 |       for ac_search_lib_test in $ac_search_lib_path; do
 90 |          if test -r "$ac_search_lib_test"; then
 91 |             ls $ac_search_lib_test/libcfitsio*  >/dev/null 2>&1
 92 |             if test $? -eq 0; then
 93 |                ac_cfitsio_libdir="$ac_search_lib_test/"
 94 |                break;
 95 |             fi
 96 |          fi
 97 |       done
 98 |    fi
 99 | 
100 |    if test "x${ac_cfitsio_include}" == "x"; then
101 |      for ac_search_include_test in $ac_search_include_path ; do
102 |         if test -r "$ac_search_include_test/fitsio.h"; then
103 |            ac_cfitsio_include="$ac_search_include_test"
104 |            break;
105 |         fi
106 |      done
107 |    fi
108 | 
109 |    AX_CFITSIO_LOCAL($ac_cfitsio_libdir, $ac_cfitsio_include)
110 | ])
111 | 
112 | 
113 | dnl Subfunction which intermediatly sets the LDFLAGS and CXXFLAGS
114 | dnl to the search paths found above, tries to compile-link a trivial
115 | dnl program that uses the standard fitsio.h, and results in
116 | dnl either failure or success of the entire search. The LDFLAGS
117 | dnl and CXXFLAGS are restored to the content they had before the
118 | dnl macro call.
119 | AC_DEFUN([AX_CFITSIO_LOCAL],
120 | [
121 |    AC_REQUIRE([AX_SAVE_FLAGS])
122 |    AC_REQUIRE([AX_RESTORE_FLAGS])
123 | 
124 |    AX_SAVE_FLAGS(cfitsio)
125 | 
126 |    AC_MSG_NOTICE(Check $1 $2)
127 | 
128 |    if test "$1"; then
129 |        LDFLAGS="$LDFLAGS -L$1 -lcfitsio -pthread"
130 |    fi
131 |    if test "$2"; then
132 |        CXXFLAGS="$CXXFLAGS -I$2"
133 |    fi
134 | 
135 |    AC_LANG_PUSH(C)
136 |    AC_MSG_CHECKING(for cfitsio in $1)
137 | 
138 |    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[ ; ]])],[success=yes],[success=no])
139 | 
140 |    AC_MSG_RESULT($success)
141 |    AC_LANG_POP()
142 | 
143 |    AX_RESTORE_FLAGS(cfitsio)
144 | 
145 |    if test "x$success" != xyes; then
146 |        AC_MSG_ERROR(cfitsio not (properly) installed. Get a recent version from: https://heasarc.gsfc.nasa.gov/docs/software/fitsio/ or the linux package manager)
147 |    else
148 |       if test "$1"; then
149 |           AC_SUBST(CFITSIO_LDFLAGS, "-L$1")
150 |           AC_SUBST(CFITSIO_LIBS, "-lcfitsio")
151 |       fi
152 |       if test "$2"; then
153 |           AC_SUBST(CFITSIO_CFLAGS, "-I$2")
154 |       fi
155 |    fi
156 | ])
157 | 


--------------------------------------------------------------------------------
/m4/lt~obsolete.m4:
--------------------------------------------------------------------------------
  1 | # lt~obsolete.m4 -- aclocal satisfying obsolete definitions.    -*-Autoconf-*-
  2 | #
  3 | #   Copyright (C) 2004-2005, 2007, 2009, 2011-2019, 2021-2024 Free
  4 | #   Software Foundation, Inc.
  5 | #   Written by Scott James Remnant, 2004.
  6 | #
  7 | # This file is free software; the Free Software Foundation gives
  8 | # unlimited permission to copy and/or distribute it, with or without
  9 | # modifications, as long as this notice is preserved.
 10 | 
 11 | # serial 5 lt~obsolete.m4
 12 | 
 13 | # These exist entirely to fool aclocal when bootstrapping libtool.
 14 | #
 15 | # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN),
 16 | # which have later been changed to m4_define as they aren't part of the
 17 | # exported API, or moved to Autoconf or Automake where they belong.
 18 | #
 19 | # The trouble is, aclocal is a bit thick.  It'll see the old AC_DEFUN
 20 | # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
 21 | # using a macro with the same name in our local m4/libtool.m4 it'll
 22 | # pull the old libtool.m4 in (it doesn't see our shiny new m4_define
 23 | # and doesn't know about Autoconf macros at all.)
 24 | #
 25 | # So we provide this file, which has a silly filename so it's always
 26 | # included after everything else.  This provides aclocal with the
 27 | # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
 28 | # because those macros already exist, or will be overwritten later.
 29 | # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6.
 30 | #
 31 | # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
 32 | # Yes, that means every name once taken will need to remain here until
 33 | # we give up compatibility with versions before 1.7, at which point
 34 | # we need to keep only those names which we still refer to.
 35 | 
 36 | # This is to help aclocal find these macros, as it can't see m4_define.
 37 | AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
 38 | 
 39 | m4_ifndef([AC_LIBTOOL_LINKER_OPTION],	[AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
 40 | m4_ifndef([AC_PROG_EGREP],		[AC_DEFUN([AC_PROG_EGREP])])
 41 | m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH],	[AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
 42 | m4_ifndef([_LT_AC_SHELL_INIT],		[AC_DEFUN([_LT_AC_SHELL_INIT])])
 43 | m4_ifndef([_LT_AC_SYS_LIBPATH_AIX],	[AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
 44 | m4_ifndef([_LT_PROG_LTMAIN],		[AC_DEFUN([_LT_PROG_LTMAIN])])
 45 | m4_ifndef([_LT_AC_TAGVAR],		[AC_DEFUN([_LT_AC_TAGVAR])])
 46 | m4_ifndef([AC_LTDL_ENABLE_INSTALL],	[AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
 47 | m4_ifndef([AC_LTDL_PREOPEN],		[AC_DEFUN([AC_LTDL_PREOPEN])])
 48 | m4_ifndef([_LT_AC_SYS_COMPILER],	[AC_DEFUN([_LT_AC_SYS_COMPILER])])
 49 | m4_ifndef([_LT_AC_LOCK],		[AC_DEFUN([_LT_AC_LOCK])])
 50 | m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE],	[AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
 51 | m4_ifndef([_LT_AC_TRY_DLOPEN_SELF],	[AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
 52 | m4_ifndef([AC_LIBTOOL_PROG_CC_C_O],	[AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
 53 | m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
 54 | m4_ifndef([AC_LIBTOOL_OBJDIR],		[AC_DEFUN([AC_LIBTOOL_OBJDIR])])
 55 | m4_ifndef([AC_LTDL_OBJDIR],		[AC_DEFUN([AC_LTDL_OBJDIR])])
 56 | m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
 57 | m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP],	[AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
 58 | m4_ifndef([AC_PATH_MAGIC],		[AC_DEFUN([AC_PATH_MAGIC])])
 59 | m4_ifndef([AC_PROG_LD_GNU],		[AC_DEFUN([AC_PROG_LD_GNU])])
 60 | m4_ifndef([AC_PROG_LD_RELOAD_FLAG],	[AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
 61 | m4_ifndef([AC_DEPLIBS_CHECK_METHOD],	[AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
 62 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
 63 | m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
 64 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
 65 | m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS],	[AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
 66 | m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP],	[AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
 67 | m4_ifndef([LT_AC_PROG_EGREP],		[AC_DEFUN([LT_AC_PROG_EGREP])])
 68 | m4_ifndef([LT_AC_PROG_SED],		[AC_DEFUN([LT_AC_PROG_SED])])
 69 | m4_ifndef([_LT_CC_BASENAME],		[AC_DEFUN([_LT_CC_BASENAME])])
 70 | m4_ifndef([_LT_COMPILER_BOILERPLATE],	[AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
 71 | m4_ifndef([_LT_LINKER_BOILERPLATE],	[AC_DEFUN([_LT_LINKER_BOILERPLATE])])
 72 | m4_ifndef([_AC_PROG_LIBTOOL],		[AC_DEFUN([_AC_PROG_LIBTOOL])])
 73 | m4_ifndef([AC_LIBTOOL_SETUP],		[AC_DEFUN([AC_LIBTOOL_SETUP])])
 74 | m4_ifndef([_LT_AC_CHECK_DLFCN],		[AC_DEFUN([_LT_AC_CHECK_DLFCN])])
 75 | m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER],	[AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])])
 76 | m4_ifndef([_LT_AC_TAGCONFIG],		[AC_DEFUN([_LT_AC_TAGCONFIG])])
 77 | m4_ifndef([AC_DISABLE_FAST_INSTALL],	[AC_DEFUN([AC_DISABLE_FAST_INSTALL])])
 78 | m4_ifndef([_LT_AC_LANG_CXX],		[AC_DEFUN([_LT_AC_LANG_CXX])])
 79 | m4_ifndef([_LT_AC_LANG_F77],		[AC_DEFUN([_LT_AC_LANG_F77])])
 80 | m4_ifndef([_LT_AC_LANG_GCJ],		[AC_DEFUN([_LT_AC_LANG_GCJ])])
 81 | m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])])
 82 | m4_ifndef([_LT_AC_LANG_C_CONFIG],	[AC_DEFUN([_LT_AC_LANG_C_CONFIG])])
 83 | m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])])
 84 | m4_ifndef([_LT_AC_LANG_CXX_CONFIG],	[AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])])
 85 | m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])])
 86 | m4_ifndef([_LT_AC_LANG_F77_CONFIG],	[AC_DEFUN([_LT_AC_LANG_F77_CONFIG])])
 87 | m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])])
 88 | m4_ifndef([_LT_AC_LANG_GCJ_CONFIG],	[AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])])
 89 | m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])])
 90 | m4_ifndef([_LT_AC_LANG_RC_CONFIG],	[AC_DEFUN([_LT_AC_LANG_RC_CONFIG])])
 91 | m4_ifndef([AC_LIBTOOL_CONFIG],		[AC_DEFUN([AC_LIBTOOL_CONFIG])])
 92 | m4_ifndef([_LT_AC_FILE_LTDLL_C],	[AC_DEFUN([_LT_AC_FILE_LTDLL_C])])
 93 | m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS],	[AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])])
 94 | m4_ifndef([_LT_AC_PROG_CXXCPP],		[AC_DEFUN([_LT_AC_PROG_CXXCPP])])
 95 | m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS],	[AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])])
 96 | m4_ifndef([_LT_PROG_ECHO_BACKSLASH],	[AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])])
 97 | m4_ifndef([_LT_PROG_F77],		[AC_DEFUN([_LT_PROG_F77])])
 98 | m4_ifndef([_LT_PROG_FC],		[AC_DEFUN([_LT_PROG_FC])])
 99 | m4_ifndef([_LT_PROG_CXX],		[AC_DEFUN([_LT_PROG_CXX])])
100 | 


--------------------------------------------------------------------------------
/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 | int main()
 26 | {
 27 |     extern int 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 |     int 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 | 


--------------------------------------------------------------------------------
/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 | /* An opaque pointer. */
 22 | #ifndef YY_TYPEDEF_YY_SCANNER_T
 23 | #define YY_TYPEDEF_YY_SCANNER_T
 24 | typedef void* yyscan_t;
 25 | #endif
 26 | #ifndef FFBISON
 27 | #include "eval_tab.h"
 28 | #endif
 29 | 
 30 | 
 31 | typedef struct {
 32 |                   char   name[MAXVARNAME+1];
 33 |                   int    type;
 34 |                   long   nelem;
 35 |                   int    naxis;
 36 |                   long   naxes[MAXDIMS];
 37 |                   char   *undef;
 38 |                   void   *data;
 39 |                                 } DataInfo;
 40 | 
 41 | typedef struct {
 42 |                   long   nelem;
 43 |                   int    naxis;
 44 |                   long   naxes[MAXDIMS];
 45 |                   char   *undef;
 46 |                   union {
 47 |                          double dbl;
 48 |                          long   lng;
 49 |                          char   log;
 50 |                          char   str[MAX_STRLEN];
 51 |                          double *dblptr;
 52 |                          long   *lngptr;
 53 |                          char   *logptr;
 54 |                          char   **strptr;
 55 |                          void   *ptr;
 56 | 		  } data;
 57 |                                 } lval;
 58 | 
 59 | typedef struct Node {
 60 |                   int    operation;
 61 |   		  void   (*DoOp)(ParseData *, struct Node *this);
 62 |                   int    nSubNodes;
 63 |                   int    SubNodes[MAXSUBS];
 64 |                   int    type;
 65 |                   lval   value;
 66 |                                 } Node;
 67 | 
 68 | struct ParseData_struct {
 69 |                   fitsfile    *def_fptr;
 70 |   		  int         (*getData)( ParseData *, char *dataName, void *dataValue );
 71 |   		  int         (*loadData)( ParseData *, int varNum, long fRow, long nRows,
 72 | 					   void *data, char *undef );
 73 | 
 74 |                   int         compressed;
 75 |                   int         timeCol;
 76 |                   int         parCol;
 77 |                   int         valCol;
 78 | 
 79 |                   char        *expr;
 80 |                   int         index;
 81 |                   int         is_eobuf;
 82 | 
 83 |                   Node        *Nodes;
 84 |                   int         nNodes;
 85 |                   int         nNodesAlloc;
 86 |                   int         resultNode;
 87 |                   
 88 |                   long        firstRow;
 89 |                   long        nRows;
 90 | 
 91 |                   int         nCols;
 92 |                   long 	      nElements;
 93 |                   int         nAxis;
 94 |                   long        nAxes[MAXDIMS];
 95 |                   iteratorCol *colData;
 96 |                   DataInfo    *varData;
 97 |                   PixelFilter *pixFilter;
 98 | 
 99 |                   long        firstDataRow;
100 |                   long        nDataRows;
101 |                   long        totalRows;
102 |                   long        nPrevDataRows;
103 | 
104 |                   int         datatype;
105 |                   int         hdutype;
106 | 
107 |                   int         status;
108 | };
109 | 
110 | typedef enum {
111 |                   rnd_fct = 1001,
112 |                   sum_fct,
113 |                   nelem_fct,
114 |                   sin_fct,
115 |                   cos_fct,
116 |                   tan_fct,
117 |                   asin_fct,
118 |                   acos_fct,
119 |                   atan_fct,
120 |                   sinh_fct,
121 |                   cosh_fct,
122 |                   tanh_fct,
123 |                   exp_fct,
124 |                   log_fct,
125 |                   log10_fct,
126 |                   sqrt_fct,
127 |                   abs_fct,
128 |                   atan2_fct,
129 |                   ceil_fct,
130 |                   floor_fct,
131 |                   round_fct,
132 | 		  min1_fct,
133 | 		  min2_fct,
134 | 		  max1_fct,
135 | 		  max2_fct,
136 |                   near_fct,
137 |                   circle_fct,
138 |                   box_fct,
139 |                   elps_fct,
140 |                   isnull_fct,
141 |                   defnull_fct,
142 |                   gtifilt_fct,
143 |                   regfilt_fct,
144 |                   ifthenelse_fct,
145 |                   row_fct,
146 |                   null_fct,
147 | 		  median_fct,
148 | 		  average_fct,
149 | 		  stddev_fct,
150 | 		  nonnull_fct,
151 | 		  angsep_fct,
152 | 		  gasrnd_fct,
153 | 		  poirnd_fct,
154 | 		  strmid_fct,
155 | 		  strpos_fct,
156 | 		  setnull_fct,
157 | 		  gtiover_fct,
158 | 		  gtifind_fct,
159 | 		  elemnum_fct,
160 | 		  axiselem_fct,
161 | 		  array_fct
162 |                                 } funcOp;
163 | 
164 | 
165 | typedef struct parseInfo_struct parseInfo;
166 | 
167 | struct ParseStatusVariables { /* These variables were 'static' in fits_parse_workfn() */
168 |   void *Data, *Null;
169 |   int  datasize;
170 |   long lastRow, repeat, resDataSize;
171 |   LONGLONG jnull;
172 |   parseInfo *userInfo;
173 |   long zeros[4];
174 | };
175 | 
176 | struct parseInfo_struct {
177 |      int  datatype;   /* Data type to cast parse results into for user       */
178 |      void *dataPtr;   /* Pointer to array of results, NULL if to use iterCol */
179 |      void *nullPtr;   /* Pointer to nulval, use zero if NULL                 */
180 |      long maxRows;    /* Max No. of rows to process, -1=all, 0=1 iteration   */
181 |      int  anyNull;    /* Flag indicating at least 1 undef value encountered  */
182 |      ParseData *parseData; /* Pointer to parser configuration */
183 |      struct ParseStatusVariables parseVariables;
184 | };
185 | 
186 | #ifdef __cplusplus
187 | extern "C" {
188 | #endif
189 | 
190 | /* Not sure why this is needed but it is */
191 | #define YYSTYPE FITS_PARSER_YYSTYPE
192 | /* How ParseData is accessed from the lexer, i.e. by yyextra */
193 | #define YY_EXTRA_TYPE ParseData *
194 | 
195 |    int  fits_parser_yyparse(yyscan_t yyscaner, ParseData *lParse);
196 |    int  fits_parser_yylex(FITS_PARSER_YYSTYPE *, yyscan_t yyscanner);
197 |    void fits_parser_yyrestart(FILE*, yyscan_t yyscanner);
198 |    int  fits_parser_yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner);
199 |    int  fits_parser_yylex_destroy (yyscan_t scanner);
200 | 
201 |    void Evaluate_Parser( ParseData *lParse, long firstRow, long nRows );
202 |    int  fits_parser_allocateCol( ParseData *lParse, int nCol, int *status );
203 |    int fits_parser_set_temporary_col(ParseData *lParse, parseInfo *Info,
204 | 				     long int nrows, void *nulval, int *status);
205 | 
206 | #ifdef __cplusplus
207 |     }
208 | #endif
209 | 


--------------------------------------------------------------------------------
/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 | 


--------------------------------------------------------------------------------
/utilities/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 | 


--------------------------------------------------------------------------------
/utilities/fverify.h:
--------------------------------------------------------------------------------
  1 | #ifndef _FVERIFY_H
  2 | #define _FVERIFY_H
  3 | 
  4 | #include 
  5 | #include 
  6 | #include 
  7 | #include 
  8 | #include 
  9 | #include 
 10 | #include "fitsio.h"
 11 | #define MAXERRORS  200		
 12 | #define MAXWRNS  200		
 13 | 
 14 | static char errmes[256];
 15 | static char comm[FLEN_FILENAME+6];
 16 | extern int prhead;
 17 | extern int testdata;
 18 | extern int testfill;
 19 | extern int testcsum;
 20 | extern int totalhdu;		/* total number of hdu */
 21 | extern int err_report;
 22 | extern int heasarc_conv;
 23 | extern int testhierarch;
 24 | extern int prstat;
 25 | /********************************
 26 | *				*   
 27 | *       Keywords 		*
 28 | *				*   
 29 | ********************************/
 30 | 
 31 | typedef enum  {      STR_KEY,   /* string   key */
 32 | 		     LOG_KEY, 	/* Logical key */
 33 | 		     INT_KEY,	/* Integer key */
 34 | 		     FLT_KEY,   /* Float key   */
 35 | 		     CMI_KEY, 	/* Complex integer key */
 36 | 		     CMF_KEY,	/* Complex float key */
 37 | 		     COM_KEY,	/* history, comment, "  ", and end */
 38 | 		     UNKNOWN	/* Unknown types */
 39 | 		     } kwdtyp;
 40 | /* error number masks of  the keyword test */
 41 | #define 	BAD_STR			0X0001 
 42 | #define		NO_TRAIL_QUOTE		0X0002
 43 | #define		BAD_NUM			0X0004 
 44 | #define		LOWCASE_EXPO		0X0008 
 45 | #define		NO_TRAIL_PAREN		0X0010
 46 | #define		NO_COMMA		0X0020
 47 | #define		TOO_MANY_COMMA		0X0040
 48 | #define		BAD_REAL		0X0080
 49 | #define		BAD_IMG			0X0100
 50 | #define         BAD_LOGICAL		0x0200
 51 | #define         NO_START_SLASH		0X0400
 52 | #define         BAD_COMMENT		0x0800
 53 | #define         UNKNOWN_TYPE		0x1000
 54 | 
 55 | /* Number of possible WCS descriptions to check.*/
 56 | /* 1 for the primary + 26 for [A-Z] suffix. */
 57 | #define NWCSDESCR  27
 58 | 
 59 | /* keyword structure */ 
 60 | typedef struct { 
 61 |     char kname[FLEN_KEYWORD];	/* fits keyword name */
 62 |     kwdtyp ktype;		/* fits keyword type */
 63 |     char kvalue[FLEN_VALUE];	/* fits keyword name */
 64 |     int kindex;			/* position at the header */
 65 |     int goodkey;		/* good keyword flag (=1 good)*/
 66 | }FitsKey;
 67 | int fits_parse_card(FILE *out, int pos, char *card, char *kname, kwdtyp *ktype,
 68 | 		    char *kvalue, char *kcomm);
 69 | void get_str(char **p, char *kvalue, unsigned long *stat);
 70 | void get_log(char **p, char *kvalue, unsigned long *stat);
 71 | void get_num(char **p, char *kvalue, kwdtyp *ktype, unsigned long *stat);
 72 | void get_cmp(char **p, char *kvalue, kwdtyp *ktype, unsigned long *stat);
 73 | int check_str(FitsKey* pkey, FILE *out);
 74 | int check_int(FitsKey* pkey, FILE *out);
 75 | int check_flt(FitsKey* pkey, FILE *out);
 76 | int check_cmi(FitsKey* pkey, FILE *out);
 77 | int check_cmf(FitsKey* pkey, FILE *out);
 78 | int check_log(FitsKey* pkey, FILE *out);
 79 | int check_fixed_int(char *card, FILE *out);
 80 | int check_fixed_log(char *card, FILE *out);
 81 | int check_fixed_str(char *card, FILE *out);
 82 | 
 83 | void get_unknown(char **p, char *kvalue, kwdtyp *ktype, unsigned long *stat);
 84 | void get_comm(char **p, char *kcomm, unsigned long *stat);
 85 | void pr_kval_err(FILE *out, int pos, char *keyname, char *keyval,
 86 |       unsigned long stat);
 87 | 
 88 | /********************************
 89 | *				*   
 90 | *       Headers  		*
 91 | *				*   
 92 | ********************************/
 93 | typedef struct { 
 94 |     int	 hdutype; 		/* hdutype */
 95 |     int	 hdunum; 		/* hdunum  */
 96 |     int  isgroup;		/* random group flag */ 
 97 |     int  istilecompressed;	/* tile compressed image */ 
 98 |     int  gcount;		/* gcount  */
 99 |     LONGLONG  pcount;		/* pcount  */
100 |     int  bitpix;		/* pix number */
101 |     int  naxis;			/* number of the axis,used for image array*/
102 |     LONGLONG *naxes;		/* dimension of each axis,used for image array*/
103 |     int  ncols;			/* number of the columns, used for image only*/ 
104 |     char extname[FLEN_VALUE];		/* EXTENSION NAME */
105 |     int extver;			/* extension version */
106 |     char **datamax;		/* strings for the maximum of the data in a column */
107 |     char **datamin;		/* strings for the minimum of the data in a column */
108 |     char **tnull;	        /* number of NULL values */
109 |     int  nkeys; 		/* number of keys */
110 |     int  tkeys; 		/* total of the keys tested*/
111 |     int  heap;			/* heap */
112 |     FitsKey **kwds;		/* keywords list starting from the 
113 | 				   last NAXISn keyword. The array 
114 | 				   is sorted in the ascending alphabetical 
115 | 				   order of keyword names. The last keyword END 
116 | 				   and commentary keywords are  excluded. 
117 | 				   The total number of element, tkey, is 
118 | 				   nkeys - 4 - naxis - ncomm. */
119 |     int use_longstr;		/* flag indicates that the long string
120 |                                    convention is used */
121 | }FitsHdu;   
122 | 
123 | typedef struct {
124 |      char * name;
125 |      int index;
126 | }ColName;
127 | 
128 | int verify_fits(char *infile, FILE *out);
129 | void leave_early (FILE* out);
130 | void close_err(FILE* out);
131 | void init_hdu(fitsfile *infits, FILE *out, int hdunum, int hdutype,
132 | 	     FitsHdu *hduptr);
133 | void test_hdu(fitsfile *infits, FILE *out, FitsHdu *hduptr);
134 | void test_ext(fitsfile *infits, FILE *out, FitsHdu *hduptr);
135 | void test_tbl(fitsfile *infits, FILE *out, FitsHdu *hduptr);
136 | void test_array(fitsfile *infits, FILE *out, FitsHdu *hduptr);
137 | void test_prm(fitsfile *infits, FILE *out, FitsHdu *hduptr);
138 | void test_img_ext(fitsfile *infits, FILE *out, FitsHdu *hduptr);
139 | void test_asc_ext(fitsfile *infits, FILE *out, FitsHdu *hduptr);
140 | void test_bin_ext(fitsfile *infits, FILE *out, FitsHdu *hduptr);
141 | void test_header(fitsfile *infits, FILE *out, FitsHdu *hduptr);
142 | void key_match(char **strs, int nstr, char **pattern, int exact, 
143 | 	       int *ikey, int *mkey);
144 | void test_colnam(FILE *out, FitsHdu *hduptr);
145 | void parse_vtform(fitsfile *infits, FILE *out, FitsHdu *hduptr, 
146 | 	     int colnum, int *datacode, long *maxlen, int *isQFormat);
147 | int  parse_wcskey_suffix(char *fullname, char* rootname, int* axis, int* alt);
148 | void print_title(FILE* out, int hdunum, int hdutype);
149 | void print_header(FILE* out);
150 | void print_summary(fitsfile *infits, FILE *out, FitsHdu *hduptr);
151 | void close_hdu(FitsHdu *hduptr);
152 | 
153 | 
154 | /********************************
155 | *				*   
156 | *       Data 	  		*
157 | *				*   
158 | ********************************/
159 | 
160 | void test_data(fitsfile *infits, FILE *out, FitsHdu *hduptr);
161 | void test_agap(fitsfile *infits, FILE *out, FitsHdu *hduptr);
162 | void test_checksum(fitsfile *infits, FILE *out);
163 | int iterdata(long totaln, long offset, long firstn, long nrows, 
164 | 	     int narrays, iteratorCol *iter_col, void *usrdata);
165 | /********************************
166 | *				*   
167 | *       Files   		*
168 | *				*   
169 | ********************************/
170 | typedef struct { 
171 |     int	 hdutype; 		/* hdutype */
172 |     int	 hdunum; 		/* hdunum  */
173 |     char extname[FLEN_VALUE];	/* extension name, used for extension*/
174 |     int	 extver; 		/* extension version, used for extension */
175 |     int  errnum;			/* number of errors in this hdu */
176 |     int  wrnno;			/* number of warnning in this hdu */
177 | }HduName;    
178 | int get_total_warn();
179 | int get_total_err();
180 | void init_hduname();
181 | void set_hduname(int hdunum,int hdutype, char* extname,int  extver);
182 | void set_hduerr(int hdunum);
183 | void set_hdubasic(int hdunum,int hdutype);
184 | int test_hduname(int hdunum1, int hdunum2);
185 | void total_errors (int *totalerr, int * totalwrn);
186 | void hdus_summary(FILE *out);
187 | void destroy_hduname();
188 | void test_end(fitsfile *infits, FILE *out);
189 | void init_report(FILE *out, char *rootnam);
190 | void close_report(FILE *out);
191 | void update_parfile(int numerr, int numwrn);
192 | 
193 | 
194 | /********************************
195 | *				*   
196 | *       Miscellaneous	 	*
197 | *				*   
198 | ********************************/
199 | void print_fmt(FILE *out, char *temp, int nprompt);
200 | int wrtout (FILE *out,char *comm);
201 | int wrterr (FILE *out,char *comm, int severity);
202 | int wrtwrn (FILE *out,char *comm, int heasarc);
203 | int wrtferr(FILE *out, char* mess, int *status, int severity);
204 | int wrtserr(FILE *out, char* mess, int *status, int severity);
205 | void wrtsep (FILE *out,char fill, char *title, int nchar);
206 | void num_err_wrn(int *num_err, int *num_wrn);
207 | void reset_err_wrn();
208 | int compkey (const void *key1, const void *key2);
209 | int compcol (const void *col1, const void *col2);
210 | int compcol (const void *col1, const void *col2);
211 | int compstrp (const void *str1, const void *str2);
212 | int compstre (const void *str1, const void *str2);
213 | 
214 | #endif
215 | 


--------------------------------------------------------------------------------
/config/missing:
--------------------------------------------------------------------------------
  1 | #! /bin/sh
  2 | # Common wrapper for a few potentially missing GNU and other programs.
  3 | 
  4 | scriptversion=2024-06-07.14; # UTC
  5 | 
  6 | # shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
  7 | 
  8 | # Copyright (C) 1996-2024 Free Software Foundation, Inc.
  9 | # Originally written by Fran,cois Pinard , 1996.
 10 | 
 11 | # This program is free software; you can redistribute it and/or modify
 12 | # it under the terms of the GNU General Public License as published by
 13 | # the Free Software Foundation; either version 2, or (at your option)
 14 | # any later version.
 15 | 
 16 | # This program is distributed in the hope that it will be useful,
 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 19 | # GNU General Public License for more details.
 20 | 
 21 | # You should have received a copy of the GNU General Public License
 22 | # along with this program.  If not, see .
 23 | 
 24 | # As a special exception to the GNU General Public License, if you
 25 | # distribute this file as part of a program that contains a
 26 | # configuration script generated by Autoconf, you may include it under
 27 | # the same distribution terms that you use for the rest of that program.
 28 | 
 29 | if test $# -eq 0; then
 30 |   echo 1>&2 "Try '$0 --help' for more information"
 31 |   exit 1
 32 | fi
 33 | 
 34 | case $1 in
 35 | 
 36 |   --is-lightweight)
 37 |     # Used by our autoconf macros to check whether the available missing
 38 |     # script is modern enough.
 39 |     exit 0
 40 |     ;;
 41 | 
 42 |   --run)
 43 |     # Back-compat with the calling convention used by older automake.
 44 |     shift
 45 |     ;;
 46 | 
 47 |   -h|--h|--he|--hel|--help)
 48 |     echo "\
 49 | $0 [OPTION]... PROGRAM [ARGUMENT]...
 50 | 
 51 | Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
 52 | to PROGRAM being missing or too old.
 53 | 
 54 | Options:
 55 |   -h, --help      display this help and exit
 56 |   -v, --version   output version information and exit
 57 | 
 58 | Supported PROGRAM values:
 59 | aclocal autoconf autogen  autoheader autom4te automake autoreconf
 60 | bison   flex     help2man lex        makeinfo perl     yacc
 61 | 
 62 | Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
 63 | 'g' are ignored when checking the name.
 64 | 
 65 | Report bugs to .
 66 | GNU Automake home page: .
 67 | General help using GNU software: ."
 68 |     exit $?
 69 |     ;;
 70 | 
 71 |   -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
 72 |     echo "missing (GNU Automake) $scriptversion"
 73 |     exit $?
 74 |     ;;
 75 | 
 76 |   -*)
 77 |     echo 1>&2 "$0: unknown '$1' option"
 78 |     echo 1>&2 "Try '$0 --help' for more information"
 79 |     exit 1
 80 |     ;;
 81 | 
 82 | esac
 83 | 
 84 | # Run the given program, remember its exit status.
 85 | "$@"; st=$?
 86 | 
 87 | # If it succeeded, we are done.
 88 | test $st -eq 0 && exit 0
 89 | 
 90 | # Also exit now if we it failed (or wasn't found), and '--version' was
 91 | # passed; such an option is passed most likely to detect whether the
 92 | # program is present and works.
 93 | case $2 in --version|--help) exit $st;; esac
 94 | 
 95 | # Exit code 63 means version mismatch.  This often happens when the user
 96 | # tries to use an ancient version of a tool on a file that requires a
 97 | # minimum version.
 98 | if test $st -eq 63; then
 99 |   msg="probably too old"
100 | elif test $st -eq 127; then
101 |   # Program was missing.
102 |   msg="missing on your system"
103 | else
104 |   # Program was found and executed, but failed.  Give up.
105 |   exit $st
106 | fi
107 | 
108 | perl_URL=https://www.perl.org/
109 | flex_URL=https://github.com/westes/flex
110 | gnu_software_URL=https://www.gnu.org/software
111 | 
112 | program_details ()
113 | {
114 |   case $1 in
115 |     aclocal|automake|autoreconf)
116 |       echo "The '$1' program is part of the GNU Automake package:"
117 |       echo "<$gnu_software_URL/automake>"
118 |       echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
119 |       echo "<$gnu_software_URL/autoconf>"
120 |       echo "<$gnu_software_URL/m4/>"
121 |       echo "<$perl_URL>"
122 |       ;;
123 |     autoconf|autom4te|autoheader)
124 |       echo "The '$1' program is part of the GNU Autoconf package:"
125 |       echo "<$gnu_software_URL/autoconf/>"
126 |       echo "It also requires GNU m4 and Perl in order to run:"
127 |       echo "<$gnu_software_URL/m4/>"
128 |       echo "<$perl_URL>"
129 |       ;;
130 |     *)
131 |       :
132 |       ;;
133 |   esac
134 | }
135 | 
136 | give_advice ()
137 | {
138 |   # Normalize program name to check for.
139 |   normalized_program=`echo "$1" | sed '
140 |     s/^gnu-//; t
141 |     s/^gnu//; t
142 |     s/^g//; t'`
143 | 
144 |   printf '%s\n' "'$1' is $msg."
145 | 
146 |   configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
147 |   autoheader_deps="'acconfig.h'"
148 |   automake_deps="'Makefile.am'"
149 |   aclocal_deps="'acinclude.m4'"
150 |   case $normalized_program in
151 |     aclocal*)
152 |       echo "You should only need it if you modified $aclocal_deps or"
153 |       echo "$configure_deps."
154 |       ;;
155 |     autoconf*)
156 |       echo "You should only need it if you modified $configure_deps."
157 |       ;;
158 |     autogen*)
159 |       echo "You should only need it if you modified a '.def' or '.tpl' file."
160 |       echo "You may want to install the GNU AutoGen package:"
161 |       echo "<$gnu_software_URL/autogen/>"
162 |       ;;
163 |     autoheader*)
164 |       echo "You should only need it if you modified $autoheader_deps or"
165 |       echo "$configure_deps."
166 |       ;;
167 |     automake*)
168 |       echo "You should only need it if you modified $automake_deps or"
169 |       echo "$configure_deps."
170 |       ;;
171 |     autom4te*)
172 |       echo "You might have modified some maintainer files that require"
173 |       echo "the 'autom4te' program to be rebuilt."
174 |       ;;
175 |     autoreconf*)
176 |       echo "You should only need it if you modified $aclocal_deps or"
177 |       echo "$automake_deps or $autoheader_deps or $automake_deps or"
178 |       echo "$configure_deps."
179 |       ;;
180 |     bison*|yacc*)
181 |       echo "You should only need it if you modified a '.y' file."
182 |       echo "You may want to install the GNU Bison package:"
183 |       echo "<$gnu_software_URL/bison/>"
184 |       ;;
185 |     help2man*)
186 |       echo "You should only need it if you modified a dependency" \
187 |            "of a man page."
188 |       echo "You may want to install the GNU Help2man package:"
189 |       echo "<$gnu_software_URL/help2man/>"
190 |     ;;
191 |     lex*|flex*)
192 |       echo "You should only need it if you modified a '.l' file."
193 |       echo "You may want to install the Fast Lexical Analyzer package:"
194 |       echo "<$flex_URL>"
195 |       ;;
196 |     makeinfo*)
197 |       echo "You should only need it if you modified a '.texi' file, or"
198 |       echo "any other file indirectly affecting the aspect of the manual."
199 |       echo "You might want to install the Texinfo package:"
200 |       echo "<$gnu_software_URL/texinfo/>"
201 |       echo "The spurious makeinfo call might also be the consequence of"
202 |       echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
203 |       echo "want to install GNU make:"
204 |       echo "<$gnu_software_URL/make/>"
205 |       ;;
206 |     perl*)
207 |       echo "You should only need it to run GNU Autoconf, GNU Automake, "
208 |       echo "  assorted other tools, or if you modified a Perl source file."
209 |       echo "You may want to install the Perl 5 language interpreter:"
210 |       echo "<$perl_URL>"
211 |       ;;
212 |     *)
213 |       echo "You might have modified some files without having the proper"
214 |       echo "tools for further handling them.  Check the 'README' file, it"
215 |       echo "often tells you about the needed prerequisites for installing"
216 |       echo "this package.  You may also peek at any GNU archive site, in"
217 |       echo "case some other package contains this missing '$1' program."
218 |       ;;
219 |   esac
220 |   program_details "$normalized_program"
221 | }
222 | 
223 | give_advice "$1" | sed -e '1s/^/WARNING: /' \
224 |                        -e '2,$s/^/         /' >&2
225 | 
226 | # Propagate the correct exit status (expected to be 127 for a program
227 | # not found, 63 for a program that failed due to version mismatch).
228 | exit $st
229 | 
230 | # Local variables:
231 | # eval: (add-hook 'before-save-hook 'time-stamp)
232 | # time-stamp-start: "scriptversion="
233 | # time-stamp-format: "%:y-%02m-%02d.%02H"
234 | # time-stamp-time-zone: "UTC0"
235 | # time-stamp-end: "; # UTC"
236 | # End:
237 | 


--------------------------------------------------------------------------------
/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 | 


--------------------------------------------------------------------------------
/utilities/fvrf_file.c:
--------------------------------------------------------------------------------
  1 | #include "fverify.h"
  2 | static HduName  **hduname; 
  3 | static int total_err=1;  /* initialzed to 1 in case fail to open file */
  4 | static int total_warn=0;
  5 | 
  6 | int get_total_warn()
  7 | {
  8 |     return (total_warn);
  9 | }
 10 | int get_total_err()
 11 | {
 12 |     return (total_err);
 13 | }
 14 | 
 15 | /* Get the total hdu number and allocate the memory for hdu array */  
 16 | void init_hduname() 
 17 | {
 18 |     int i;
 19 |     /* allocate memories for the hdu structure array  */
 20 |     hduname = (HduName **)malloc(totalhdu*sizeof(HduName *));
 21 |     for (i=0; i < totalhdu; i++) { 
 22 | 	hduname[i] = (HduName *)calloc(1, sizeof(HduName));
 23 | 	hduname[i]->hdutype = -1;
 24 |         hduname[i]->errnum = 0; 
 25 |         hduname[i]->wrnno = 0;
 26 |         strcpy(hduname[i]->extname,"");
 27 |         hduname[i]->extver = 0;
 28 |     }
 29 |     return;
 30 | }
 31 | /* set the hduname memeber hdutype, extname, extver */
 32 | void set_hduname(  int hdunum,		/* hdu number */ 
 33 | 		   int hdutype,		/* hdutype */
 34 | 		   char* extname,	/* extension name */
 35 |                    int  extver 		/* extension version */
 36 |                 )
 37 | {
 38 |     int i; 
 39 |     i = hdunum - 1;
 40 |     hduname[i]->hdutype = hdutype;
 41 |     if(extname!=NULL)
 42 |         strcpy (hduname[i]->extname,extname); 
 43 |     else 
 44 |         strcpy(hduname[i]->extname,"");
 45 |     hduname[i]->extver = extver;
 46 |     return;
 47 | } 
 48 | 
 49 | 
 50 | /* get the total errors and total warnings in this hdu */
 51 | void set_hduerr(int hdunum	/* hdu number */ 
 52 |                 )
 53 | {
 54 |     int i; 
 55 |     i = hdunum - 1;
 56 |     num_err_wrn(&(hduname[i]->errnum), &(hduname[i]->wrnno));
 57 |     reset_err_wrn();   /* reset the error and warning counter */
 58 |     return;
 59 | } 
 60 | 
 61 | /* set the basic information for hduname structure */
 62 | void set_hdubasic(int hdunum,int hdutype)
 63 | { 
 64 |    set_hduname(hdunum, hdutype, NULL, 0);
 65 |    set_hduerr(hdunum); 
 66 |    return;
 67 | }
 68 | 
 69 | /* test to see whether the two extension having the same name */
 70 | /* return 1: identical 0: different */
 71 | int test_hduname (int hdunum1,		/* index of first hdu */
 72 | 		  int hdunum2		/* index of second hdu */
 73 |                   )
 74 | { 
 75 |     HduName *p1;
 76 |     HduName *p2; 
 77 | 
 78 |     p1 = hduname[hdunum1-1];
 79 |     p2 = hduname[hdunum2-1];
 80 |     if(!strlen(p1->extname) || !strlen(p2->extname)) return 0;
 81 |     if(!strcmp(p1->extname,p2->extname) && p1->hdutype == p2->hdutype
 82 |        && p2->extver == p1->extver && hdunum1 != hdunum2){ 
 83 | 	   return 1;
 84 |     } 
 85 |     return 0;
 86 | } 
 87 | 
 88 | /* Added the error numbers */
 89 | void total_errors (int *toterr, int * totwrn)  
 90 | {    
 91 |    int i = 0;
 92 |    int ierr, iwrn;
 93 |    *toterr = 0;
 94 |    *totwrn = 0;
 95 | 
 96 |    if (totalhdu == 0) { /* this means the file couldn't be opened */
 97 |        *toterr = 1;
 98 |        return;
 99 |    }
100 | 
101 |    for (i = 0; i < totalhdu; i++) { 
102 |        *toterr += hduname[i]->errnum; 
103 |        *totwrn += hduname[i]->wrnno;
104 |    } 
105 |    /*check the end of file errors */
106 |    num_err_wrn(&ierr, &iwrn); 
107 |    *toterr +=ierr; 
108 |    *totwrn +=iwrn; 
109 |    return;
110 | }
111 |     
112 | /* print the extname, exttype, extver, errnum and wrnno in a  table */ 
113 | void hdus_summary(FILE *out)
114 | {
115 |    HduName *p;
116 |    int i;
117 |    int ierr, iwrn;
118 |    char temp[FLEN_VALUE];
119 |    char temp1[FLEN_VALUE];
120 | 
121 |    wrtsep(out,'+'," Error Summary  ",60);
122 |    wrtout(out," ");
123 |    sprintf(comm," HDU#  Name (version)       Type             Warnings  Errors");
124 |    wrtout(out,comm);
125 | 
126 |    sprintf(comm," 1                          Primary Array    %-4d      %-4d  ", 
127 | 	   hduname[0]->wrnno,hduname[0]->errnum); 
128 |    wrtout(out,comm);
129 |    for (i=2; i <= totalhdu; i++) { 
130 |        p = hduname[i-1];
131 |        strcpy(temp,p->extname);
132 |        if(p->extver && p->extver!= -999) { 
133 |            sprintf(temp1," (%-d)",p->extver);
134 |            strcat(temp,temp1);
135 |        }
136 |        switch(hduname[i-1]->hdutype){ 
137 | 	   case IMAGE_HDU: 
138 |                sprintf(comm," %-5d %-20s Image Array      %-4d      %-4d  ", 
139 | 	               i,temp, p->wrnno,p->errnum); 
140 |                wrtout(out,comm); 
141 | 	       break;
142 | 	   case ASCII_TBL: 
143 |                sprintf(comm," %-5d %-20s ASCII Table      %-4d      %-4d  ", 
144 | 	               i,temp, p->wrnno,p->errnum); 
145 |                wrtout(out,comm); 
146 | 	       break;
147 | 	   case BINARY_TBL: 
148 |                sprintf(comm," %-5d %-20s Binary Table     %-4d      %-4d  ", 
149 | 	               i,temp, p->wrnno,p->errnum); 
150 |                wrtout(out,comm); 
151 | 	       break;
152 |            default:
153 |                sprintf(comm," %-5d %-20s Unknown HDU      %-4d      %-4d  ", 
154 | 	               i,temp, p->wrnno,p->errnum); 
155 |                wrtout(out,comm); 
156 | 	       break; 
157 |       }
158 |    } 
159 |    /* check the end of file */ 
160 |    num_err_wrn(&ierr, &iwrn); 
161 |    if (iwrn || ierr) {
162 |      sprintf(comm," End-of-file %-30s  %-4d      %-4d  ", "", iwrn,ierr); 
163 |      wrtout(out,comm); 
164 |    }
165 |    wrtout(out," ");
166 |    return;
167 | }
168 | 
169 | 		   
170 | 
171 | void destroy_hduname() 
172 | { 
173 |    int i;
174 |    for (i=0; i < totalhdu; i++) free(hduname[i]);
175 |    free(hduname);
176 |    return;
177 | } 
178 | 
179 | /* Routine to test the extra bytes at the end of file */ 
180 |    void  test_end(fitsfile *infits, 
181 | 		  FILE *out) 
182 | 
183 | {   
184 |    int status = 0; 
185 |    LONGLONG headstart, datastart, dataend;
186 |    int hdutype;
187 | 
188 |    /* check whether there are any HDU left */ 
189 |    fits_movrel_hdu(infits,1, &hdutype, &status);
190 |    if (!status) {
191 |        wrtout(out,"< End-of-File >");
192 |        sprintf(errmes, 
193 |     "There are extraneous HDU(s) beyond the end of last HDU.");
194 |        wrterr(out,errmes,2);
195 |        wrtout(out," ");
196 |        return;
197 |    }
198 | 
199 |    if (status != END_OF_FILE) { 
200 |       wrtserr(out,"Bad HDU? ",&status,2);
201 |       return;
202 |    } 
203 | 
204 |    status = 0;  
205 |    fits_clear_errmsg();
206 |    if(ffghadll(infits, &headstart, &datastart, &dataend, &status)) 
207 |        wrtferr(out, "",&status,1);
208 | 
209 |    /* try to move to the last byte of this extension.  */
210 |    if (ffmbyt(infits, dataend - 1,0,&status))
211 |    {
212 |        sprintf(errmes, 
213 |    "Error trying to read last byte of the file at byte %ld.", (long) dataend);
214 |        wrterr(out,errmes,2);
215 |        wrtout(out,"< End-of-File >");
216 |        wrtout(out," ");
217 |        return;
218 |    } 
219 | 
220 |    /* try to move to what would be the first byte of the next extension. 
221 |      If successfull, we have a problem... */
222 | 
223 |    ffmbyt(infits, dataend,0,&status);
224 |    if(status == 0) { 
225 |        wrtout(out,"< End-of-File >");
226 |        sprintf(errmes, 
227 |      "File has extra byte(s) after last HDU at byte %ld.", (long) dataend);
228 |        wrterr(out,errmes,2);
229 |        wrtout(out," ");
230 |    } 
231 | 
232 |    return;
233 | }
234 | 
235 | 
236 | 
237 | /******************************************************************************
238 | * Function
239 | *      init_report
240 | *
241 | *
242 | * DESCRIPTION:
243 | *      Initialize the fverify report
244 | *
245 | *******************************************************************************/
246 | void init_report(FILE *out,              /* output file */
247 |                  char *rootnam          /* input file name */
248 |                  )
249 | {
250 |     sprintf(comm,"\n%d Header-Data Units in this file.",totalhdu);
251 |     wrtout(out,comm);
252 |     wrtout(out," ");
253 | 
254 |     reset_err_wrn();
255 |     init_hduname();
256 | }
257 | 
258 | /******************************************************************************
259 | * Function
260 | *      close_report
261 | *
262 | *
263 | * DESCRIPTION:
264 | *      Close the fverify report
265 | *
266 | *******************************************************************************/
267 | void close_report(FILE *out              /* output file */ )
268 | {
269 |     int numerrs = 0;                    /* number of the errors         */
270 |     int numwrns = 0;                    /* number of the warnings       */
271 | 
272 |     /* print out a summary of all the hdus */
273 |     if(prstat)hdus_summary(out);
274 |     total_errors (&numerrs, &numwrns);
275 | 
276 |     total_warn = numwrns;
277 |     total_err  = numerrs;
278 | 
279 |     /* get the total number of errors and warnnings */
280 |     sprintf(comm,"**** Verification found %d warning(s) and %d error(s). ****",
281 |               numwrns, numerrs);
282 |     wrtout(out,comm);
283 | 
284 |     update_parfile(numerrs,numwrns);
285 |     /* destroy the hdu name */
286 |     destroy_hduname();
287 |     return ;
288 | } 
289 | 
290 | 


--------------------------------------------------------------------------------
/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