[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 20050504: LDM: PIPE-ing to scripts


Is the decoder a work-in-progress or not?  It, effectively, does just
what the FILE action does -- so if you're not going to modify it, then
you should use the FILE action, instead.

Steve Emmerson

------- Original Message

Date:    Thu, 12 May 2005 11:31:52 -0800
From:    "Scott Swank" <address@hidden>To:      Steve Emmerson <address@hidden
Subject: Re: 20050504: LDM: PIPE-ing to scripts

This is a multi-part message in MIME format.
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hey Steve,

> The above message contained the following:
> The compiled decoders that handle non-textual data-products typically
> read the data from the standard-input stream using either the fread() or
> read() functions.
> One can also write a perl(1) script that does something similar.
> I take it you're not familiar with UNIX programs that read non-textual
> data from standard-input.  You might want to consult with a UNIX person
> at your site.

I could use a little help.  I've written the following program (in C 
since I don't know perl) and for some reason it isn't correctly reading 
the entire product when it is binary.  I've used the getc/putc method 
for years when dealing with binaries and this is the first time it's 
failed.  So, I commented that out and did the fread/fwrite combination 
and it has the same affect.  Depending on the binary, I'm only getting 
about 1/3 of it before the program thinks it has hit eof.


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

int main(int argc, char *argv[]) {
FILE *fp;
int  c;
char filename[100];

   if (strlen(argv[1]) > 100) {
     printf ("Error: Filename %s over 100 characters in length. 
Exiting\n", argv[1]);
     return 1;

   printf ("File to be processed is %s\n", argv[1]);
   strcpy(filename, argv[1]);

   if ((fp=fopen(filename, "wb"))==NULL) {
      printf ("Failed to open file %s for writing! Exiting.\n",filename);
      return 1;
   printf ("Opened file %s for writing\n", filename);

   while(!feof(stdin)) {
     fread(&c, sizeof(c),1,stdin);
     fwrite(&c, sizeof(c),1,fp);
// This does the same thing as above for some reason...
//  while ((c = getchar()) != EOF)
//    fputc(c, fp);

   printf ("Finished Processing file %s\n", filename);
   fclose (fp);
   return 0;


Content-Type: text/x-vcard; charset=utf-8;
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;

fn:Scott Swank
title:Computer Program Manager


------- End of Original Message

NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.