/* @(#)cutil.c 17.1.1.1 (ESO-DMD) 01/25/02 17:40:33 */ /*=========================================================================== 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 CUTIL .LANGUAGE C .AUTHOR K. Banse IPG-ESO Garching .KEYWORDS .COMMENTS holds FRAMOU_C, BLANKO_C, OSCHAR_C, ReadASCI, Newsort .ENVIRONment MIDAS #include Prototypes for MIDAS interfaces .VERSIONS 1.00 940411 converted to C from UTIL.FOR RvH 1.10 940901 add GetWC routine KB 010423 last modif ------------------------------------------------------------*/ /* Define _POSIX_SOURCE to indicate that this is a POSIX program */ #define _POSIX_SOURCE 1 #include #include #include #include #include #define MAXDIM 3 #define SWAP(a,b) temp=(a);(a)=(b);(b)=temp; /* */ /*++++++++++++++++++++++++++++++ .PURPOSE display name of image and its data type .ALGORITHM use STFINF to get data type .INPUT/OUTPUT call as FRAMOU_C(frame) input: char *frame name of data frame .RETURNS nothing ------------------------------*/ #ifdef __STDC__ void FRAMOU_C(char *frame) #else void FRAMOU_C(frame) char *frame; #endif { int nn, ibuf[6]; char cbuff[4], file[80], output[100]; /* make sure that the frame name ends with a null character */ if ((int)strlen(frame) > 82) { (void) strncpy(output,frame,82); output[82] = '\0'; (void) CGN_CUTOFF(output,file); } else (void) CGN_CUTOFF(frame,file); nn = (int)strlen(file); if (nn > 66) { file[nn++] = '\n'; /* too long: split the output */ file[nn] = '\0'; } /* Get data format of frame, as well as file type */ (void) SCFINF(frame,7,ibuf); if (ibuf[1] == D_R4_FORMAT) (void) strcpy(cbuff,"R4"); else if (ibuf[1] == D_I4_FORMAT) (void) strcpy(cbuff,"I4"); else if (ibuf[1] == D_I2_FORMAT) (void) strcpy(cbuff,"I2"); else if (ibuf[1] == D_I1_FORMAT) (void) strcpy(cbuff,"I1"); else if (ibuf[1] == D_UI2_FORMAT) (void) strcpy(cbuff,"UI2"); else if (ibuf[1] == D_R8_FORMAT) (void) strcpy(cbuff,"R8"); else { (void) sprintf(output,"frame: %s unknown data type",file); SCTPUT(output); return; } (void) sprintf(output,"frame: %s (data = %s",file,cbuff); if (ibuf[2] == 0) /* Midas frame */ { if (ibuf[5] == 2) (void) strcat(output,")"); else if (ibuf[5] == 1) (void) strcat(output,") (desc = ZFormat)"); else (void) strcat(output,") (desc = oFormat!!)"); } else /* FITS file */ { if (ibuf[5] == 2) (void) strcat(output,", format = FITS)"); else if (ibuf[5] == 1) (void) strcat(output,", format = FITS) (desc = ZFormat)"); else (void) strcat(output,", format = FITS) (desc = oFormat!!)"); } SCTPUT(output); } /* */ /*++++++++++++++++++++++++++++++ .PURPOSE remove spaces in input string .INPUT/OUTPUT call as BLANKO_C( string ) in/output: char *string input string .RETURNS nothing ------------------------------*/ #ifdef __STDC__ void BLANKO_C(char *string) #else void BLANKO_C(string) char *string; #endif { register char *pntr; pntr = string; while (*pntr != '\0') { if (*pntr != ' ') *string++ = *pntr; pntr++; } *string = '\0'; } /*+++++++++++++++++++++++++++++++ .PURPOSE return the backslash character .INPUT/OUTPUT call as OSCHAR_C( cval ) output: char *cval backslash character .RETURNS nothing -------------------------------*/ #ifdef __STDC__ void OSCHAR_C(char *cval) #else void OSCHAR_C(cval) char *cval; #endif { static char backsl = '\\'; *cval = backsl; } /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .IDENTIFICATION function ReadASCI version 1.00 951130 K. Banse ESO - Garching .KEYWORDS ASCII data file .PURPOSE get data from ASCII file .ALGORITHM read all records of an ASCII file, convert to real data and fill buffer .INPUT/OUTPUT use as: void ReadASCI(infile,dattyp,total,a,b,minflg,fmin,fmax) input parameter: INFILE: char * name of ASCII data file DATTYP: int 1 = integer, 2 = real, 4 = double TOTAL: int no. of pixels to fill MINFLG: int = 1 to also calculate MIN + MAX, else = 0 output parameter: A: float array data buffer to be filled B: int array data buffer to be filled FMIN: float * minimum of data FMAX: float * maximum ----------------------------------------------------------------------- */ #ifdef __STDC__ void ReadASCI(char *infile,int dattyp,int total,float *a,int *b, int minflg,float *fmin,float *fmax) #else void ReadASCI(infile,dattyp,total,a,b,minflg,fmin,fmax) char *infile; int dattyp, total, minflg, *b; float *a, *fmin, *fmax; #endif { int fb, no, ic, finis, uni; int linecnt, reclen, inull, more; int fid; register int nr; float rnull; char *cptr, *ncptr, *oldrec, *newrec; #define NOELM 2000 #define RECMAX 8000 (void) SCKRDR("NULL",2,1,&ic,&rnull,&uni,&no); /* get user null value */ more = 0; linecnt = 0; fid = osaopen(infile,READ); if (fid < 0) { char errmess[80]; (void) sprintf(errmess,"Problems opening data file %s",infile); SCETER(1,errmess); return; } oldrec = malloc((unsigned int) RECMAX); /* get space for file record */ newrec = malloc((unsigned int) RECMAX); ic = 0; /* init data counter */ finis = 0; /* ----------------------------- */ /* reading loop for integer data */ /* ----------------------------- */ if (dattyp == 1) { int *ispace, *iptr, bmin = 99999, bmax = -99999; register int ir; float rdum = 0; double ddum = 0; inull = CGN_NINT(rnull); ispace = (int *) malloc((unsigned int) (NOELM*sizeof(int))); sect_200: linecnt ++; reclen = osaread(fid,oldrec,RECMAX); if (reclen < 0) goto sect_930; /* EOF encountered */ if (reclen == 0) goto sect_200; /* skip empty records */ fb = 1; /* first-blank-flag is set in the beginning */ ncptr = newrec; cptr = oldrec; for (nr=0; nr total) { more = - (no + ic - total); /* more goes negatively */ no = total - ic; /* cut off overflow data */ finis = 1; } if (minflg == 1) { for (nr=0; nr bmax) bmax = ir; else if (ir < bmin) bmin = ir; } } else { for (nr=0; nr total) { more = - (no + ic - total); /* more goes negatively */ no = total - ic; /* cut off overflow data */ finis = 1; } if (minflg == 1) { for (nr=0; nr rmax) rmax = rr; else if (rr < rmin) rmin = rr; } } else { for (nr=0; nr total) { more = - (no + ic - total); /* more goes negatively */ no = total - ic; /* cut off overflow data */ finis = 1; } if (minflg == 1) { for (nr=0; nr dmax) dmax = dd; else if (dd < dmin) dmin = dd; } } else { for (nr=0; nr> 1; SWAP(arr[mid],arr[l+1]) if (arr[l] > arr[ir]) { SWAP(arr[l],arr[ir]) } if (arr[l+1] > arr[ir]) { SWAP(arr[l+1],arr[ir]) } if (arr[l] > arr[l+1]) { SWAP(arr[l],arr[l+1]) } i = ll = l + 1; j = ir; a = arr[ll]; for (;;) { do i++; while (arr[i] < a); do j--; while (arr[j] > a); if (j < i) break; SWAP(arr[i],arr[j]) } arr[ll] = arr[j]; arr[j] = a; if (j >= nmed) ir = j-1; if (j <= nmed) l = i; } } }