Changeset 27435 for trunk/Ohana/src/libfits/header/F_modify.c
- Timestamp:
- Mar 24, 2010, 11:22:25 AM (16 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/libfits/header/F_modify.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana
-
Property svn:mergeinfo
set to
/branches/eam_branches/20091201/Ohana merged eligible /branches/eam_branches/largefiles.20100314/Ohana merged eligible
-
Property svn:mergeinfo
set to
-
trunk/Ohana/src/libfits/header/F_modify.c
r21059 r27435 2 2 # include <gfitsio.h> 3 3 4 // this is only valid for the regular and non-boolean fields 4 5 int gfits_modify (Header *header, char *field, char *mode, int N,...) { 5 6 … … 8 9 9 10 char comment[82], string[82], data[82]; 10 char *p, *q s, *qe;11 char *p, *qe; 11 12 va_list argp; 12 13 … … 29 30 30 31 /* is there enough space for 1 more line? */ 31 if (header[0]. size - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {32 header[0]. size += FT_RECORD_SIZE;33 REALLOCATE (header[0].buffer, char, header[0]. size);32 if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) { 33 header[0].datasize += FT_RECORD_SIZE; 34 REALLOCATE (header[0].buffer, char, header[0].datasize); 34 35 p = gfits_header_field (header, "END", 1); 35 36 if (p == NULL) return (FALSE); … … 50 51 51 52 /* write the numeric modes */ 52 if (!strcmp (mode, "%d")) snprintf (string, 81, "%-8s= %20d / %-s ", field, va_arg (argp, int), comment); 53 if (!strcmp (mode, "%u")) snprintf (string, 81, "%-8s= %20d / %-s ", field, va_arg (argp, unsigned), comment); 54 if (!strcmp (mode, "%ld")) snprintf (string, 81, "%-8s= %20ld / %-s ", field, va_arg (argp, long), comment); 55 if (!strcmp (mode, "%hd")) snprintf (string, 81, "%-8s= %20d / %-s ", field, va_arg (argp, int), comment); 56 if (!strcmp (mode, "%f")) snprintf (string, 81, "%-8s= %20.10f / %-s ", field, va_arg (argp, double), comment); 57 if (!strcmp (mode, "%lf")) snprintf (string, 81, "%-8s= %20.10f / %-s ", field, va_arg (argp, double), comment); 58 if (!strcmp (mode, "%e")) snprintf (string, 81, "%-8s= %20.10E / %-s ", field, va_arg (argp, double), comment); 59 if (!strcmp (mode, "%le")) snprintf (string, 81, "%-8s= %20.10E / %-s ", field, va_arg (argp, double), comment); 60 if (!strcmp (mode, "%g")) snprintf (string, 81, "%-8s= %20.10G / %-s ", field, va_arg (argp, double), comment); 61 if (!strcmp (mode, "%lg")) snprintf (string, 81, "%-8s= %20.10G / %-s ", field, va_arg (argp, double), comment); 53 if (!strcmp (mode, "%d")) snprintf (string, 81, "%-8s= %20d / %-s ", field, va_arg (argp, int), comment); 54 if (!strcmp (mode, "%ld")) snprintf (string, 81, "%-8s= %20ld / %-s ", field, va_arg (argp, long), comment); 55 if (!strcmp (mode, "%lld")) snprintf (string, 81, "%-8s= %20lld / %-s ", field, va_arg (argp, long long), comment); 56 if (!strcmp (mode, "%Ld")) snprintf (string, 81, "%-8s= %20lld / %-s ", field, va_arg (argp, long long), comment); 57 if (!strcmp (mode, "%u")) snprintf (string, 81, "%-8s= %20u / %-s ", field, va_arg (argp, unsigned), comment); 58 if (!strcmp (mode, "%lu")) snprintf (string, 81, "%-8s= %20lu / %-s ", field, va_arg (argp, unsigned long), comment); 59 if (!strcmp (mode, "%llu")) snprintf (string, 81, "%-8s= %20llu / %-s ", field, va_arg (argp, unsigned long long), comment); 60 if (!strcmp (mode, "%Lu")) snprintf (string, 81, "%-8s= %20llu / %-s ", field, va_arg (argp, unsigned long long), comment); 61 if (!strcmp (mode, "%hd")) snprintf (string, 81, "%-8s= %20d / %-s ", field, va_arg (argp, int), comment); 62 if (!strcmp (mode, "%f")) snprintf (string, 81, "%-8s= %20.10f / %-s ", field, va_arg (argp, double), comment); 63 if (!strcmp (mode, "%lf")) snprintf (string, 81, "%-8s= %20.10f / %-s ", field, va_arg (argp, double), comment); 64 if (!strcmp (mode, "%e")) snprintf (string, 81, "%-8s= %20.10E / %-s ", field, va_arg (argp, double), comment); 65 if (!strcmp (mode, "%le")) snprintf (string, 81, "%-8s= %20.10E / %-s ", field, va_arg (argp, double), comment); 66 if (!strcmp (mode, "%g")) snprintf (string, 81, "%-8s= %20.10G / %-s ", field, va_arg (argp, double), comment); 67 if (!strcmp (mode, "%lg")) snprintf (string, 81, "%-8s= %20.10G / %-s ", field, va_arg (argp, double), comment); 68 69 /* string value. Quotes must be at least 18 chars apart */ 70 if (!strcmp (mode, "%s")) { 71 strncpy (data, va_arg (argp, char *), 68); 72 snprintf (string, 81, "%-8s= '%-18s' / %-s ", field, data, comment); 73 } 74 75 strncpy (p, string, 80); 76 va_end (argp); 77 return (TRUE); 78 79 } 80 81 // alternate version for the special types (boolean, comments, COMMENT) 82 int gfits_modify_alt (Header *header, char *field, char *mode, int N,...) { 83 84 /* this function expects one more argument, the value to be written */ 85 /* this function is extremely similar to gfits_print, except it allows for changing an existing field. */ 86 87 char comment[82], string[82], data[82]; 88 char *p, *qs, *qe; 89 va_list argp; 90 91 va_start (argp, N); 92 bzero (data, 82); 93 bzero (string, 82); 94 bzero (comment, 82); 95 96 if (mode[0] != '%') { 97 fprintf (stderr, "gfits_print: weird mode: %s\n", mode); 98 return (FALSE); 99 } 100 101 /* find location of desired entry */ 102 p = gfits_header_field (header, field, N); 103 if (p == NULL) { 104 /* new entry, find the END of the header */ 105 p = gfits_header_field (header, "END", 1); 106 if (p == NULL) return (FALSE); 107 108 /* is there enough space for 1 more line? */ 109 if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) { 110 header[0].datasize += FT_RECORD_SIZE; 111 REALLOCATE (header[0].buffer, char, header[0].datasize); 112 p = gfits_header_field (header, "END", 1); 113 if (p == NULL) return (FALSE); 114 memset (p + FT_LINE_LENGTH, ' ', FT_RECORD_SIZE); 115 } 116 117 /* push END line back 1 */ 118 memmove ((p + FT_LINE_LENGTH), p, FT_LINE_LENGTH); 119 memset (p, ' ', FT_LINE_LENGTH); 120 } else { 121 /* old entry, save the comment region (is this skipping a character for non-strings?) */ 122 qe = gfits_keyword_end (p); 123 qe += 3; 124 qe = MIN (p + 80, qe); 125 strncpy (comment, qe, p + 80 - qe); 126 } 127 gfits_pad_ending (comment, ' ', 82); /* comment must contain spaces to the end */ 62 128 63 129 /* write the boolean mode */ … … 67 133 else 68 134 snprintf (string, 81, "%-8s= %18s F / %-s ", field, " ", comment); 69 }70 71 /* string value. Quotes must be at least 18 chars apart */72 if (!strcmp (mode, "%s")) {73 strncpy (data, va_arg (argp, char *), 68);74 snprintf (string, 81, "%-8s= '%-18s' / %-s ", field, data, comment);75 135 } 76 136
Note:
See TracChangeset
for help on using the changeset viewer.
