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 
00019 /* === Doxygen Comment ======================================= */
00033 /* =========================================================== */
00034 
00035 int open_image(IMAGE2D *frame, char *name, char *mode, int class, char *type)
00036 {
00037   int inclass;
00038   
00039   print_msg("Opening %s frame '%s' [%s]...",type,name,mode);
00040 
00041   if (open_frame(frame,name,mode) < 0) {
00042     print_msg("Cannot open frame %s",name);
00043     return(ERR_OPEN);
00044   }
00045 
00046   /* Correcting 'blank' ident and cunit */
00047   last_char(frame->ident);
00048   last_char(frame->cunit);
00049 
00050   if (DEBUG) print_msg("   '%s' [%c]: %dx%d [%.3g:%.3g %s]",
00051                        frame->ident,frame->data_type,
00052                        frame->nx,frame->ny,frame->min,frame->max,frame->cunit);
00053 
00054   /* Class checking */
00055   if (class > 0) {
00056     if ((inclass = read_file_class(frame)) != class) {
00057       print_error("Wrong fclass (%d) for `%s' (should be %d)",
00058                   inclass,frame->name,class);
00059       return(ERR_BAD_TYPE);
00060     }
00061   }
00062   else if (class < 0 && DEBUG)
00063     print_warning("No file class checking: "
00064                   "'%s' is assumed to be of type %s",frame->name,type);
00065 
00066   return(OK);
00067 }
00068 
00069 /* === Doxygen Comment ======================================= */
00085 /* =========================================================== */
00086 
00087 int open_image_ext(IMAGE2D *signal, IMAGE2D *variance, 
00088                    char *name, char *mode, int class, char *type)
00089 {
00090   char nameext[lg_name+1], sigext[]="image", varext[]="variance";
00091   int status;
00092 
00093   sprintf(nameext,"%s[%s]",name,sigext);
00094   if (exist_extension(nameext)) {            /* [signal] extension */
00095     if ((status = open_image(signal, nameext, mode, class, type))) 
00096       return(status);
00097   }
00098   else {                                     /* NO [signal] extension */
00099     if (DEBUG) print_warning("No SIGNAL extension in frame %s, "
00100                              "switching to primary frame",name);
00101     if ((status = open_image(signal, name, mode, class, type))) 
00102       return(status);
00103   }
00104 
00105   if (variance != NULL) {
00106     sprintf(nameext,"%s[%s]",name,varext);
00107     if (exist_extension(nameext)) {          /* [variance] extension */
00108       if ((status = open_image(variance, nameext, mode, 0, type))) 
00109         return(status);
00110     }
00111     else {                                   /* NO [variance] extension */
00112       print_error("There's no VARIANCE extention in frame %s",name);
00113       return(ERR_NODATA);
00114     }
00115   }
00116   return(OK);
00117 }
00118 
00119 /* === Doxygen Comment ======================================= */
00123 /* =========================================================== */
00124 
00125 float read_mean_RoN(void *anyfile, Channel channel) 
00126 {
00127   float rdnoise[2], RoN;
00128   
00129   disable_user_warnings();
00130   if (RD_desc(anyfile, RDNOISE2, FLOAT, 2, rdnoise) < 0) {
00131     RoN = (channel == BLUE_CHANNEL)? CCDB_RON:CCDR_RON;
00132     print_warning("%s descriptor absent from %s: "
00133                   "assuming default <RoN>[%s] = %.2f",
00134                   RDNOISE2,((Anyfile *)anyfile)->name,
00135                   channel_names[channel],RoN);
00136   } 
00137   else {
00138     RoN = (rdnoise[0] + rdnoise[1])/2;
00139     if (DEBUG) 
00140       print_msg("   CCD mean readout noise: %.2f e- (%.2f,%.2f)",
00141                 RoN,rdnoise[0],rdnoise[1]);
00142   }
00143   restore_user_warnings();
00144 
00145   return(RoN);
00146 }
00147 
00148 /* === Doxygen Comment ======================================= */
00152 /* =========================================================== */
00153 
00154 float read_jdate(void *anyfile) 
00155 {
00156   float jdate;
00157   
00158   disable_user_warnings();
00159   if (RD_desc(anyfile, JDATE, FLOAT, 1, &jdate) < 0) {
00160     jdate = -1;
00161     print_warning("%s descriptor absent from %s",
00162                   JDATE,((Anyfile *)anyfile)->name);
00163   } 
00164   else if (DEBUG) {
00165     print_msg("%s of frame %s: %.2f", 
00166               JDATE,((Anyfile *)anyfile)->name,jdate);
00167   }
00168   restore_user_warnings();
00169 
00170   return(jdate);
00171 }
00172 
00173 /* === Doxygen Comment ======================================= */
00177 /* =========================================================== */
00178 
00179 float check_jdate(char *arcname, float cal_jdate, 
00180                   char *objname, float obj_jdate) 
00181 {
00182   float diff;
00183   
00184   if (cal_jdate < 0 || obj_jdate < 0) {
00185     print_warning("Julian date of %s or %s is unset, cannot compute difference",
00186                   arcname,objname);
00187     return(-1);
00188   }
00189   
00190   diff = 24*ABS(cal_jdate - obj_jdate);
00191   if (DEBUG) 
00192     print_msg("JDate(calibration %s) - JDate(object %s) = %.2fh",
00193               arcname,objname,diff);
00194   
00195   if (diff > 1.) 
00196     print_warning("JDate(calibration %s) - JDate(object %s) > 1 day (%.2fh)",
00197                   arcname,objname,diff);
00198 
00199   return(diff);
00200 }
00201 
00202 /* === Doxygen Comment ======================================= */
00206 /* =========================================================== */
00207 
00208 void read_ima_axes(IMAGE2D *inframe, char xlab[], char ylab[])
00209 {
00210   set_control_level(WARNING);
00211   if (RD_desc(inframe, "LABX", CHAR, lg_label+1, xlab) < 0) strcpy(xlab, "x");
00212   if (RD_desc(inframe, "LABY", CHAR, lg_label+1, ylab) < 0) strcpy(ylab, "y");
00213   set_control_level(FATAL);
00214   /* Add units for 'I' and 'J' */
00215   if (strcmp(xlab,"I")==0 && strcmp(ylab,"J")==0) {
00216     strcpy(xlab, "I [spaxel]"); 
00217     strcpy(ylab, "J [spaxel]");
00218   }
00219 }

Generated on Wed Oct 26 23:59:39 2005 for Snifs by doxygen 1.3.5