VIRCAM Pipeline  2.3.10
casu_utils.c
1 /* $Id: casu_utils.c,v 1.9 2015/11/27 12:06:41 jim Exp $
2  *
3  * This file is part of the CASU Pipeline utilities
4  * Copyright (C) 2015 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jim $
23  * $Date: 2015/11/27 12:06:41 $
24  * $Revision: 1.9 $
25  * $Name: $
26  */
27 
28 /* Includes */
29 
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #define _XOPEN_SOURCE
35 #include <sys/time.h>
36 #include <time.h>
37 #include <libgen.h>
38 #include <string.h>
39 #include <unistd.h>
40 
41 #include <cpl.h>
42 #include <math.h>
43 
44 #include "casu_utils.h"
45 #include "casu_fits.h"
46 #include "imcore.h"
47 
48 #define SZKEY 32
49 #define SZVAL 64
50 
51 static void casu_substr(char *in, int ist, int len, char *out);
52 static int casu_mjdcompare(const cpl_frame *f1, const cpl_frame *f2);
53 
68 /*---------------------------------------------------------------------------*/
94 /*---------------------------------------------------------------------------*/
95 
96 extern int casu_compare_tags(const cpl_frame *frame1, const cpl_frame *frame2) {
97  char *v1,*v2;
98 
99  /* Test entries */
100 
101  if (frame1 == NULL || frame2 == NULL)
102  return(-1);
103 
104  /* Get the tags */
105 
106  if ((v1 = (char *)cpl_frame_get_tag(frame1)) == NULL)
107  return(-1);
108  if ((v2 = (char *)cpl_frame_get_tag(frame2)) == NULL)
109  return(-1);
110 
111  /* Compare the tags */
112 
113  if (strcmp(v1,v2))
114  return(0);
115  else
116  return(1);
117 }
118 
119 /*---------------------------------------------------------------------------*/
147 /*---------------------------------------------------------------------------*/
148 
149 extern cpl_frameset *casu_frameset_subgroup(cpl_frameset *frameset,
150  cpl_size *labels, cpl_size nlab,
151  const char *tag) {
152  int i;
153  cpl_frameset *cur_set,*ret_set;
154  cpl_frame *cur_frame;
155  char *cur_tag;
156 
157 
158  ret_set = NULL;
159  for (i = 0; i < nlab; i++) {
160  cur_set = cpl_frameset_extract(frameset,labels,(cpl_size)i);
161  if (cur_set == NULL)
162  break;
163  cur_frame = cpl_frameset_get_position(cur_set,0);
164  cur_tag = (char *)cpl_frame_get_tag(cur_frame);
165  if (!strcmp(cur_tag,tag)) {
166  ret_set = cur_set;
167  cpl_frameset_sort(ret_set,casu_mjdcompare);
168  break;
169  }
170  cpl_frameset_delete(cur_set);
171  }
172  return(ret_set);
173 }
174 
175 /*---------------------------------------------------------------------------*/
204 /*---------------------------------------------------------------------------*/
205 
206 extern cpl_frame *casu_frameset_subgroup_1(cpl_frameset *frameset,
207  cpl_size *labels, cpl_size nlab,
208  const char *tag) {
209  cpl_frameset *cur_set;
210  cpl_frame *cur_frame,*new_frame;
211 
212  if ((cur_set = casu_frameset_subgroup(frameset,labels,nlab,tag)) == NULL) {
213  return(NULL);
214  } else {
215  cur_frame = cpl_frameset_get_position(cur_set,0);
216  new_frame = cpl_frame_duplicate(cur_frame);
217  cpl_frameset_delete(cur_set);
218  return(new_frame);
219  }
220 }
221 
222 /*---------------------------------------------------------------------------*/
241 /*---------------------------------------------------------------------------*/
242 
243 extern long casu_getnpts(cpl_image *in) {
244  int nx,ny;
245  long npts;
246  const char *fctid = "casu_getnpts";
247 
248  if ((nx = (int)cpl_image_get_size_x(in)) == -1) {
249  cpl_msg_error(fctid,"NULL image input");
250  return(0);
251  }
252  if ((ny = (int)cpl_image_get_size_y(in)) == -1) {
253  cpl_msg_error(fctid,"NULL image input");
254  return(0);
255  }
256  npts = (long)nx*ny;
257  return(npts);
258 }
259 
260 /*---------------------------------------------------------------------------*/
285 /*---------------------------------------------------------------------------*/
286 
287 extern void casu_prov(cpl_propertylist *p, casu_fits **inlist, int n,
288  int isextn) {
289  int i;
290  char keyword[SZKEY],value[SZVAL],*fn,*base;
291 
292  /* Delete all the provenance keywords that might already exist */
293 
294  if (isextn)
295  cpl_propertylist_erase_regexp(p,"ESO DRS PROV[0-9]*",0);
296  else
297  cpl_propertylist_erase_regexp(p,"PROV[0-9]*",0);
298 
299  /* Add the new provenance keywords */
300 
301  for (i = 0; i < n; i++) {
302  if (isextn) {
303  (void)snprintf(keyword,SZKEY,"ESO DRS PROV%d",i+1);
304  fn = cpl_strdup(casu_fits_get_fullname(inlist[i]));
305  base = basename(fn);
306  (void)snprintf(value,SZVAL,"%s",base);
307  cpl_free(fn);
308  } else {
309  (void)snprintf(keyword,SZKEY,"PROV%d",i+1);
310  fn = cpl_strdup(casu_fits_get_filename(inlist[i]));
311  base = basename(fn);
312  (void)snprintf(value,SZVAL,"%s",base);
313  cpl_free(fn);
314  }
315  cpl_propertylist_update_string(p,keyword,value);
316  (void)snprintf(value,SZVAL,"Input file # %d",i+1);
317  cpl_propertylist_set_comment(p,keyword,value);
318  }
319 }
320 
321 /*---------------------------------------------------------------------------*/
347 /*---------------------------------------------------------------------------*/
348 
349 extern void casu_sort(float **a, int n, int m) {
350  int increment,i,j,k;
351  float *t;
352 
353  t = cpl_malloc(m*sizeof(*t));
354 
355  increment = n/2;
356  while (increment > 0) {
357  for (i = increment; i < n; i++) {
358  j = i;
359  for (k = 0; k < m; k++)
360  t[k] = a[k][i];
361  while ((j >= increment) && (a[0][j-increment] > t[0])) {
362  for (k = 0; k < m; k++)
363  a[k][j] = a[k][j-increment];
364  j = j - increment;
365  }
366  for (k = 0; k < m; k++)
367  a[k][j] = t[k];
368  }
369  if (increment == 2)
370  increment = 1;
371  else
372  increment = (int)((float)increment/2.2);
373  }
374  cpl_free(t);
375 }
376 
377 /*---------------------------------------------------------------------------*/
397 /*---------------------------------------------------------------------------*/
398 
399 extern void casu_merge_propertylists(cpl_propertylist *p1,
400  cpl_propertylist *p2) {
401  int i;
402  const char *name;
403 
404  /* Return if either propertylist is NULL */
405 
406  if (p1 == NULL || p2 == NULL)
407  return;
408 
409  /* Erase any common properties so that you don't get a clash with
410  data types. Then copy each property from the second list into
411  the first one */
412 
413  for (i = 0; i < cpl_propertylist_get_size(p2); i++) {
414  name = cpl_property_get_name(cpl_propertylist_get(p2,i));
415  if (cpl_propertylist_has(p1,name))
416  cpl_propertylist_erase(p1,name);
417  }
418  cpl_propertylist_append(p1,p2);
419 
420 }
421 
422 /*---------------------------------------------------------------------------*/
443 /*---------------------------------------------------------------------------*/
444 
445 extern void casu_dummy_property(cpl_propertylist *p) {
446 
447  /* Check for silly input */
448 
449  if (p == NULL)
450  return;
451 
452  /* Add the property now */
453 
454  cpl_propertylist_update_bool(p,"ESO DRS IMADUMMY",TRUE);
455  cpl_propertylist_set_comment(p,"ESO DRS IMADUMMY",
456  "This is a dummy product");
457  return;
458 }
459 
460 /*---------------------------------------------------------------------------*/
483 /*---------------------------------------------------------------------------*/
484 
485 extern void casu_rename_property(cpl_propertylist *p, const char *oldname,
486  char *newname) {
487  cpl_propertylist *temp;
488  cpl_property *property;
489 
490  /* First get the old property. Note that we have to do this in a
491  particularly silly way since you cannot reference an individual property
492  in a propertylist by its name. You can only do it by its index
493  number. Remeber to change this when CPL comes to it's senses... */
494 
495  if (! cpl_propertylist_has(p,oldname))
496  return;
497  temp = cpl_propertylist_new();
498  cpl_propertylist_copy_property(temp,p,oldname);
499  property = cpl_propertylist_get(temp,0);
500 
501  /* Now change its name */
502 
503  cpl_property_set_name(property,newname);
504 
505  /* Now insert this into the propertylist and delete the old one */
506 
507  cpl_propertylist_append(p,temp);
508  cpl_propertylist_erase(p,oldname);
509  cpl_propertylist_delete(temp);
510 }
511 
512 /*---------------------------------------------------------------------------*/
531 /*---------------------------------------------------------------------------*/
532 
533 extern cpl_image *casu_dummy_image(casu_fits *model) {
534  cpl_image *im;
535 
536  /* Copy the input model image */
537 
538  im = cpl_image_duplicate(casu_fits_get_image(model));
539 
540  /* Now change it all to zeros */
541 
542  cpl_image_multiply_scalar(im,0.0);
543 
544  /* Return the result */
545 
546  return(im);
547 }
548 
549 /*---------------------------------------------------------------------------*/
568 /*---------------------------------------------------------------------------*/
569 
570 extern cpl_table *casu_dummy_catalogue(int type) {
571  int xcol,ycol;
572  cpl_table *tab;
573 
574  imcore_tabinit(NULL,&xcol,&ycol,type,&tab);
575  return(tab);
576 }
577 
578 /*---------------------------------------------------------------------------*/
596 /*---------------------------------------------------------------------------*/
597 
598 extern int casu_is_dummy(cpl_propertylist *p) {
599 
600  /* Check for silly input */
601 
602  if (p == NULL)
603  return(0);
604 
605  /* Check the propertylist and return the result */
606 
607  return(cpl_propertylist_has(p,"ESO DRS IMADUMMY"));
608 }
609 
610 /*---------------------------------------------------------------------------*/
650 /*---------------------------------------------------------------------------*/
651 
652 extern void casu_overexp(casu_fits **fitslist, int *n, int ndit, float lthr,
653  float hthr, int ditch, float *minv, float *maxv,
654  float *avev) {
655  int i,m;
656  cpl_image *im;
657  double val,dndit,sum;
658 
659  /* Loop for each of the fits items */
660 
661  dndit = (double)ndit;
662  m = 0;
663  *minv = 1.0e10;
664  *maxv = -1.0e10;
665  sum = 0.0;
666  for (i = 0; i < *n; i++) {
667  im = casu_fits_get_image(fitslist[i]);
668  val = cpl_image_get_median_window(im,500,500,1000,1000);
669  val /= dndit;
670  *minv = min(*minv,val);
671  *maxv = max(*maxv,val);
672  sum += val;
673  if (val > lthr && val < hthr) {
674  fitslist[m++] = fitslist[i];
675  } else {
676  if (ditch)
677  casu_fits_delete(fitslist[i]);
678  }
679  }
680  for (i = m; i < *n; i++)
681  fitslist[i] = NULL;
682  *avev = sum/(double)*n;
683  *n = m;
684 }
685 
686 /*---------------------------------------------------------------------------*/
711 /*---------------------------------------------------------------------------*/
712 
713 extern int casu_compare_dims(cpl_image *im1, cpl_image *im2) {
714 
715  if (cpl_image_get_size_x(im1) != cpl_image_get_size_x(im2) ||
716  cpl_image_get_size_y(im1) != cpl_image_get_size_y(im2))
717  return(CASU_FATAL);
718  else
719  return(CASU_OK);
720 }
721 
722 /*---------------------------------------------------------------------------*/
755 /*---------------------------------------------------------------------------*/
756 
757 extern int casu_gaincor_calc(cpl_frame *frame, int *n, float **cors,
758  int *status) {
759  float sum,val;
760  int i,ngood;
761  unsigned char *iflag;
762  cpl_propertylist *p;
763 
764  /* Inherited status */
765 
766  if (*status != CASU_OK)
767  return(*status);
768 
769  /* Find the number of extensions in the file and allocate some workspace
770  to hold the results. Allocate a small workspace to flag dummy
771  extensions */
772 
773  *n = cpl_frame_get_nextensions(frame);
774  *cors = cpl_malloc(*n*sizeof(float));
775  iflag = cpl_calloc(*n,sizeof(iflag));
776 
777  /* Ok, loop through the extensions and read the propertylists */
778 
779  sum = 0.0;
780  ngood = 0;
781  for (i = 0; i < *n; i++) {
782  p = cpl_propertylist_load(cpl_frame_get_filename(frame),(cpl_size)(i+1));
783  if (cpl_propertylist_has(p,"ESO DRS IMADUMMY")) {
784  iflag[i] = 1;
785  } else if (! cpl_propertylist_has(p,"ESO DRS MEDFLAT")) {
786  iflag[i] = 1;
787  } else {
788  val = cpl_propertylist_get_double(p,"ESO DRS MEDFLAT");
789  if (val == 0.0) {
790  iflag[i] = 1;
791  } else {
792  sum += val;
793  (*cors)[i] = val;
794  ngood++;
795  }
796  }
797  cpl_propertylist_delete(p);
798  }
799 
800  /* If any of them are good, then work out what the average is and
801  create the correction factors. If the image was a dummy or
802  there was no MEDFLAT keyword in the header, then just give it
803  a factor of 1 */
804 
805  if (ngood > 0)
806  sum /= (float)ngood;
807  for (i = 0; i < *n; i++) {
808  if (iflag[i] == 0) {
809  (*cors)[i] = sum/(*cors)[i];
810  } else {
811  (*cors)[i] = 1.0;
812  }
813  }
814  cpl_free(iflag);
815 
816  /* Get out of here */
817 
818  GOOD_STATUS
819 }
820 
821 /*---------------------------------------------------------------------------*/
847 /*---------------------------------------------------------------------------*/
848 
849 extern void casu_timestamp(char *out, int n) {
850  struct timeval tv;
851  struct tm *tm;
852  float sec;
853  struct tm result;
854  /* Get the Greenwich Mean Time */
855 
856  (void)gettimeofday(&tv,NULL);
857 
858  tm = gmtime_r(&(tv.tv_sec), &result);
859  sec = (float)tm->tm_sec + 1.0e-6*(float)tv.tv_usec;
860 
861  /* Now format it */
862 
863  (void)snprintf(out,n,"%04d-%02d-%02dT%02d:%02d:%07.4f",1900+tm->tm_year,
864  tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,sec);
865 }
866 
867 /*---------------------------------------------------------------------------*/
897 /*---------------------------------------------------------------------------*/
898 
899 extern int casu_catpars(cpl_frame *indx, char **catpath, char **catname) {
900  cpl_propertylist *p;
901  int status;
902  const char *fctid = "casu_catpars",*unk = "unknown";
903 
904  /* Initialise a few things */
905 
906  *catpath = NULL;
907  *catname = NULL;
908 
909  /* First get the full path to the indx file and make sure it exists */
910 
911  *catpath = cpl_strdup(cpl_frame_get_filename(indx));
912  if (access((const char *)*catpath,R_OK) != 0) {
913  cpl_msg_error(fctid,"Can't access index file %s",*catpath);
914  freespace(*catpath);
915  return(CASU_FATAL);
916  }
917 
918  /* Load the propertylist if you can. If you can't then signal a fatal
919  error since this probably means the whole file is messed up */
920 
921  if ((p = cpl_propertylist_load(cpl_frame_get_filename(indx),0)) == NULL) {
922  freespace(*catpath);
923  cpl_msg_error(fctid,"Can't load index file header %s",
924  cpl_frame_get_filename(indx));
925  return(CASU_FATAL);
926  }
927 
928  /* If there is a catalogue name in the header then send it back. If there
929  isn't then give a default name and send a warning */
930 
931  if (cpl_propertylist_has(p,"CATNAME")) {
932  *catname = cpl_strdup(cpl_propertylist_get_string(p,"CATNAME"));
933  status = CASU_OK;
934  } else {
935  *catname = cpl_strdup(unk);
936  cpl_msg_warning(fctid,"Property CATNAME not in index file header %s",
937  cpl_frame_get_filename(indx));
938  status = CASU_WARN;
939  }
940  freepropertylist(p);
941 
942  /* Get out of here */
943 
944  return(status);
945 }
946 
947 /*---------------------------------------------------------------------------*/
980 /*---------------------------------------------------------------------------*/
981 
982 extern int casu_fndmatch(float x, float y, float *xlist, float *ylist,
983  int nlist, float err) {
984  int isp,ifp,indx,i;
985  float errsq,errmin,dx,dy,poserr;
986 
987  /* Find lower limit index */
988 
989  isp = 0;
990  ifp = nlist - 1;
991  errsq = err*err;
992  indx = (isp + ifp)/2;
993  while (ifp-isp >= 2) {
994  if (ylist[indx] < y - err) {
995  isp = indx;
996  indx = (indx+ifp)/2;
997  } else if (ylist[indx] > y - err) {
998  ifp = indx;
999  indx = (indx+isp)/2;
1000  } else {
1001  isp = indx;
1002  break;
1003  }
1004  }
1005 
1006  /* Now find nearest one within limit */
1007 
1008  indx = -1;
1009  errmin = errsq;
1010  for (i = isp; i < nlist; i++) {
1011  if (ylist[i] > y+err)
1012  break;
1013  dx = x - xlist[i];
1014  dy = y - ylist[i];
1015  poserr = dx*dx + dy*dy;
1016  if (poserr < errsq) {
1017  if (poserr <= errmin) {
1018  indx = i;
1019  errmin = poserr;
1020  }
1021  }
1022  }
1023  return(indx);
1024 }
1025 
1026 /*---------------------------------------------------------------------------*/
1048 /*---------------------------------------------------------------------------*/
1049 
1050 extern int casu_findcol(cpl_propertylist *p, const char *col) {
1051 
1052  if (!strcmp(col,"X")) {
1053  if (cpl_propertylist_has(p,"ESO DRS XCOL"))
1054  return(cpl_propertylist_get_int(p,"ESO DRS XCOL"));
1055  else
1056  return(-1);
1057  } else if (!strcmp(col,"Y")) {
1058  if (cpl_propertylist_has(p,"ESO DRS YCOL"))
1059  return(cpl_propertylist_get_int(p,"ESO DRS YCOL"));
1060  else
1061  return(-1);
1062  }
1063  return(-1);
1064 }
1065 
1066 /*---------------------------------------------------------------------------*/
1086 /*---------------------------------------------------------------------------*/
1087 
1088 extern int casu_night_from_dateobs(char *dateobs) {
1089  int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
1090  int offs[] = {0,5,8,11,14,17};
1091  int lns[] = {4,2,2,2,2,7};
1092  int info[5],i,night;
1093  double ss;
1094  double utc,civil;
1095  char test[8];
1096 
1097  /* Format of dateobs: 2013-01-01T06:29:34.1397
1098  Start by getting the information from the input string */
1099 
1100  for (i = 0; i < 5; i++) {
1101  casu_substr(dateobs,offs[i],lns[i],test);
1102  info[i] = atoi(test);
1103  }
1104  casu_substr(dateobs,offs[5],lns[5],test);
1105  ss = atof(test);
1106 
1107  /* Form the UTC as a decimal. Subtract 16 hours to see where we are relative
1108  to noon on the advertised day. If it's negative, then this dateobs
1109  belongs to the previous night. */
1110 
1111  utc = info[3] + (double)info[4]/60.0 + ss/3600.0;
1112  civil = utc - 16.0;
1113  if (civil < 0.0) {
1114  info[2] -= 1;
1115  if (info[2] == 0) {
1116  info[1] -= 1;
1117  if (info[1] == 0) {
1118  info[1] = 12;
1119  info[0] -= 1;
1120  info[2] = days[info[1] - 1];
1121  } else if (info[1] == 2) {
1122  info[2] = days[1];
1123  if (info[0] % 4 == 0)
1124  info[2] += 1;
1125  } else {
1126  info[2] = days[info[1] - 1];
1127  }
1128  }
1129  }
1130 
1131  /* Now format the night...*/
1132 
1133  night = 10000*info[0] + 100*info[1] + info[2];
1134  return(night);
1135 }
1136 
1137 /*---------------------------------------------------------------------------*/
1161 /*---------------------------------------------------------------------------*/
1162 
1163 extern void casu_propertylist_update_float(cpl_propertylist *plist,
1164  const char *name, float val) {
1165  char *comment;
1166 
1167  /* First check whether the property exists. If it doesn't then just
1168  update it using the standard cpl_ routine and get out of here */
1169 
1170  if (cpl_propertylist_has(plist,name) == 0) {
1171  cpl_propertylist_update_float(plist,name,val);
1172  return;
1173  } else if (cpl_propertylist_get_type(plist,name) == CPL_TYPE_FLOAT) {
1174  cpl_propertylist_update_float(plist,name,val);
1175  return;
1176  }
1177 
1178  /* OK, it already has the property. So delete it and write a new one */
1179 
1180  comment = cpl_strdup(cpl_propertylist_get_comment(plist,name));
1181  cpl_propertylist_erase(plist,name);
1182  cpl_propertylist_update_float(plist,name,val);
1183  cpl_propertylist_set_comment(plist,name,comment);
1184  freespace(comment);
1185 }
1186 
1187 /*---------------------------------------------------------------------------*/
1210 /*---------------------------------------------------------------------------*/
1211 
1212 extern void casu_propertylist_update_double(cpl_propertylist *plist,
1213  const char *name, double val) {
1214  char *comment;
1215 
1216  /* First check whether the property exists. If it doesn't then just
1217  update it using the standard cpl_ routine and get out of here */
1218 
1219  if (cpl_propertylist_has(plist,name) == 0) {
1220  cpl_propertylist_update_double(plist,name,val);
1221  return;
1222  } else if (cpl_propertylist_get_type(plist,name) == CPL_TYPE_DOUBLE) {
1223  cpl_propertylist_update_double(plist,name,val);
1224  return;
1225  }
1226 
1227  /* OK, it already has the property, but it's the wrong type. So
1228  delete it and write a new one */
1229 
1230  comment = cpl_strdup(cpl_propertylist_get_comment(plist,name));
1231  cpl_propertylist_erase(plist,name);
1232  cpl_propertylist_update_double(plist,name,val);
1233  cpl_propertylist_set_comment(plist,name,comment);
1234  freespace(comment);
1235 }
1236 
1239 /*---------------------------------------------------------------------------*/
1263 /*---------------------------------------------------------------------------*/
1264 
1265 static void casu_substr(char *in, int ist, int len, char *out) {
1266  char *c;
1267 
1268  /* Get the starting place. Then do a copy of the correct number of
1269  characters */
1270 
1271  c = in + ist;
1272  (void)strncpy(out,c,len);
1273  out[len] = '\0';
1274 }
1275 
1276 /*---------------------------------------------------------------------------*/
1297 /*---------------------------------------------------------------------------*/
1298 
1299 static int casu_mjdcompare(const cpl_frame *f1, const cpl_frame *f2) {
1300  double mjd1,mjd2;
1301  cpl_propertylist *p;
1302 
1303  p = cpl_propertylist_load(cpl_frame_get_filename(f1),0);
1304  if (cpl_propertylist_has(p,"MJD-OBS") == 0) {
1305  cpl_propertylist_delete(p);
1306  p = cpl_propertylist_load(cpl_frame_get_filename(f1),1);
1307  }
1308  mjd1 = cpl_propertylist_get_double(p,"MJD-OBS");
1309  cpl_propertylist_delete(p);
1310  p = cpl_propertylist_load(cpl_frame_get_filename(f2),0);
1311  if (cpl_propertylist_has(p,"MJD-OBS") == 0) {
1312  cpl_propertylist_delete(p);
1313  p = cpl_propertylist_load(cpl_frame_get_filename(f1),1);
1314  }
1315  mjd2 = cpl_propertylist_get_double(p,"MJD-OBS");
1316  cpl_propertylist_delete(p);
1317  if (mjd1 < mjd2)
1318  return(-1);
1319  else if (mjd1 > mjd2)
1320  return(1);
1321  else
1322  return(0);
1323 }
1324 
1325 /*
1326 
1327 $Log: casu_utils.c,v $
1328 Revision 1.9 2015/11/27 12:06:41 jim
1329 Detabbed a few things
1330 
1331 Revision 1.8 2015/11/25 10:27:04 jim
1332 modified casu_catpars so that the catpath always contains a file
1333 name along with the full path
1334 
1335 Revision 1.7 2015/10/07 10:57:39 jim
1336 Modified casu_mjdcompare to look for the mjd keyword in the first extension
1337 if it's not present in the primary
1338 
1339 Revision 1.6 2015/09/22 13:12:41 jim
1340 fixed data type error in mjdcompare
1341 
1342 Revision 1.5 2015/09/22 09:37:44 jim
1343 casu_frameset_subgroup now sorts output by MJD
1344 
1345 Revision 1.4 2015/09/11 09:27:53 jim
1346 Fixed some problems with the docs
1347 
1348 Revision 1.3 2015/08/12 11:22:12 jim
1349 Modified calls to imcore procedures where necessary
1350 
1351 Revision 1.2 2015/08/07 13:06:54 jim
1352 Fixed copyright to ESO
1353 
1354 Revision 1.1.1.1 2015/06/12 10:44:32 jim
1355 Initial import
1356 
1357 Revision 1.12 2015/05/13 11:47:21 jim
1358 Added casu_propertylist_update_double and fixed some regular expressions
1359 
1360 Revision 1.11 2015/03/12 09:16:51 jim
1361 Modified to remove some compiler moans
1362 
1363 Revision 1.10 2015/02/14 12:34:15 jim
1364 Added casu_propertylist_update_float
1365 
1366 Revision 1.9 2015/01/29 11:56:27 jim
1367 modified comments
1368 
1369 Revision 1.8 2015/01/09 12:13:15 jim
1370 *** empty log message ***
1371 
1372 Revision 1.7 2014/12/11 12:23:33 jim
1373 new version
1374 
1375 Revision 1.6 2014/04/27 10:10:10 jim
1376 fixed catpars so that if something other than the 2mass or ppmxl index
1377 files is passed, then you get the full path to the one FITS catalogue
1378 
1379 Revision 1.5 2014/03/26 16:01:01 jim
1380 Removed calls to deprecated cpl routine
1381 
1382 Revision 1.4 2013/11/21 09:38:14 jim
1383 detabbed
1384 
1385 Revision 1.3 2013-10-24 09:27:45 jim
1386 Added casu_night_from_dateobs
1387 
1388 Revision 1.2 2013-09-30 18:13:53 jim
1389 Added casu_dummy_catalogue
1390 
1391 Revision 1.1.1.1 2013-08-27 12:07:48 jim
1392 Imported
1393 
1394 
1395 */
cpl_image * casu_fits_get_image(casu_fits *p)
Definition: casu_fits.c:436
char * casu_fits_get_filename(casu_fits *p)
Definition: casu_fits.c:646
char * casu_fits_get_fullname(casu_fits *p)
Definition: casu_fits.c:680
void casu_fits_delete(casu_fits *p)
Definition: casu_fits.c:364
cpl_image * casu_dummy_image(casu_fits *model)
Create a dummy image of zeros based on a model.
Definition: casu_utils.c:533
void casu_prov(cpl_propertylist *p, casu_fits **inlist, int n, int isextn)
Write provenance keywords.
Definition: casu_utils.c:287
int casu_findcol(cpl_propertylist *p, const char *col)
Find from catalogue header which are x,y columns.
Definition: casu_utils.c:1050
int casu_is_dummy(cpl_propertylist *p)
See if the header of an image or table says its a dummy.
Definition: casu_utils.c:598
cpl_frame * casu_frameset_subgroup_1(cpl_frameset *frameset, cpl_size *labels, cpl_size nlab, const char *tag)
Extract a frame of a given label from a frameset.
Definition: casu_utils.c:206
int casu_compare_tags(const cpl_frame *frame1, const cpl_frame *frame2)
Compare input tags.
Definition: casu_utils.c:96
void casu_merge_propertylists(cpl_propertylist *p1, cpl_propertylist *p2)
Merge two propertylists.
Definition: casu_utils.c:399
void casu_propertylist_update_double(cpl_propertylist *plist, const char *name, double val)
Definition: casu_utils.c:1212
long casu_getnpts(cpl_image *in)
Get the number of pixels in a 2d image.
Definition: casu_utils.c:243
int casu_catpars(cpl_frame *indx, char **catpath, char **catname)
Find the name of the standard catalogue and its location.
Definition: casu_utils.c:899
void casu_overexp(casu_fits **fitslist, int *n, int ndit, float lthr, float hthr, int ditch, float *minv, float *maxv, float *avev)
Remove over- or under-exposed images from a list.
Definition: casu_utils.c:652
void casu_propertylist_update_float(cpl_propertylist *plist, const char *name, float val)
Definition: casu_utils.c:1163
int casu_compare_dims(cpl_image *im1, cpl_image *im2)
Compare dimensions of two 2d images.
Definition: casu_utils.c:713
void casu_dummy_property(cpl_propertylist *p)
Set dummy property keyword.
Definition: casu_utils.c:445
void casu_timestamp(char *out, int n)
Create a timestamp string.
Definition: casu_utils.c:849
int casu_fndmatch(float x, float y, float *xlist, float *ylist, int nlist, float err)
Match the x,y coordinates of an object to one from a list.
Definition: casu_utils.c:982
int casu_night_from_dateobs(char *dateobs)
Use the dateobs value to work out the night of an observation.
Definition: casu_utils.c:1088
cpl_table * casu_dummy_catalogue(int type)
Create a dummy catalogue of a given type with no rows.
Definition: casu_utils.c:570
void casu_rename_property(cpl_propertylist *p, const char *oldname, char *newname)
Rename a property in a given propertylist.
Definition: casu_utils.c:485
cpl_frameset * casu_frameset_subgroup(cpl_frameset *frameset, cpl_size *labels, cpl_size nlab, const char *tag)
Extract a frameset from another frameset.
Definition: casu_utils.c:149
void casu_sort(float **a, int n, int m)
Sort a 2d array by the first column and co-sort the rest.
Definition: casu_utils.c:349
int casu_gaincor_calc(cpl_frame *frame, int *n, float **cors, int *status)
Work out gain corrections.
Definition: casu_utils.c:757
void imcore_tabinit(ap_t *ap, int *xcol, int *ycol, int cattype, cpl_table **tab)
Initialise catalogues.
Definition: create_table.c:62