Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

extract/lib/proc_misc.c

Go to the documentation of this file.
00001 /* === Doxygen Comment ======================================= */
00013 /* =========================================================== */
00014 
00015 #include <IFU_io.h>
00016 #include <IFU_math.h>
00017 #include <snifs.h>
00018 #include <extract.h>
00019 
00020 /* === Doxygen Comment ======================================= */
00034 /* =========================================================== */
00035 
00036 int open_image(IMAGE2D *frame, char *name, char *mode, int class, char *type)
00037 {
00038   int inclass;
00039   
00040   print_msg("Opening %s frame '%s' [%s]...",type,name,mode);
00041 
00042   if (open_frame(frame,name,mode) < 0) {
00043     print_msg("Unable to open %s",name);
00044     return(ERR_OPEN);
00045   }
00046 
00047   /* Correcting 'blank' ident and cunit */
00048   last_char(frame->ident);
00049   last_char(frame->cunit);
00050 
00051   if (DEBUG) print_msg("   '%s' [%c]: %dx%d [%.3g:%.3g %s]",
00052                        frame->ident,frame->data_type,
00053                        frame->nx,frame->ny,frame->min,frame->max,frame->cunit);
00054 
00055   /* Class checking */
00056   if (class > 0) {
00057     if ((inclass = read_file_class(frame)) != class) {
00058       print_error("Wrong file class: `%s' should be %d, got %d",
00059                   frame->name,class,inclass);
00060       return(ERR_BAD_TYPE);
00061     }
00062   }
00063   else if (class < 0 && DEBUG)
00064     print_warning("No file class checking: "
00065                   "'%s' is assumed to be of type %s",frame->name,type);
00066 
00067   return(OK);
00068 }
00069 
00070 /* === Doxygen Comment ======================================= */
00086 /* =========================================================== */
00087 
00088 int open_image_ext(IMAGE2D *signal, IMAGE2D *variance, 
00089                    char *name, char *mode, int class, char *type)
00090 {
00091   char nameext[lg_name+1], sigext[]="image", varext[]="variance";
00092   int status;
00093 
00094   sprintf(nameext,"%s[%s]",name,sigext);
00095   if (exist_extension(nameext)) {            /* [signal] extension */
00096     if ((status = open_image(signal, nameext, mode, class, type))) 
00097       return(status);
00098   }
00099   else {                                     /* NO [signal] extension */
00100     if (DEBUG) print_warning("No SIGNAL extension in frame %s, "
00101                              "switching to primary frame",name);
00102     if ((status = open_image(signal, name, mode, class, type))) 
00103       return(status);
00104   }
00105 
00106   if (variance != NULL) {
00107     sprintf(nameext,"%s[%s]",name,varext);
00108     if (exist_extension(nameext)) {          /* [variance] extension */
00109       if ((status = open_image(variance, nameext, mode, 0, type))) 
00110         return(status);
00111     }
00112     else {                                   /* NO [variance] extension */
00113       print_error("There's no VARIANCE extention in frame %s",name);
00114       return(ERR_NODATA);
00115     }
00116   }
00117   return(OK);
00118 }
00119 
00120 /* === Doxygen Comment ======================================= */
00124 /* =========================================================== */
00125 
00126 float read_mean_RoN(void *anyfile, Channel channel) 
00127 {
00128   float rdnoise[2], RoN;
00129   
00130   disable_user_warnings();
00131   if (RD_desc(anyfile, RDNOISE2, FLOAT, 2, rdnoise) < 0) {
00132     RoN = (channel == BLUE_CHANNEL)? CCDB_RON:CCDR_RON;
00133     print_warning("%s descriptor absent from %s: assuming default <RoN>[%s] = %.2f",
00134                   RDNOISE2,((Anyfile *)anyfile)->name,channel_names[channel],RoN);
00135   } 
00136   else {
00137     RoN = (rdnoise[0] + rdnoise[1])/2;
00138     if (DEBUG) 
00139       print_msg("   CCD mean readout noise: %.2f e- (%.2f,%.2f)",RoN,rdnoise[0],rdnoise[1]);
00140   }
00141   restore_user_warnings();
00142 
00143   return(RoN);
00144 }
00145 
00146 /* === Doxygen Comment ======================================= */
00150 /* =========================================================== */
00151 
00152 float read_airmass(void *anyfile) 
00153 {
00154   float airmass;
00155   
00156   disable_user_warnings();
00157   if (RD_desc(anyfile, AIRMASS, FLOAT, 1, &airmass) < 0 || airmass == 0) {
00158     airmass = 1;
00159     print_warning("%s descriptor absent from %s or null: assuming z = 1",
00160                   AIRMASS,((Anyfile *)anyfile)->name);
00161   } 
00162   else if (DEBUG) {
00163     print_msg("Airmass of frame %s: z = %.3g",
00164               ((Anyfile *)anyfile)->name,airmass);
00165   }
00166   restore_user_warnings();
00167 
00168   return(airmass);
00169 }
00170 
00171 /* === Doxygen Comment ======================================= */
00175 /* =========================================================== */
00176 
00177 float read_juliandate(void *anyfile) 
00178 {
00179   float mjdate;
00180   
00181   disable_user_warnings();
00182   if (RD_desc(anyfile, MJDATE, FLOAT, 1, &mjdate) < 0) {
00183     mjdate = 0;
00184     print_warning("%s descriptor absent from %s: assuming Jdate = 0",
00185                   MJDATE,((Anyfile *)anyfile)->name);
00186   } 
00187   else if (DEBUG) {
00188     print_msg("Julian date of frame %s: %.2f", 
00189               ((Anyfile *)anyfile)->name,mjdate);
00190   }
00191   restore_user_warnings();
00192 
00193   return(mjdate);
00194 }
00195 
00196 /* === Doxygen Comment ======================================= */
00200 /* =========================================================== */
00201 
00202 float check_airmass(char *arcname, float cal_airmass, 
00203                     char *objname, float obj_airmass) 
00204 {
00205   float diff;
00206   
00207   diff = ABS(acos(1./cal_airmass) - acos(1./obj_airmass))*180/M_PI;
00208   if (DEBUG) 
00209     print_msg("Zenithal distance calibration %s/object %s: %.1f deg", 
00210               arcname,objname,diff);
00211   
00212   if (diff > 15.) 
00213     print_warning("Zenithal distance calibration %s/object %s > 1h (%.1f deg)",
00214                   arcname,objname,diff);
00215   
00216   return(diff);
00217 }
00218 
00219 /* === Doxygen Comment ======================================= */
00223 /* =========================================================== */
00224 
00225 float check_jdate(char *arcname, float cal_jdate, 
00226                   char *objname, float obj_jdate) 
00227 {
00228   float diff;
00229   
00230   diff = 24*ABS(cal_jdate - obj_jdate);
00231   if (DEBUG) 
00232     print_msg("JDate(calibration %s) - JDate(object %s) = %.1fh",
00233               arcname,objname,diff);
00234   
00235   if (diff > 1.) 
00236     print_warning("JDate(calibration %s) - JDate(object %s) > 1 day (%.1fh)",
00237                   arcname,objname,diff);
00238 
00239   return(diff);
00240 }
00241 
00242 

Generated on Tue Nov 23 18:04:19 2004 for Snifs by doxygen 1.3.3