forked from cbassa/sattools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fitsheader.c
64 lines (51 loc) · 1.08 KB
/
fitsheader.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define LIM 81
int fgetline(FILE *,char *,int);
void rtrim(char *);
int main(int argc,char *argv[])
{
char line[LIM];
FILE *fitsfile;
// Usage
if (argc<2) {
printf("Usage: %s <fitsfile>\n",argv[0]);
printf("\n\nOutputs the header of <fitsfile>\n");
return 1;
}
// Open file
fitsfile=fopen(argv[1],"r");
// Loop over file and output
while (fgetline(fitsfile,line,LIM)>0) {
rtrim(line);
printf("%s\n",line);
if (strcmp(line,"END")==0) break;
}
// Close file
fclose(fitsfile);
return 0;
}
// Read a line of maximum length int lim from file FILE into string s
int fgetline(FILE *file,char *s,int lim)
{
int c,i=0;
while (--lim > 0 && (c=fgetc(file)) != EOF && c != '\n')
s[i++] = c;
if (c == '\n')
s[i++] = c;
s[i] = '\0';
return i;
}
// Removes trailing blanks from string s
void rtrim(char *s)
{
int i,j=0,n;
n=strlen(s);
for (i=n;i>=0;i--)
if (s[i]!='\0' && s[i]!='\n')
if (!isspace(s[i]) && j==0) j=i;
s[++j]='\0';
return;
}