Changeset 21116
- Timestamp:
- Jan 13, 2009, 10:53:38 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFits.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFits.c
r21081 r21116 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.8 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2009-01- 03 01:05:47$9 * @version $Revision: 1.83 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2009-01-13 20:53:38 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 36 36 37 37 #define MAX_STRING_LENGTH 256 // maximum length string for FITS routines 38 39 #define FITS_OPEN_RETRIES 5 // Number of retries to attempt when opening a FITS file 40 #define FITS_OPEN_RETRY_WAIT 200000 // Wait between retries (usec) 41 38 42 static char *defaultExtword = "EXTNAME"; 39 43 40 bool p_psFitsDumpErrors (const char* filename, unsigned int lineno, const char* func, 41 psErrorCode code, const char *message, ...) { 44 45 bool p_psFitsDumpErrors (const char* filename, unsigned int lineno, const char* func, 46 psErrorCode code, const char *message, ...) { 42 47 43 48 char fitsErr[MAX_STRING_LENGTH]; … … 49 54 50 55 while (fits_read_errmsg(fitsErr)) { 51 p_psError(filename, lineno, func, PS_ERR_BAD_FITS, false, "CFITSIO error: %s", fitsErr);56 p_psError(filename, lineno, func, PS_ERR_BAD_FITS, false, "CFITSIO error: %s", fitsErr); 52 57 } 53 58 … … 55 60 } 56 61 57 psErrorCode p_psFitsError(const char* filename, unsigned int lineno, const char* func, 58 int status, bool new, const char *errorMsg, ...)62 psErrorCode p_psFitsError(const char* filename, unsigned int lineno, const char* func, 63 int status, bool new, const char *errorMsg, ...) 59 64 { 60 65 char fitsErr[MAX_STRING_LENGTH]; … … 68 73 69 74 while (fits_read_errmsg(fitsErr)) { 70 psError(PS_ERR_IO, false, "[CFITSIO error: %s]", fitsErr);75 psError(PS_ERR_IO, false, "[CFITSIO error: %s]", fitsErr); 71 76 } 72 77 return PS_ERR_IO; … … 97 102 if (fits != NULL) { 98 103 if (fits_close_file(fits->fd, &status)) { 99 psFitsDumpErrors (PS_ERR_IO, "Error while closing psFits object");104 psFitsDumpErrors (PS_ERR_IO, "Error while closing psFits object"); 100 105 return false; 101 106 } … … 124 129 } 125 130 126 # define FITS_OPEN_RETRIES 5127 # define FITS_OPEN_RETRY_WAIT 200000128 129 131 psFits* psFitsOpen(const char* name, const char* mode) 130 132 { 131 133 PS_ASSERT_STRING_NON_EMPTY(name, NULL); 132 134 133 int status = 0; 134 fitsfile *fptr = NULL; /* Pointer to the FITS file */ 135 136 // check that the directory exists : for NFS-mounted file systems, the directory may 135 // Check that the directory exists: for NFS-mounted file systems, the directory may 137 136 // take some time to appear 138 137 139 int dirstat = 0; 140 char *tmpname = psStringCopy (name); 141 char *tmpdir = dirname (tmpname); 142 char *dir = psStringCopy (tmpdir); 138 int dirstat = 0; // Status of directory access 139 psString tmpname = psStringCopy(name); // Copy of filename, since dirname() may modify 140 const char *dir = dirname(tmpname); 143 141 useconds_t waittime = FITS_OPEN_RETRY_WAIT; 144 145 for (int i = 0; (i < FITS_OPEN_RETRIES) && ((dirstat = access (dir, F_OK)) != 0); i++) {146 // if the error is not ENOENT, then the error is more serious than NFS-mount delays 147 if (errno != ENOENT) { 148 int thisErrno = errno; 149 char errorBuf[64], *errorMsg;150 # if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)151 errorMsg = strerror_r (thisErrno, errorBuf, 64);152 # else153 strerror_r (thisErrno, errorBuf, 64);154 errorMsg = errorBuf; 155 # endif156 psError (PS_ERR_IO, true, "Directory (%s) for requested file is not accessible: %s", dir, errorMsg); 157 158 psFree (dir); 159 psFree(tmpname);160 return NULL;161 }162 163 usleep(waittime);164 waittime *= 2;142 143 for (int i = 0; (i < FITS_OPEN_RETRIES) && ((dirstat = access(dir, F_OK)) != 0); i++) { 144 if (errno != ENOENT) { 145 // The error is more serious than NFS-mount delays 146 int thisErrno = errno; // Error number 147 char errorBuf[MAX_STRING_LENGTH], *errorMsg; 148 #if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE) 149 errorMsg = strerror_r(thisErrno, errorBuf, MAX_STRING_LENGTH); 150 #else 151 strerror_r(thisErrno, errorBuf, MAX_STRING_LENGTH); 152 errorMsg = errorBuf; 153 #endif 154 psError(PS_ERR_IO, true, "Directory (%s) for requested file is not accessible: %s", 155 dir, errorMsg); 156 157 psFree(tmpname); 158 return NULL; 159 } 160 161 usleep(waittime); 162 waittime *= 2; 165 163 } 166 164 if (dirstat != 0) { 167 psError (PS_ERR_IO, true, "Directory (%s) for requested file is not accessible, timed out", dir); 168 psFree (dir); 169 psFree (tmpname); 170 return NULL; 171 } 172 psFree (dir); 173 psFree (tmpname); 165 psError(PS_ERR_IO, true, "Directory (%s) for requested file is not accessible, timed out", dir); 166 psFree(tmpname); 167 return NULL; 168 } 169 psFree(tmpname); 174 170 175 171 /* check the mode to determine how to open/create file */ … … 196 192 } 197 193 194 int status = 0; // CFITSIO status 195 fitsfile *fptr = NULL; // Pointer to the FITS file 196 198 197 if (newFile) { 199 198 /* Check if an existing file is in the way before creating file */ … … 201 200 // file exists, delete old one first 202 201 if (remove(name)) { 203 int thisErrno = errno;204 char errorBuf[64], *errorMsg;202 int thisErrno = errno; 203 char errorBuf[64], *errorMsg; 205 204 # if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE) 206 errorMsg = strerror_r (errno, errorBuf, 64);205 errorMsg = strerror_r (errno, errorBuf, 64); 207 206 # else 208 strerror_r (errno, errorBuf, 64);209 errorMsg = errorBuf; 207 strerror_r (errno, errorBuf, 64); 208 errorMsg = errorBuf; 210 209 # endif 211 psError (PS_ERR_IO, true, "Failed to delete a previously-existing file: %s", errorMsg);212 fprintf (stderr, "errno: %d, %s, %s : %lx, %lx\n", thisErrno, errorMsg, errorBuf, (long int) errorMsg, (long int) errorBuf);213 return NULL;214 }210 psError (PS_ERR_IO, true, "Failed to delete a previously-existing file: %s", errorMsg); 211 fprintf (stderr, "errno: %d, %s, %s : %lx, %lx\n", thisErrno, errorMsg, errorBuf, (long int) errorMsg, (long int) errorBuf); 212 return NULL; 213 } 215 214 } 216 215 if (!access(name, F_OK)) { 217 psError (PS_ERR_IO, true, "deleted file still exists!");218 return NULL;219 }216 psError (PS_ERR_IO, true, "deleted file still exists!"); 217 return NULL; 218 } 220 219 221 220 #if ( CFITSIO_DISKFILE == 1 ) … … 226 225 (&fptr, name, &status); 227 226 if (fptr == NULL || status != 0) { 228 psFitsDumpErrors (PS_ERR_IO, _("Could not create file,'%s'"), name);227 psFitsDumpErrors (PS_ERR_IO, _("Could not create file,'%s'"), name); 229 228 return NULL; 230 229 } … … 237 236 (&fptr, name, iomode, &status); 238 237 if (fptr == NULL || status != 0) { 239 psFitsDumpErrors(PS_ERR_IO, _("Could not open file,'%s'"), name);238 psFitsDumpErrors(PS_ERR_IO, _("Could not open file,'%s'"), name); 240 239 return NULL; 241 240 } … … 414 413 fits_movrel_hdu(fits->fd, extnum, &hdutype, &status); 415 414 if (status != 0) { 416 psFitsDumpErrors (PS_ERR_LOCATION_INVALID, _("Could not move %d HDUs from current position"), extnum);415 psFitsDumpErrors (PS_ERR_LOCATION_INVALID, _("Could not move %d HDUs from current position"), extnum); 417 416 return false; 418 417 } … … 420 419 fits_movabs_hdu(fits->fd, extnum+1, &hdutype, &status); 421 420 if (status != 0) { 422 psFitsDumpErrors (PS_ERR_LOCATION_INVALID, _("Could not move to specified HDU #%d."), extnum);421 psFitsDumpErrors (PS_ERR_LOCATION_INVALID, _("Could not move to specified HDU #%d."), extnum); 423 422 return false; 424 423 } … … 475 474 476 475 if (fits_update_key_str(fits->fd, extword, (char*)name, NULL, &status) != 0) { 477 psFitsDumpErrors (PS_ERR_IO, _("Could not write data to file %s"), name);476 psFitsDumpErrors (PS_ERR_IO, _("Could not write data to file %s"), name); 478 477 return false; 479 478 }
Note:
See TracChangeset
for help on using the changeset viewer.
