- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/Ohana
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/Ohana merged eligible /branches/eam_branches/Ohana.20100407 27635-27772 /branches/pap_delete/Ohana 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/tap_branches/Ohana/src/libfits/header/F_print.c
r7054 r27838 2 2 # include <gfitsio.h> 3 3 4 // this only prints the regular and non-boolean fields 4 5 int gfits_print (Header *header, char *field, char *mode, int N,...) { 6 7 /* this function expects one more argument, the value to be written */ 8 9 static char blank[] = " "; 10 char string[82], line[80]; 11 char *p; 12 va_list argp; 13 14 va_start (argp, N); 15 16 if (mode[0] != '%') { 17 fprintf (stderr, "gfits_print: weird mode: %s\n", mode); 18 return (FALSE); 19 } 20 21 /* this is supposed to create a new field, not modify an old one. */ 22 p = gfits_header_field (header, field, N); 23 if (p != NULL) return (FALSE); 24 25 /* find the END of the header */ 26 p = gfits_header_field (header, "END", 1); 27 if (p == NULL) return (FALSE); 28 29 /* is there enough space for 1 more line? */ 30 if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) { 31 header[0].datasize += FT_RECORD_SIZE; 32 REALLOCATE (header[0].buffer, char, header[0].datasize); 33 /* re-find the "END" marker, in case new memory block is used */ 34 p = gfits_header_field (header, "END", 1); 35 if (p == NULL) return (FALSE); 36 memset (p + FT_LINE_LENGTH, ' ', FT_RECORD_SIZE); 37 } 38 39 /* push END line back 1 */ 40 memmove ((p + FT_LINE_LENGTH), p, FT_LINE_LENGTH); 41 memset (p, ' ', FT_LINE_LENGTH); 42 43 /* write the new FITS card, setting the comment to be blank */ 44 /* in these lines, the value field will expand as needed, forcing out the comment 45 the total line is limited by snprintf to only 80 chars + EOL */ 46 47 /* write the numeric modes */ 48 if (!strcmp (mode, "%d")) { snprintf (string, 81, "%-8s= %20d / %46s ", field, va_arg (argp, int), blank); } 49 if (!strcmp (mode, "%ld")) { snprintf (string, 81, "%-8s= %20ld / %46s ", field, va_arg (argp, long), blank); } 50 if (!strcmp (mode, "%lld")){ snprintf (string, 81, "%-8s= %20lld / %46s ", field, va_arg (argp, long long), blank); } 51 if (!strcmp (mode, "%Ld")) { snprintf (string, 81, "%-8s= %20lld / %46s ", field, va_arg (argp, long long), blank); } 52 if (!strcmp (mode, "%u")) { snprintf (string, 81, "%-8s= %20u / %46s ", field, va_arg (argp, unsigned), blank); } 53 if (!strcmp (mode, "%lu")) { snprintf (string, 81, "%-8s= %20lu / %46s ", field, va_arg (argp, unsigned long), blank); } 54 if (!strcmp (mode, "%llu")){ snprintf (string, 81, "%-8s= %20llu / %46s ", field, va_arg (argp, unsigned long long), blank); } 55 if (!strcmp (mode, "%Lu")) { snprintf (string, 81, "%-8s= %20llu / %46s ", field, va_arg (argp, unsigned long long), blank); } 56 if (!strcmp (mode, "%hd")) { snprintf (string, 81, "%-8s= %20d / %46s ", field, va_arg (argp, int), blank); } 57 if (!strcmp (mode, "%f")) { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double), blank); } 58 if (!strcmp (mode, "%lf")) { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double), blank); } 59 if (!strcmp (mode, "%e")) { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double), blank); } 60 if (!strcmp (mode, "%le")) { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double), blank); } 61 if (!strcmp (mode, "%g")) { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double), blank); } 62 if (!strcmp (mode, "%lg")) { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double), blank); } 63 64 /* string value. Quotes must be at least 18 chars apart. Longer lines will this should be fixed to allow arbitrary string lengths, up to 69 chars */ 65 if (!strcmp (mode, "%s")) { 66 strcpy (line, va_arg (argp, char *)); 67 line[68] = 0; 68 snprintf (string, 81, "%-8s= '%-18s' / %46s ", field, line, blank); 69 } 70 71 strncpy (p, string, 80); 72 73 va_end (argp); 74 return (TRUE); 75 76 } 77 78 // alternate version for the special types (boolean, comments, COMMENT) 79 int gfits_print_alt (Header *header, char *field, char *mode, int N,...) { 5 80 6 81 /* this function expects one more argument, the value to be written */ … … 27 102 28 103 /* is there enough space for 1 more line? */ 29 if (header[0]. size - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {30 header[0]. size += FT_RECORD_SIZE;31 REALLOCATE (header[0].buffer, char, header[0]. size);104 if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) { 105 header[0].datasize += FT_RECORD_SIZE; 106 REALLOCATE (header[0].buffer, char, header[0].datasize); 32 107 /* re-find the "END" marker, in case new memory block is used */ 33 108 p = gfits_header_field (header, "END", 1); … … 40 115 memset (p, ' ', FT_LINE_LENGTH); 41 116 42 /* write the new FITS card, setting the comment to be blank */43 /* in these lines, the value field will expand as needed, forcing out the comment44 the total line is limited by snprintf to only 80 chars + EOL */45 46 /* write the numeric modes */47 if (!strcmp (mode, "%d")) { snprintf (string, 81, "%-8s= %20d / %46s ", field, va_arg (argp, int), blank); }48 if (!strcmp (mode, "%u")) { snprintf (string, 81, "%-8s= %20d / %46s ", field, va_arg (argp, unsigned), blank); }49 if (!strcmp (mode, "%ld")) { snprintf (string, 81, "%-8s= %20ld / %46s ", field, va_arg (argp, long), blank); }50 if (!strcmp (mode, "%hd")) { snprintf (string, 81, "%-8s= %20d / %46s ", field, va_arg (argp, int), blank); }51 if (!strcmp (mode, "%f")) { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double), blank); }52 if (!strcmp (mode, "%lf")) { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double), blank); }53 if (!strcmp (mode, "%e")) { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double), blank); }54 if (!strcmp (mode, "%le")) { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double), blank); }55 if (!strcmp (mode, "%g")) { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double), blank); }56 if (!strcmp (mode, "%lg")) { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double), blank); }57 58 117 /* write the boolean mode */ 59 118 if (!strcmp (mode, "%t")) { … … 63 122 else 64 123 snprintf (string, 81, "%-8s= %18s F / %46s ", field, blank, blank); 65 }66 67 /* string value. Quotes must be at least 18 chars apart. Longer lines will this should be fixed to allow arbitrary string lengths, up to 69 chars */68 if (!strcmp (mode, "%s")) {69 strcpy (line, va_arg (argp, char *));70 line[68] = 0;71 snprintf (string, 81, "%-8s= '%-18s' / %46s ", field, line, blank);72 124 } 73 125
Note:
See TracChangeset
for help on using the changeset viewer.
