Re: 19990520: Incomplete file NetCDF

>To: netcdfgroup@xxxxxxxxxxxxxxxx,
>To: support@xxxxxxxxxxxxxxxx
>cc: hnv@xxxxxxxxxxxxxxxx
>From: jps@xxxxxxxxxxxxxxxx (John Sheldon)
>Subject: Incomplete file
>Organization: .
>Keywords: 199905201835.MAA25942

Hi John,

> I have a job which bombed before the NCCLOS call could be made made.
> I know it wrote many records before bombing, and the file is very
> large, but an NCDUMP shows 0 records written.  Is there a way to 
> "poke" a value into the header to allow me to access at least the
> data that already went to the file?  If so, would I subsequently be
> able to continue extending the file along the record dimension?

Yes, and yes, except that the last record might not be complete, so
might need to be rewritten.  Thus you may want to set the number of
records to 1 less than the number that appear to be written, unless
you can verify that the last record is OK.

In the current netCDF format (version 1, described in Appendix B of
the User's Guides) the number of records in a netCDF file is a
non-negative IEEE 32-bit integer that appears right after the first
four bytes of the file.  You could use an editor such as emacs that
permits editing a binary file to carefully change those four bytes to
represent the correct number of records as an IEEE 32-bit integer.

Alternatively, you could use the appended C program on a *copy* of the
file to change the number of records to the number specified on the
command line after the file name.

--Russ

_____________________________________________________________________

Russ Rew                                         UCAR Unidata Program
russ@xxxxxxxxxxxxxxxx                     http://www.unidata.ucar.edu


#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define SUCCESS 0
#define FAILURE 1

/*
 * Change second four bytes of specified file to specified IEEE integer.
 */
int
main(int nargs, char *args[]) {
  FILE *file;
  long lrecs;
  char *endptr = 0;
  char ieeebytes[4];

  if (nargs != 3) {
    fprintf(stderr, "usage: %s  filename  nrecs\n", args[0]);
    return FAILURE;
  }

  lrecs = strtol(args[2], &endptr, 10);
  if (endptr - args[2] != strlen(args[2])
      || lrecs < 0 ||
      lrecs >= INT_MAX) {
    fprintf(stderr, 
            "%s not representable as a 32-bin IEEE non-negative integer\n", 
            args[2]);
    return FAILURE;
  }

  ieeebytes[3] = lrecs % 256;
  lrecs /= 256;
  ieeebytes[2] = lrecs % 256;
  lrecs /= 256;
  ieeebytes[1] = lrecs % 256;
  lrecs /= 256;
  ieeebytes[0] = lrecs % 256;

  file = fopen(args[1], "r+");
  if(file == NULL) {
    perror("open failed");
    return FAILURE;
  }

  if (fseek(file, 4L, SEEK_SET) == -1) {
    perror("seek failed");
    return FAILURE;
  }

  if (fwrite(ieeebytes, 1, 4, file) != 4) {
    perror("fwrite failed");
    return FAILURE;
  }

  fclose(file);

  return SUCCESS;
}

  • 1999 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: