IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 19, 2010, 5:35:25 PM (16 years ago)
Author:
eugene
Message:

update ohana formatting functions to check format and associated types; fixes derived from format checks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/largefiles.20100314/Ohana/src/libfits/header/F_modify.c

    r27295 r27368  
    22# include <gfitsio.h>
    33
     4// this is only valid for the regular and non-boolean fields
    45int gfits_modify (Header *header, char *field, char *mode, int N,...) {
    56 
     
    89
    910  char comment[82], string[82], data[82];
    10   char *p, *qs, *qe;
     11  char *p, *qe;
    1112  va_list argp;
    1213 
     
    6667  if (!strcmp (mode, "%lg"))  snprintf (string, 81, "%-8s= %20.10G / %-s ", field, va_arg (argp, double),             comment);
    6768
     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)
     82int 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 */
     128
    68129  /* write the boolean mode */
    69130  if (!strcmp (mode, "%t")) {
     
    72133    else
    73134      snprintf (string, 81, "%-8s= %18s F / %-s ", field, " ", comment);
    74   }
    75 
    76   /* string value.  Quotes must be at least 18 chars apart */
    77   if (!strcmp (mode, "%s")) {
    78     strncpy (data, va_arg (argp, char *), 68);
    79     snprintf (string, 81, "%-8s= '%-18s' / %-s ", field, data, comment);
    80135  }
    81136
Note: See TracChangeset for help on using the changeset viewer.