/* @(#)wrldco.c 17.1.1.1 (ESO-DMD) 01/25/02 17:40:37 */ /*=========================================================================== Copyright (C) 1995 European Southern Observatory (ESO) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. Correspondence concerning ESO-MIDAS should be addressed as follows: Internet e-mail: midas@eso.org Postal address: European Southern Observatory Data Management Division Karl-Schwarzschild-Strasse 2 D 85748 Garching bei Muenchen GERMANY ===========================================================================*/ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .COPYRIGHT: Copyright (c) 1987 European Southern Observatory, all rights reserved .IDENTIFIER module wrldco.c .LANGUAGE C .AUTHOR K. Banse IPG-ESO Garching .KEYWORDS .COMMENTS holds fp2wc .ENVIRONment MIDAS #include Prototypes for MIDAS interfaces .VERSIONS 1.00 951215 build on `fp2wc' from cutil.c KB 010213 last modif ------------------------------------------------------------*/ /* Define _POSIX_SOURCE to indicate that this is a POSIX program */ #define _POSIX_SOURCE 1 #include #include #include #include #define MAXDIM 4 /* synchronize with error message below */ #define MAXDIMSQ MAXDIM*MAXDIM /* */ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE convert from Pixel to World Coordinate and vice versa .INPUT/OUTPUT call as fp2wc(flag,imno,coordin,coordout) input: int flag = 0 for initialization, = 1 for conversion fp -> wc, = -1 for conversion wc -> fp int imno image no. for flag = 0 unused if flag != 0 in/output: double *coordin frame pixel (flag = 1) world coord (flag = -1) double *coordout world coord (flag = 1) frame pixel (flag = -1) .RETURNS status 0 = o.k. for flag != 0 0 or -1 for flag=0 to tell, if non- or linear coord system > 0 if error for all flags ------------------------------------------------------------*/ #ifdef __STDC__ int fp2wc(int flag,int imno,double *coordin,double *coordout) #else int fp2wc(flag,imno,coordin,coordout) int flag, imno; double *coordin; double *coordout; #endif { int naxis, stat, retstat; int ioff, mr, null, nval, unit; int e_c=1, e_log=0, e_disp=0; register int nr; static int npix[MAXDIM]; static char ctype[6][9]; double tmpr[MAXDIM], phi=0, theta=0; static double start[MAXDIM], step[MAXDIM], refpix[MAXDIM], crval[MAXDIM]; static double end[MAXDIM], pcval[MAXDIMSQ]; static struct wcsprm wcs; static struct linprm lin; static struct prjprm prj; static struct celprm cel; retstat = 0; if (flag == 0) { char cunit[100], pcnam[12]; int rstat, ln, ln1, ln2; double longpole, latpole; (void) SCDRDI(imno,"NAXIS",1,1,&nval,&naxis,&unit,&null); if (naxis > MAXDIM) { SCTPUT("WCO: max. 4 dimensions supported..."); return (1); } (void) SCDRDI(imno,"NPIX",1,naxis,&nval,npix,&unit,&null); (void) SCDRDD(imno,"START",1,naxis,&nval,start,&unit,&null); (void) SCDRDD(imno,"STEP",1,naxis,&nval,step,&unit,&null); nval = (naxis+1)*16; (void) SCDRDC(imno,"CUNIT",1,1,nval,&ln,cunit,&unit,&null); mr = 16; for (nr=0; nr use center pixels"); } for (nr=0; nr 0) /* pixel coords => world coords */ { /* 1, 2, ... counting */ if (wcs.flag == 999) { /* no projection type specified */ for (nr=0; nr (double) npix[nr])) retstat = 55; } } else { stat = wcsrev(ctype,&wcs,coordin,&lin,tmpr,&prj,&phi,&theta,crval, &cel,coordout); if (stat != 0) { SCTPUT("WCO: problems with wcsrev routine..."); retstat = 5; } } } else /* world coords => pixel coords */ { if (wcs.flag == 999) { /* no projection type specified */ for (nr=0; nr npix[nr])) retstat = 55; } } else { stat = wcsfwd(ctype,&wcs,coordin,crval,&cel,&phi,&theta,&prj,tmpr, &lin,coordout); if (stat != 0) { SCTPUT("WCO: problems with wcsfwd routine..."); retstat = 5; } } } } return retstat; }