/* FILE: par_coo_file.c * PURPOSE: * (1) Open the coordinate file * (2) Create and fill the qdphot5_ParS->ParS_CooS * (3) Close the coordinate file * AUTHOR: Kenneth J. Mighell (mighell@noao.edu) * LANGUAGE: ANSI C * DATE: 2001JUL03 * COPYRIGHT: (C) 2001 Assoc. of Universities for Research in Astronomy Inc. */ #include "mx.h" #include "qdphot.h" #define DEBUG (MX_FALSE) int qdphot5_ParS_CooS_File_f1 ( qdphot5_ParS *ParS ){ char mxfunc[] = "qdphot5_ParS_CooS_File_f1"; int mxstatus = 0; #define CARDSIZE (1024) char card[CARDSIZE]; double cooxd; double cooyd; int cooidi; int j; int k; int items; /* * Abort if there is no coordinate file */ if ( ParS->coo_is_INDEF ) goto bye; if (DEBUG) printf( "# Try to open coordinate file\n\"%s\"\n", ParS->coo); if ( (FILE *)NULL != ParS->cfp ) { mxstatus = 1; sprintf ( MX.tmpmsg, "# ParS->cfp != (FILE *)NULL\n" ); goto mx_error2; } ParS->cfp = fopen( ParS->coo, "r"); if ( (FILE *)NULL == ParS->cfp ) { mxstatus = 2; sprintf ( MX.tmpmsg, "# Could not open coordinate file\n" "# \"%s\"\n", ParS->coo ); goto mx_error2; } if ( ParS->coodim != 0 ) { mxstatus = 3; sprintf ( MX.tmpmsg, "# ParS->CooS appears to already be allocated\n" ); goto mx_error2; } while ( (char *)NULL != fgets(card, CARDSIZE, ParS->cfp) ) ParS->coodim++; rewind( ParS->cfp); if (DEBUG) printf( "# %d lines total\n", ParS->coodim); ParS->CooS = (qdphot5_CooS *)malloc(sizeof(qdphot5_CooS)*ParS->coodim); j = -1; for ( k=0; kcoodim; ++k ) { fgets(card, CARDSIZE, ParS->cfp); items = sscanf( card, "%lf%lf", &cooxd, &cooyd); if (items == 2) { j++; if (j == ParS->coodim) { mxstatus = 4; sprintf ( MX.tmpmsg, "# Yikes! j == coodim (array bounds exceeded)\n" ); goto mx_error2; } ParS->CooS[j].xd = cooxd; ParS->CooS[j].yd = cooyd; cooidi = j + 1; ParS->CooS[j].idi = cooidi; if (DEBUG) printf( "%8.2f%8.2f%7d\n", ParS->CooS[j].xd, ParS->CooS[j].yd, ParS->CooS[j].idi); } else { if (DEBUG) printf( "# *** WARNING *** Could not read line %d : %s", (k+1), card ); } } ParS->coostars = cooidi; if (DEBUG) printf( "# %d stars total\n", ParS->coostars ); fclose( ParS->cfp ); ParS->cfp = (FILE *)NULL; ok: mxstatus = 0; goto bye; mx_error1: mxp_tmpmsg_init_f0(); mx_error2: mxp_errmsg_append_f3 (mxfunc, mxstatus, MX.tmpmsg); goto bye; bye: return(mxstatus); #undef CARDSIZE #undef DEBUG } /* end-of-file */