IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 24, 2010, 11:22:25 AM (16 years ago)
Author:
eugene
Message:

large update merging in changes for Ohana to support large files

Location:
trunk/Ohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/libfits/header/F_modify.c

    r21059 r27435  
    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 
     
    2930   
    3031    /* 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);
    3435      p = gfits_header_field (header, "END", 1);
    3536      if (p == NULL) return (FALSE);
     
    5051
    5152  /* 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)
     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 */
    62128
    63129  /* write the boolean mode */
     
    67133    else
    68134      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);
    75135  }
    76136
Note: See TracChangeset for help on using the changeset viewer.