Changeset 34529
- Timestamp:
- Oct 8, 2012, 2:30:52 PM (14 years ago)
- Location:
- branches/eam_branches/ipp-20120905/Ohana/src/opihi
- Files:
-
- 6 edited
-
cmd.data/spline.c (modified) (2 diffs)
-
cmd.data/spline_commands.c (modified) (1 diff)
-
cmd.data/write_vectors.c (modified) (1 diff)
-
include/data.h (modified) (1 diff)
-
lib.data/SplineOps.c (modified) (4 diffs)
-
lib.shell/VectorIO.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20120905/Ohana/src/opihi/cmd.data/spline.c
r34526 r34529 4 4 int spline_create (int argc, char **argv); 5 5 int spline_apply (int argc, char **argv); 6 int spline_load (int argc, char **argv); 7 int spline_save (int argc, char **argv); 6 8 int spline_delete (int argc, char **argv); 7 9 int spline_getspline (int argc, char **argv); … … 11 13 {1, "create", spline_create, "create a spline"}, 12 14 {1, "apply", spline_apply, "apply a spline"}, 15 {1, "load", spline_load, "write a spline to a FITS file"}, 16 {1, "save", spline_save, "read a spline from a FITS file"}, 13 17 {1, "delete", spline_delete, "delete a spline"}, 14 18 }; -
branches/eam_branches/ipp-20120905/Ohana/src/opihi/cmd.data/spline_commands.c
r34526 r34529 69 69 } 70 70 71 int spline_save (int argc, char **argv) { 72 73 int N; 74 75 int APPEND = FALSE; 76 if ((N = get_argument (argc, argv, "-append"))) { 77 APPEND = TRUE; 78 remove_argument (N, &argc, argv); 79 } 80 81 if (argc != 3) { 82 gprint (GP_ERR, "USAGE: spline save (name) (filename) [-append]\n"); 83 return FALSE; 84 } 85 86 if (!SaveSpline(argv[2], argv[1], APPEND)) { 87 gprint (GP_ERR, "failed to save spline %s\n", argv[1]); 88 return (FALSE); 89 } 90 return TRUE; 91 } 92 93 int spline_load (int argc, char **argv) { 94 95 if (argc != 3) { 96 gprint (GP_ERR, "USAGE: spline load (name) (filename)\n"); 97 return FALSE; 98 } 99 100 if (!LoadSpline(argv[2], argv[1])) { 101 gprint (GP_ERR, "failed to load spline %s\n", argv[1]); 102 return (FALSE); 103 } 104 return TRUE; 105 } 106 71 107 int spline_delete (int argc, char **argv) { 72 108 -
branches/eam_branches/ipp-20120905/Ohana/src/opihi/cmd.data/write_vectors.c
r33963 r34529 99 99 } 100 100 101 /* open file for out uput */101 /* open file for output */ 102 102 if (append) { 103 103 f = fopen (argv[1], "a"); -
branches/eam_branches/ipp-20120905/Ohana/src/opihi/include/data.h
r34525 r34529 190 190 int DeleteSpline (Spline *spline); 191 191 void ListSplines (); 192 int SaveSpline (char *filename, char *name, int append); 193 int LoadSpline (char *filename, char *name); 192 194 193 195 /* hermitian functions */ -
branches/eam_branches/ipp-20120905/Ohana/src/opihi/lib.data/SplineOps.c
r34526 r34529 27 27 void InitSpline (Spline *spline, char *name, int Nknots) { 28 28 29 if (!spline[0].name) { 29 30 spline[0].name = strcreate (name); 30 31 spline[0].Nknots = Nknots; 31 } 32 spline[0].Nknots = Nknots; 33 34 if (spline[0].xk) { 35 REALLOCATE (spline[0].xk, opihi_flt, spline[0].Nknots); 36 REALLOCATE (spline[0].yk, opihi_flt, spline[0].Nknots); 37 REALLOCATE (spline[0].y2, opihi_flt, spline[0].Nknots); 38 } else { 32 39 ALLOCATE (spline[0].xk, opihi_flt, spline[0].Nknots); 33 40 ALLOCATE (spline[0].yk, opihi_flt, spline[0].Nknots); 34 41 ALLOCATE (spline[0].y2, opihi_flt, spline[0].Nknots); 35 memset (spline[0].xk, 0, spline[0].Nknots * sizeof(opihi_flt)); 36 memset (spline[0].yk, 0, spline[0].Nknots * sizeof(opihi_flt)); 37 memset (spline[0].y2, 0, spline[0].Nknots * sizeof(opihi_flt)); 42 } 43 memset (spline[0].xk, 0, spline[0].Nknots * sizeof(opihi_flt)); 44 memset (spline[0].yk, 0, spline[0].Nknots * sizeof(opihi_flt)); 45 memset (spline[0].y2, 0, spline[0].Nknots * sizeof(opihi_flt)); 38 46 } 39 47 … … 76 84 77 85 spline = FindSpline (name); 78 if (spline != NULL) return (spline); 86 if (spline != NULL) { 87 InitSpline (spline, name, Nknots); 88 return (spline); 89 } 79 90 80 91 N = Nsplines; … … 82 93 CHECK_REALLOCATE (splines, Spline *, NSPLINES, Nsplines, 16); 83 94 ALLOCATE (spline, Spline, 1); 95 spline->name = NULL; 96 spline->xk = NULL; 97 spline->yk = NULL; 98 spline->y2 = NULL; 84 99 InitSpline (spline, name, Nknots); 85 100 splines[N] = spline; … … 126 141 return; 127 142 } 143 144 // write the spline data to a FITS file. 145 int SaveSpline (char *filename, char *name, int append) { 146 147 Header header; 148 Matrix matrix; 149 Header theader; 150 FTable ftable; 151 152 Spline *myspline = FindSpline (name); 153 if (!myspline) { 154 gprint (GP_ERR, "can't find spline for write : %s\n", name); 155 return (FALSE); 156 } 157 158 FILE *f = NULL; 159 160 /* open file for output */ 161 if (append) { 162 f = fopen (filename, "a"); 163 } else { 164 f = fopen (filename, "w"); 165 } 166 if (f == (FILE *) NULL) { 167 gprint (GP_ERR, "can't open file for write : %s\n", filename); 168 return (FALSE); 169 } 170 171 gfits_create_table_header (&theader, "BINTABLE", name); 172 173 gfits_define_bintable_column (&theader, "D", "X_KNOT", NULL, NULL, 1.0, 0.0); 174 gfits_define_bintable_column (&theader, "D", "Y_KNOT", NULL, NULL, 1.0, 0.0); 175 gfits_define_bintable_column (&theader, "D", "DY2_DX", NULL, NULL, 1.0, 0.0); 176 177 // generate the output array that carries the data 178 gfits_create_table (&theader, &ftable); 179 180 gfits_set_bintable_column_reformat (&theader, &ftable, "X_KNOT", "double", myspline->xk, myspline->Nknots); 181 gfits_set_bintable_column_reformat (&theader, &ftable, "Y_KNOT", "double", myspline->yk, myspline->Nknots); 182 gfits_set_bintable_column_reformat (&theader, &ftable, "DY2_DX", "double", myspline->y2, myspline->Nknots); 183 184 if (!append) { 185 gfits_init_header (&header); 186 header.extend = TRUE; 187 188 gfits_create_header (&header); 189 gfits_create_matrix (&header, &matrix); 190 191 gfits_fwrite_header (f, &header); 192 gfits_fwrite_matrix (f, &matrix); 193 194 gfits_free_header (&header); 195 gfits_free_matrix (&matrix); 196 } 197 gfits_fwrite_Theader (f, &theader); 198 gfits_fwrite_table (f, &ftable); 199 200 gfits_free_header (&theader); 201 gfits_free_table (&ftable); 202 203 fclose (f); 204 fflush (f); 205 return (TRUE); 206 } 207 208 // read the spline data from a FITS file. 209 // these functions (LoadSpline, SaveSpline) should probably take spline pointers not names 210 int LoadSpline (char *filename, char *name) { 211 212 int i, Ncol; 213 off_t Nrow; 214 char type[16]; 215 216 Header theader; 217 FTable ftable; 218 219 FILE *f = NULL; 220 221 /* open file for input */ 222 f = fopen (filename, "r"); 223 if (f == (FILE *) NULL) { 224 gprint (GP_ERR, "can't open file for read : %s\n", filename); 225 return FALSE; 226 } 227 228 ftable.header = &theader; 229 230 // read the full table data into a buffer 231 if (!gfits_fread_ftable (f, &ftable, name)) { 232 fclose (f); 233 gprint (GP_ERR, "can't read FITS file : %s\n", filename); 234 return FALSE; 235 } 236 237 // XXX: need to handle case of spline data not existing... 238 239 // need to create and assign to flat-field correction 240 double *xk = gfits_get_bintable_column_data (&theader, &ftable, "X_KNOT", type, &Nrow, &Ncol); 241 assert (!strcmp(type, "double")); 242 243 // need to create and assign to flat-field correction 244 double *yk = gfits_get_bintable_column_data (&theader, &ftable, "Y_KNOT", type, &Nrow, &Ncol); 245 assert (!strcmp(type, "double")); 246 247 // need to create and assign to flat-field correction 248 double *y2 = gfits_get_bintable_column_data (&theader, &ftable, "DY2_DX", type, &Nrow, &Ncol); 249 assert (!strcmp(type, "double")); 250 251 Spline *myspline = CreateSpline (name, Nrow); 252 for (i = 0; i < Nrow; i++) { 253 myspline->xk[i] = xk[i]; 254 myspline->yk[i] = yk[i]; 255 myspline->y2[i] = y2[i]; 256 } 257 free (xk); 258 free (yk); 259 free (y2); 260 261 fclose (f); 262 return (TRUE); 263 } -
branches/eam_branches/ipp-20120905/Ohana/src/opihi/lib.shell/VectorIO.c
r33963 r34529 2 2 3 3 // write a set of vectors to a FITS file (vectors names become fits column names) 4 int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, char *format) { 5 4 int WriteVectorTable (Header *theader, FTable *ftable, char *extname, Vector **vec, int Nvec, char *format) { 5 6 int j; 7 6 8 char *tformat = NULL; 7 Header header; 8 Matrix matrix; 9 Header theader; 10 FTable ftable; 11 12 int j; 13 FILE *f = NULL; 14 15 /* open file for outuput */ 16 if (append) { 17 f = fopen (filename, "a"); 18 } else { 19 f = fopen (filename, "w"); 20 } 21 if (f == (FILE *) NULL) { 22 gprint (GP_ERR, "can't open file for write : %s\n", filename); 23 return (FALSE); 24 } 25 26 if (!append) { 27 gfits_init_header (&header); 28 header.extend = TRUE; 29 gfits_create_header (&header); 30 gfits_create_matrix (&header, &matrix); 31 } 32 33 gfits_create_table_header (&theader, "BINTABLE", extname); 9 10 gfits_create_table_header (theader, "BINTABLE", extname); 34 11 35 12 ALLOCATE (tformat, char, 2*Nvec); … … 71 48 // this somehow 72 49 for (j = 0; j < Nvec; j++) { 73 gfits_define_bintable_column ( &theader, &tformat[2*j], vec[j][0].name, NULL, NULL, 1.0, 0.0);50 gfits_define_bintable_column (theader, &tformat[2*j], vec[j][0].name, NULL, NULL, 1.0, 0.0); 74 51 } 75 52 free (tformat); 76 53 77 54 // generate the output array that carries the data 78 gfits_create_table ( &theader, &ftable);55 gfits_create_table (theader, ftable); 79 56 80 57 // add the vectors to the output array 81 58 for (j = 0; j < Nvec; j++) { 82 59 if (vec[j][0].type == OPIHI_FLT) { 83 gfits_set_bintable_column_reformat ( &theader, &ftable, vec[j][0].name, "double", vec[j][0].elements.Flt, vec[j][0].Nelements);60 gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "double", vec[j][0].elements.Flt, vec[j][0].Nelements); 84 61 } else { 85 gfits_set_bintable_column_reformat (&theader, &ftable, vec[j][0].name, "int", vec[j][0].elements.Int, vec[j][0].Nelements); 86 } 87 } 62 gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int", vec[j][0].elements.Int, vec[j][0].Nelements); 63 } 64 } 65 return (TRUE); 66 67 escape: 68 if (tformat) free (tformat); 69 return (FALSE); 70 } 71 72 // write a set of vectors to a FITS file (vectors names become fits column names) 73 int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, char *format) { 74 75 Header header; 76 Matrix matrix; 77 Header theader; 78 FTable ftable; 79 80 FILE *f = NULL; 81 82 /* open file for outuput */ 83 if (append) { 84 f = fopen (filename, "a"); 85 } else { 86 f = fopen (filename, "w"); 87 } 88 if (f == (FILE *) NULL) { 89 gprint (GP_ERR, "can't open file for write : %s\n", filename); 90 return (FALSE); 91 } 92 93 if (!WriteVectorTable (&theader, &ftable, extname, vec, Nvec, format)) goto escape; 88 94 89 95 if (!append) { 96 gfits_init_header (&header); 97 header.extend = TRUE; 98 gfits_create_header (&header); 99 gfits_create_matrix (&header, &matrix); 90 100 gfits_fwrite_header (f, &header); 91 101 gfits_fwrite_matrix (f, &matrix); … … 111 121 gfits_free_table (&ftable); 112 122 113 if (tformat) free (tformat);114 123 fclose (f); 115 124 fflush (f);
Note:
See TracChangeset
for help on using the changeset viewer.
