miriad 4.1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +103 -0
- data/Rakefile +82 -0
- data/ext/bug.c +341 -0
- data/ext/dio.c +317 -0
- data/ext/extconf.rb +49 -0
- data/ext/headio.c +835 -0
- data/ext/hio.c +1515 -0
- data/ext/hio.h +48 -0
- data/ext/interface.c +74 -0
- data/ext/io.h +56 -0
- data/ext/key.c +934 -0
- data/ext/maskio.c +398 -0
- data/ext/maxdimc.h.in +9 -0
- data/ext/miriad.h +371 -0
- data/ext/miriad.i +464 -0
- data/ext/miriad_ruby.c +602 -0
- data/ext/miriad_ruby.i +443 -0
- data/ext/miriad_wrap.c +4210 -0
- data/ext/narray_ruby.swg +59 -0
- data/ext/pack.c +639 -0
- data/ext/scrio.c +132 -0
- data/ext/sysdep.h +185 -0
- data/ext/uvio.c +4934 -0
- data/ext/xyio.c +476 -0
- data/ext/xyzio.c +2020 -0
- data/lib/miriad.rb +564 -0
- metadata +93 -0
data/ext/dio.c
ADDED
@@ -0,0 +1,317 @@
|
|
1
|
+
/************************************************************************/
|
2
|
+
/* DIO -- Disk I/O routines for a Unix Enviromment. */
|
3
|
+
/* */
|
4
|
+
/* Makes calls to the UNIX I/O and directory searching routines. */
|
5
|
+
/* All of these get implemented in a pretty straight forward way. */
|
6
|
+
/* */
|
7
|
+
/* Portability Notes: */
|
8
|
+
/* These routines are intended to run on BSD UNIX and UNICOS. No */
|
9
|
+
/* attempt has been made to make them any more portable than this. */
|
10
|
+
/* There are some minor differences between the two, which are */
|
11
|
+
/* selectively compiled depending if BSD is defined. */
|
12
|
+
/* 1. The mkdir system service is not present on some systems, and */
|
13
|
+
/* may require superuser priveleges to implement using mknod. */
|
14
|
+
/* In this case, use 'popen("mkdir ...","r",...)' */
|
15
|
+
/* 2. The Berkeley directory searching routines are used. These */
|
16
|
+
/* can be relatively simply implemented in other UNIX's. */
|
17
|
+
/* */
|
18
|
+
/* History: */
|
19
|
+
/* dakr-ages rjs Original version adapted from werong. */
|
20
|
+
/* 31-oct-89 pjt _trace_ added as defined() option, errno */
|
21
|
+
/* -nov-89 rjs dexpand_c routine */
|
22
|
+
/* 6-dec-89 pjt extended bug call */
|
23
|
+
/* 26-jan-90 rjs Reincluded <stdio.h>, which is needed by Unicos. */
|
24
|
+
/* 27-apr-90 rjs Added ddelete_c routine. */
|
25
|
+
/* 26-aug-93 rjs Added hrmdir. */
|
26
|
+
/* 5-nov-94 rjs Improve POSIX compliance. */
|
27
|
+
/* 26-Oct-95 rjs Honour TMPDIR environment variable, if set. */
|
28
|
+
/* 10-Jan-96 rjs Make sure scratch file names are unique. */
|
29
|
+
/* 17-jun-02 pjt MIR4 changes, and proper prototypes */
|
30
|
+
/* 5-nov-04 jwr Changed a few size_t to ssize_t or off_t */
|
31
|
+
/* 3-jan-05 pjt ssize casting to appease the compiler */
|
32
|
+
/* use SSIZE_MAX to protect from bad casting ? */
|
33
|
+
/* 2-mar-05 pjt template->templat for C++, just in case */
|
34
|
+
/************************************************************************/
|
35
|
+
|
36
|
+
#include <stddef.h>
|
37
|
+
#include <stdlib.h>
|
38
|
+
#include <string.h>
|
39
|
+
#include <sys/types.h>
|
40
|
+
#include <sys/stat.h>
|
41
|
+
#include <limits.h>
|
42
|
+
#include <unistd.h>
|
43
|
+
#include <fcntl.h>
|
44
|
+
#include <dirent.h>
|
45
|
+
#define direct dirent
|
46
|
+
#include <stdio.h>
|
47
|
+
#include <errno.h>
|
48
|
+
|
49
|
+
#include "miriad.h"
|
50
|
+
|
51
|
+
#define MAXPATH 128
|
52
|
+
|
53
|
+
#ifndef NULL
|
54
|
+
# define NULL 0
|
55
|
+
#endif
|
56
|
+
|
57
|
+
#define Malloc(x) malloc((unsigned)(x))
|
58
|
+
#define Strcat (void)strcat
|
59
|
+
#define Strcpy (void)strcpy
|
60
|
+
#define Lseek(a,b,c) (off_t)lseek(a,(off_t)(b),c)
|
61
|
+
|
62
|
+
struct dent {
|
63
|
+
char path[MAXPATH];
|
64
|
+
DIR *dir;
|
65
|
+
};
|
66
|
+
/************************************************************************/
|
67
|
+
void ddelete_c(char *path,int *iostat)
|
68
|
+
/*
|
69
|
+
This deletes a file, and returns an i/o status.
|
70
|
+
------------------------------------------------------------------------*/
|
71
|
+
{
|
72
|
+
*iostat = ( unlink(path) ? errno : 0 );
|
73
|
+
}
|
74
|
+
/************************************************************************/
|
75
|
+
void dtrans_c(char *inpath,char *outpath,int *iostat)
|
76
|
+
/*
|
77
|
+
Translate a directory spec into the local format. On a UNIX machine,
|
78
|
+
this merely involves adding a slash to the end of the name.
|
79
|
+
|
80
|
+
Input:
|
81
|
+
inpath Input directory spec.
|
82
|
+
Output:
|
83
|
+
outpath Output directory spec.
|
84
|
+
iostat Error return.
|
85
|
+
------------------------------------------------------------------------*/
|
86
|
+
{
|
87
|
+
char *s;
|
88
|
+
|
89
|
+
*iostat = 0;
|
90
|
+
Strcpy(outpath,inpath);
|
91
|
+
s = outpath + strlen(outpath) - 1;
|
92
|
+
if(*s != '/')Strcat(outpath,"/");
|
93
|
+
}
|
94
|
+
/************************************************************************/
|
95
|
+
void dmkdir_c(char *path,int *iostat)
|
96
|
+
/*
|
97
|
+
Create a directory. This might be a privileged operation on some systems,
|
98
|
+
in which case dmkdir_c will have to work by using popen(3) and mkdir(1).
|
99
|
+
|
100
|
+
Input:
|
101
|
+
path Name of directory to create. This will usually have a
|
102
|
+
trailing slash, which needs to be trimmed off.
|
103
|
+
Output:
|
104
|
+
iostat Errror status.
|
105
|
+
------------------------------------------------------------------------*/
|
106
|
+
{
|
107
|
+
char Path[MAXPATH],*s;
|
108
|
+
|
109
|
+
/* Usually the path will end in a '/', so get rid of it. */
|
110
|
+
|
111
|
+
Strcpy(Path,path);
|
112
|
+
s = Path + strlen(Path) - 1;
|
113
|
+
if(*s == '/')*s = 0;
|
114
|
+
|
115
|
+
*iostat = 0;
|
116
|
+
if(mkdir(Path,0777) < 0) *iostat = errno;
|
117
|
+
}
|
118
|
+
/************************************************************************/
|
119
|
+
void drmdir_c(char *path,int *iostat)
|
120
|
+
/*
|
121
|
+
Delete a directory. This might be a privileged operation on some systems,
|
122
|
+
in which case drmdir_c will have to work by using popen(3) and rmdir(1).
|
123
|
+
|
124
|
+
Input:
|
125
|
+
path Name of directory to remove. This will usually have a
|
126
|
+
trailing slash, which needs to be trimmed off.
|
127
|
+
Output:
|
128
|
+
iostat Errror status.
|
129
|
+
------------------------------------------------------------------------*/
|
130
|
+
{
|
131
|
+
char Path[MAXPATH],*s;
|
132
|
+
|
133
|
+
/* Usually the path will end in a '/', so get rid of it. */
|
134
|
+
|
135
|
+
Strcpy(Path,path);
|
136
|
+
s = Path + strlen(Path) - 1;
|
137
|
+
if(*s == '/')*s = 0;
|
138
|
+
|
139
|
+
*iostat = 0;
|
140
|
+
if(rmdir(Path) < 0) *iostat = errno;
|
141
|
+
}
|
142
|
+
/************************************************************************/
|
143
|
+
void dopen_c(int *fd,char *name,char *status,off_t *size,int *iostat)
|
144
|
+
/*
|
145
|
+
Open a file.
|
146
|
+
Input:
|
147
|
+
name Name of file to create (in host format).
|
148
|
+
status Either "read", "write", "append" or "scratch".
|
149
|
+
"scratch" files are using $TMPDIR, if present, else current.
|
150
|
+
|
151
|
+
Output:
|
152
|
+
fd File descriptor.
|
153
|
+
size Size of file.
|
154
|
+
iostat I/O status.
|
155
|
+
|
156
|
+
------------------------------------------------------------------------*/
|
157
|
+
{
|
158
|
+
int is_scratch,pid,flags=0;
|
159
|
+
char *s,sname[MAXPATH];
|
160
|
+
|
161
|
+
is_scratch = *iostat = 0;
|
162
|
+
s = name;
|
163
|
+
|
164
|
+
if (!strcmp(status,"read")) flags = O_RDONLY;
|
165
|
+
else if(!strcmp(status,"write")) flags = O_CREAT|O_TRUNC|O_RDWR;
|
166
|
+
else if(!strcmp(status,"append")) flags = O_CREAT|O_RDWR;
|
167
|
+
else if(!strcmp(status,"scratch")){
|
168
|
+
flags = O_CREAT|O_TRUNC|O_RDWR;
|
169
|
+
is_scratch = 1;
|
170
|
+
s = getenv("TMPDIR");
|
171
|
+
pid = getpid();
|
172
|
+
if(s != NULL)sprintf(sname,"%s/%s.%d",s,name,pid);
|
173
|
+
else sprintf(sname,"%s.%d",name,pid);
|
174
|
+
s = sname;
|
175
|
+
} else bug_c('f',"dopen_c: Unrecognised status");
|
176
|
+
#ifdef O_LARGEFILE
|
177
|
+
flags |= O_LARGEFILE;
|
178
|
+
#endif
|
179
|
+
if((*fd = open(s,flags,0644)) < 0){*iostat = errno; return;}
|
180
|
+
*size = Lseek(*fd,0,SEEK_END);
|
181
|
+
|
182
|
+
/* If its a scratch file, unlink it now, so that the file will disappear
|
183
|
+
when it is closed (or this program crashes). */
|
184
|
+
|
185
|
+
if(is_scratch)(void)unlink(s);
|
186
|
+
}
|
187
|
+
/************************************************************************/
|
188
|
+
void dclose_c(int fd,int *iostat)
|
189
|
+
/*
|
190
|
+
This subroutine does unbelievably complex stuff.
|
191
|
+
------------------------------------------------------------------------*/
|
192
|
+
{
|
193
|
+
*iostat = ( close(fd) < 0 ? errno : 0 );
|
194
|
+
}
|
195
|
+
/************************************************************************/
|
196
|
+
void dread_c(int fd, char *buffer,off_t offset,size_t length,int *iostat)
|
197
|
+
/*
|
198
|
+
Read from a file.
|
199
|
+
------------------------------------------------------------------------*/
|
200
|
+
{
|
201
|
+
ssize_t nread;
|
202
|
+
#ifdef debug
|
203
|
+
if (length >= SSIZE_MAX) bugv_c('f',"dread_c: possible incomplete read");
|
204
|
+
#endif
|
205
|
+
if(Lseek(fd,offset,SEEK_SET) < 0) { *iostat = errno; return; }
|
206
|
+
nread = read(fd,buffer,length);
|
207
|
+
if(nread < 0) *iostat = errno;
|
208
|
+
else if(nread != (ssize_t) length) *iostat = EIO;
|
209
|
+
}
|
210
|
+
/************************************************************************/
|
211
|
+
void dwrite_c(int fd, char *buffer,off_t offset,size_t length,int *iostat)
|
212
|
+
/*
|
213
|
+
Write to a file.
|
214
|
+
------------------------------------------------------------------------*/
|
215
|
+
{
|
216
|
+
ssize_t nwrite;
|
217
|
+
#ifdef debug
|
218
|
+
if (length >= SSIZE_MAX) bugv_c('f',"dwrite_c: possible incomplete write");
|
219
|
+
#endif
|
220
|
+
if(Lseek(fd,offset,SEEK_SET) < 0) { *iostat = errno; return; }
|
221
|
+
nwrite = write(fd,buffer,length);
|
222
|
+
if(nwrite < 0) *iostat = errno;
|
223
|
+
else if(nwrite != (ssize_t) length) *iostat = EIO;
|
224
|
+
}
|
225
|
+
/************************************************************************/
|
226
|
+
/*ARGSUSED*/
|
227
|
+
void dwait_c(int fd,int *iostat)
|
228
|
+
/*
|
229
|
+
This nominally waits for i/o to a file to finish. Things work synchronously
|
230
|
+
in UNIX.
|
231
|
+
------------------------------------------------------------------------*/
|
232
|
+
{
|
233
|
+
*iostat = 0;
|
234
|
+
}
|
235
|
+
/************************************************************************/
|
236
|
+
int dexpand_c(char *templat,char *output,int length)
|
237
|
+
/*
|
238
|
+
This expands wildcards, matching them with files.
|
239
|
+
|
240
|
+
Input:
|
241
|
+
templat The input character string, containing the wildcards.
|
242
|
+
length The length of the output buffer.
|
243
|
+
Output:
|
244
|
+
output All the files matching "template". Filenames are separated
|
245
|
+
by commas.
|
246
|
+
------------------------------------------------------------------------*/
|
247
|
+
{
|
248
|
+
FILE *fd;
|
249
|
+
char line[MAXPATH],*s;
|
250
|
+
int l;
|
251
|
+
|
252
|
+
Strcpy(line,"echo ");
|
253
|
+
Strcat(line,templat);
|
254
|
+
fd = popen(line,"r");
|
255
|
+
if(fd == NULL) return(-1);
|
256
|
+
s = output;
|
257
|
+
while(fgets(s,length,fd)){
|
258
|
+
l = strlen(s);
|
259
|
+
if( length-l <= 1 ){(void)pclose(fd); return(-1);}
|
260
|
+
*(s+l-1) = ',';
|
261
|
+
s += l;
|
262
|
+
length -= l;
|
263
|
+
}
|
264
|
+
if(s != output) *--s = 0;
|
265
|
+
(void)pclose(fd);
|
266
|
+
return(s-output);
|
267
|
+
}
|
268
|
+
/************************************************************************/
|
269
|
+
void dopendir_c(char **contxt,char *path)
|
270
|
+
/*
|
271
|
+
Open a directory, and prepare to read from it.
|
272
|
+
------------------------------------------------------------------------*/
|
273
|
+
{
|
274
|
+
struct dent *d;
|
275
|
+
|
276
|
+
*contxt = Malloc(sizeof(struct dent));
|
277
|
+
d = (struct dent *)*contxt;
|
278
|
+
Strcpy(d->path,path);
|
279
|
+
d->dir = opendir(path);
|
280
|
+
}
|
281
|
+
/************************************************************************/
|
282
|
+
void dclosedir_c(char *contxt)
|
283
|
+
/*
|
284
|
+
Close a directory.
|
285
|
+
------------------------------------------------------------------------*/
|
286
|
+
{
|
287
|
+
struct dent *d;
|
288
|
+
d = (struct dent *)contxt;
|
289
|
+
(void)closedir(d->dir);
|
290
|
+
free(contxt);
|
291
|
+
}
|
292
|
+
/************************************************************************/
|
293
|
+
/*ARGSUSED*/
|
294
|
+
void dreaddir_c(char *contxt,char *path,int length)
|
295
|
+
/*
|
296
|
+
Read a directory entry.
|
297
|
+
------------------------------------------------------------------------*/
|
298
|
+
{
|
299
|
+
struct dent *d;
|
300
|
+
struct direct *dp;
|
301
|
+
struct stat buf;
|
302
|
+
char npath[MAXPATH];
|
303
|
+
|
304
|
+
d = (struct dent *)contxt;
|
305
|
+
|
306
|
+
do dp = readdir(d->dir);
|
307
|
+
while(dp != NULL && (!strcmp(dp->d_name,".") || !strcmp(dp->d_name,"..")));
|
308
|
+
|
309
|
+
if(dp == NULL)
|
310
|
+
*path = 0;
|
311
|
+
else{
|
312
|
+
Strcpy(path,dp->d_name);
|
313
|
+
Strcpy(npath,d->path); Strcat(npath,path);
|
314
|
+
(void)stat(npath,&buf);
|
315
|
+
if(S_IFDIR & buf.st_mode)Strcat(path,"/");
|
316
|
+
}
|
317
|
+
}
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#$Id: extconf.rb 895 2008-04-17 21:30:28Z davidm $
|
2
|
+
#
|
3
|
+
# Usage: ruby extconf.rb --with-narray-include=/path/to/narray.h
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'rbconfig'
|
7
|
+
|
8
|
+
# Disable RPATH before requiring 'mkmf'
|
9
|
+
Config::CONFIG['RPATHFLAG']=''
|
10
|
+
|
11
|
+
require 'mkmf'
|
12
|
+
|
13
|
+
sitearchdir = Config::CONFIG['sitearchdir']
|
14
|
+
dir_config('narray',sitearchdir,sitearchdir)
|
15
|
+
|
16
|
+
na_gemspec=Gem.searcher.find('narray')
|
17
|
+
if na_gemspec
|
18
|
+
na_dir=File.join(na_gemspec.full_gem_path, na_gemspec.require_path)
|
19
|
+
$CPPFLAGS = " -I#{na_dir} "+$CPPFLAGS
|
20
|
+
else
|
21
|
+
warn "narray gem not found."
|
22
|
+
end
|
23
|
+
|
24
|
+
maxvals = {
|
25
|
+
:maxdim => 65536,
|
26
|
+
:maxiant => 2048,
|
27
|
+
:maxant => 128,
|
28
|
+
:maxnax => 7,
|
29
|
+
:maxwin => 16,
|
30
|
+
:maxbuf => 4194304
|
31
|
+
}
|
32
|
+
|
33
|
+
ARGV.grep(/^(--)?max/).each do |s|
|
34
|
+
k, v = s.split('=')
|
35
|
+
k.sub!(/^--/,'')
|
36
|
+
maxvals[k.to_sym] = Integer(v) rescue nil
|
37
|
+
end
|
38
|
+
|
39
|
+
lines = File.readlines('maxdimc.h.in').join
|
40
|
+
maxvals.each do |k,v|
|
41
|
+
lines.sub!("@#{k.to_s.upcase}@", v.to_s)
|
42
|
+
end
|
43
|
+
|
44
|
+
File.open('maxdimc.h','w') do |f|
|
45
|
+
f.write(lines)
|
46
|
+
end
|
47
|
+
|
48
|
+
$defs << '-DMIRIAD_RUBY'
|
49
|
+
create_makefile('miriad') if have_header('narray.h')
|
data/ext/headio.c
ADDED
@@ -0,0 +1,835 @@
|
|
1
|
+
/************************************************************************/
|
2
|
+
/* */
|
3
|
+
/* Routines to access "header" variables. */
|
4
|
+
/* */
|
5
|
+
/*-- */
|
6
|
+
/* History: */
|
7
|
+
/* rjs Dark_ages Original version */
|
8
|
+
/* rjs 23aug89 Fixed char variable overrun problem, in hdprobe. */
|
9
|
+
/* rjs 12feb90 Added some comments, to appease PJT. */
|
10
|
+
/* rjs 21feb90 Corrected a comment. */
|
11
|
+
/* rjs 7mar90 Added hisopen with status='write' */
|
12
|
+
/* rjs 27apr90 Fixed bug in hdprobe, which got the lengths of items */
|
13
|
+
/* less than ITEM_HDR_SIZE long wrong. */
|
14
|
+
/* pjt 19mar91 output double prec variables in -20.10g */
|
15
|
+
/* rjs 26aug92 Corrected hdprsnt declaration, and the value that */
|
16
|
+
/* it returns. */
|
17
|
+
/* rjs 23feb93 Rename a defined parameter only. */
|
18
|
+
/* rjs 10aug93 Use hexists in hdprsnt. */
|
19
|
+
/* rjs 6nov94 Change "item handle" to an integer. */
|
20
|
+
/* rjs 15may96 Fiddles with roundup macro. */
|
21
|
+
/* pjt 27mar99 make history a static, so nobody can see it :-) */
|
22
|
+
/* rjs 29apr99 Get hdprobe to check for string buffer overflow. */
|
23
|
+
/* dpr 11may01 Descriptive error for hisopen_c */
|
24
|
+
/* pjt 22jun02 MIR4 prototypes and using int8 for long integers */
|
25
|
+
/* pjt/rjs 1jan05 replaced shortcut rdhdd code with their own readers */
|
26
|
+
/* this fixes a serious bug in rdhdl for large values */
|
27
|
+
/* Also adding in some bugv_c() called to replace bug_c */
|
28
|
+
/* pjt 12jan05 Fixed up type conversion for int8's in rhhdl */
|
29
|
+
/* pjt 6feb05 rdhdd_c() : no more type check (see comment in code) */
|
30
|
+
/* pjt 17feb05 fixed bug in reading int8's from old MIR3 files */
|
31
|
+
/* pjt 6sep06 read integers via rdhdi */
|
32
|
+
/************************************************************************/
|
33
|
+
|
34
|
+
#include <stdlib.h>
|
35
|
+
#include <string.h>
|
36
|
+
#include <ctype.h>
|
37
|
+
#include <stdio.h>
|
38
|
+
#include "miriad.h"
|
39
|
+
#include "io.h"
|
40
|
+
|
41
|
+
#define check(iostat) if(iostat)bugno_c('f',iostat)
|
42
|
+
#define MAXSIZE 1024
|
43
|
+
#define MAXLINE 80
|
44
|
+
|
45
|
+
|
46
|
+
static int history[MAXOPEN];
|
47
|
+
|
48
|
+
#define Sprintf (void)sprintf
|
49
|
+
#define Strcpy (void)strcpy
|
50
|
+
|
51
|
+
/************************************************************************/
|
52
|
+
void hisopen_c(int tno,Const char *status)
|
53
|
+
/** hisopen -- Open the history file. */
|
54
|
+
/*& pjt */
|
55
|
+
/*: header-i/o */
|
56
|
+
/*+ FORTRAN call sequence:
|
57
|
+
|
58
|
+
subroutine hisopen(tno,status)
|
59
|
+
integer tno
|
60
|
+
character status
|
61
|
+
|
62
|
+
This opens the history file, and readies it to be read or written.
|
63
|
+
|
64
|
+
Inputs:
|
65
|
+
tno The handle of the open data set.
|
66
|
+
status Either "read", "write" or "append". */
|
67
|
+
/*-- */
|
68
|
+
/*----------------------------------------------------------------------*/
|
69
|
+
{
|
70
|
+
int iostat;
|
71
|
+
haccess_c(tno,&history[tno],"history",status,&iostat);
|
72
|
+
if(iostat) {bug_c('e',"Problem with history item");};
|
73
|
+
check(iostat);
|
74
|
+
}
|
75
|
+
/************************************************************************/
|
76
|
+
void hiswrite_c(int tno,Const char *text)
|
77
|
+
/** hiswrite -- Write a line of text to the history file. */
|
78
|
+
/*& pjt */
|
79
|
+
/*: header-i/o */
|
80
|
+
/*+ FORTRAN call sequence:
|
81
|
+
|
82
|
+
subroutine hiswrite(tno,line)
|
83
|
+
integer tno
|
84
|
+
character line*(*)
|
85
|
+
|
86
|
+
This writes a text string to the history file associated with an open
|
87
|
+
data set.
|
88
|
+
|
89
|
+
Inputs:
|
90
|
+
tno The handle of the open data set.
|
91
|
+
line The string of text to be written to the history file. */
|
92
|
+
/*-- */
|
93
|
+
/*----------------------------------------------------------------------*/
|
94
|
+
{
|
95
|
+
int iostat;
|
96
|
+
hwritea_c(history[tno],text,strlen(text)+1,&iostat); check(iostat);
|
97
|
+
}
|
98
|
+
/************************************************************************/
|
99
|
+
void hisread_c(int tno,char *text,size_t length,int *eof)
|
100
|
+
/** hisread -- Read a line of text from the history file. */
|
101
|
+
/*& pjt */
|
102
|
+
/*: header-i/o */
|
103
|
+
/*+ FORTRAN call sequence:
|
104
|
+
|
105
|
+
subroutine hisread(tno,line,eof)
|
106
|
+
integer tno
|
107
|
+
character line*(*)
|
108
|
+
logical eof
|
109
|
+
|
110
|
+
This reads a line of text from the history file.
|
111
|
+
|
112
|
+
Input:
|
113
|
+
tno The handle of the input data set.
|
114
|
+
Output:
|
115
|
+
line The string to receive the read string.
|
116
|
+
eof This logical variable turns true when the end of the
|
117
|
+
history file is reached. */
|
118
|
+
/*-- */
|
119
|
+
/*----------------------------------------------------------------------*/
|
120
|
+
{
|
121
|
+
int iostat;
|
122
|
+
hreada_c(history[tno],text,length,&iostat);
|
123
|
+
if(iostat == 0) *eof = FORT_FALSE;
|
124
|
+
else if(iostat == -1) *eof = FORT_TRUE;
|
125
|
+
else bugno_c('f',iostat);
|
126
|
+
}
|
127
|
+
/************************************************************************/
|
128
|
+
void hisclose_c(int tno)
|
129
|
+
/** hisclose -- This closes the history file. */
|
130
|
+
/*& pjt */
|
131
|
+
/*: header-i/o */
|
132
|
+
/*+ FORTRAN call sequence:
|
133
|
+
|
134
|
+
subroutine hisclose(tno
|
135
|
+
integer tno
|
136
|
+
|
137
|
+
This closes the history file associated with a particular data set.
|
138
|
+
Input:
|
139
|
+
tno The handle of the data set. */
|
140
|
+
/*-- */
|
141
|
+
/*----------------------------------------------------------------------*/
|
142
|
+
{
|
143
|
+
int iostat;
|
144
|
+
hdaccess_c(history[tno],&iostat); check(iostat);
|
145
|
+
}
|
146
|
+
/************************************************************************/
|
147
|
+
void wrhdr_c(int thandle,Const char *keyword,double value)
|
148
|
+
/** wrhdr -- Write a real valued header variable. */
|
149
|
+
/*& pjt */
|
150
|
+
/*: header-i/o */
|
151
|
+
/*+ FORTRAN call sequence:
|
152
|
+
|
153
|
+
subroutine wrhdr(tno,keyword,value)
|
154
|
+
integer tno
|
155
|
+
character keyword*(*)
|
156
|
+
real value
|
157
|
+
|
158
|
+
This writes a real-valued header keyword.
|
159
|
+
Input:
|
160
|
+
tno Handle of the data set.
|
161
|
+
keyword Name of the keyword to write.
|
162
|
+
value The value of the keyword. */
|
163
|
+
/*-- */
|
164
|
+
/*----------------------------------------------------------------------*/
|
165
|
+
{
|
166
|
+
int item;
|
167
|
+
float temp;
|
168
|
+
int iostat,offset;
|
169
|
+
|
170
|
+
temp = value;
|
171
|
+
haccess_c(thandle,&item,keyword,"write",&iostat); check(iostat);
|
172
|
+
hwriteb_c(item,real_item,0,ITEM_HDR_SIZE,&iostat); check(iostat);
|
173
|
+
offset = mroundup(ITEM_HDR_SIZE,H_REAL_SIZE);
|
174
|
+
hwriter_c(item,&temp,offset,H_REAL_SIZE,&iostat); check(iostat);
|
175
|
+
hdaccess_c(item,&iostat); check(iostat);
|
176
|
+
}
|
177
|
+
/************************************************************************/
|
178
|
+
void wrhdd_c(int thandle,Const char *keyword,double value)
|
179
|
+
/** wrhdd -- Write a double precision valued header variable. */
|
180
|
+
/*& mjs */
|
181
|
+
/*: header-i/o */
|
182
|
+
/*+ FORTRAN call sequence:
|
183
|
+
|
184
|
+
subroutine wrhdd(tno,keyword,value)
|
185
|
+
integer tno
|
186
|
+
character keyword*(*)
|
187
|
+
double precision value
|
188
|
+
|
189
|
+
Write the value of a header variable which has a double precision value.
|
190
|
+
|
191
|
+
Input:
|
192
|
+
tno The handle of the data set.
|
193
|
+
keyword Name to the keyword.
|
194
|
+
value The double precision value. */
|
195
|
+
/*-- */
|
196
|
+
/*----------------------------------------------------------------------*/
|
197
|
+
{
|
198
|
+
int item;
|
199
|
+
int iostat,offset;
|
200
|
+
|
201
|
+
haccess_c(thandle,&item,keyword,"write",&iostat); check(iostat);
|
202
|
+
hwriteb_c(item,dble_item,0,ITEM_HDR_SIZE,&iostat); check(iostat);
|
203
|
+
offset = mroundup(ITEM_HDR_SIZE,H_DBLE_SIZE);
|
204
|
+
hwrited_c(item,&value,offset,H_DBLE_SIZE,&iostat); check(iostat);
|
205
|
+
hdaccess_c(item,&iostat); check(iostat);
|
206
|
+
}
|
207
|
+
/************************************************************************/
|
208
|
+
void wrhdi_c(int thandle,Const char *keyword,int value)
|
209
|
+
/** wrhdi -- Write an integer valued header variable. */
|
210
|
+
/*& mjs */
|
211
|
+
/*: header-i/o */
|
212
|
+
/*+ FORTRAN call sequence:
|
213
|
+
|
214
|
+
subroutine wrhdi(tno,keyword,value)
|
215
|
+
integer tno
|
216
|
+
character keyword*(*)
|
217
|
+
integer value
|
218
|
+
|
219
|
+
Write an integer valued header variable.
|
220
|
+
|
221
|
+
Input:
|
222
|
+
tno The handle of the data set.
|
223
|
+
keyword The name of the header variable.
|
224
|
+
value The integer value of the header variable. */
|
225
|
+
/*-- */
|
226
|
+
/*----------------------------------------------------------------------*/
|
227
|
+
{
|
228
|
+
int item;
|
229
|
+
int iostat,offset;
|
230
|
+
|
231
|
+
haccess_c(thandle,&item,keyword,"write",&iostat); check(iostat);
|
232
|
+
hwriteb_c(item,int_item,0,ITEM_HDR_SIZE,&iostat); check(iostat);
|
233
|
+
offset = mroundup(ITEM_HDR_SIZE,H_INT_SIZE);
|
234
|
+
hwritei_c(item,&value,offset,H_INT_SIZE,&iostat); check(iostat);
|
235
|
+
hdaccess_c(item,&iostat); check(iostat);
|
236
|
+
}
|
237
|
+
/************************************************************************/
|
238
|
+
void wrhdl_c(int thandle,Const char *keyword,int8 value)
|
239
|
+
/** wrhdl -- Write an integer*8 valued header variable. */
|
240
|
+
/*& pjt */
|
241
|
+
/*: header-i/o */
|
242
|
+
/*+ FORTRAN call sequence:
|
243
|
+
|
244
|
+
subroutine wrhdl(tno,keyword,value)
|
245
|
+
integer tno
|
246
|
+
character keyword*(*)
|
247
|
+
integer*8 value
|
248
|
+
|
249
|
+
Write an integer*8 valued header variable. This is only supported
|
250
|
+
on compilers that know how to handle integer*8 (e.g. gnu, intel).
|
251
|
+
Without this support, some files in miriad will be limited to
|
252
|
+
8 GB.
|
253
|
+
|
254
|
+
Input:
|
255
|
+
tno The handle of the data set.
|
256
|
+
keyword The name of the header variable.
|
257
|
+
value The integer*8 value of the header variable. */
|
258
|
+
/*-- */
|
259
|
+
/*----------------------------------------------------------------------*/
|
260
|
+
{
|
261
|
+
int item;
|
262
|
+
int iostat,offset;
|
263
|
+
|
264
|
+
/* Sault proposes to write an INT if below 2^31, else INT8 */
|
265
|
+
|
266
|
+
haccess_c(thandle,&item,keyword,"write",&iostat); check(iostat);
|
267
|
+
hwriteb_c(item,int8_item,0,ITEM_HDR_SIZE,&iostat); check(iostat);
|
268
|
+
offset = mroundup(ITEM_HDR_SIZE,H_INT8_SIZE);
|
269
|
+
hwritel_c(item,&value,offset,H_INT8_SIZE,&iostat); check(iostat);
|
270
|
+
hdaccess_c(item,&iostat); check(iostat);
|
271
|
+
}
|
272
|
+
/************************************************************************/
|
273
|
+
void wrhdc_c(int thandle,Const char *keyword,Const float *value)
|
274
|
+
/** wrhdc -- Write a complex-valued header variable. */
|
275
|
+
/*& mjs */
|
276
|
+
/*: header-i/o */
|
277
|
+
/*+ FORTRAN call sequence:
|
278
|
+
|
279
|
+
subroutine wrhdc(tno,keyword,value)
|
280
|
+
integer tno
|
281
|
+
character keyword*(*)
|
282
|
+
complex value
|
283
|
+
|
284
|
+
Write a complex valued header variable.
|
285
|
+
Input:
|
286
|
+
tno The file handle fo the data set.
|
287
|
+
keyword The name of the header variable.
|
288
|
+
value The complex value of the header variable. */
|
289
|
+
/*-- */
|
290
|
+
/*----------------------------------------------------------------------*/
|
291
|
+
{
|
292
|
+
int item;
|
293
|
+
int iostat,offset;
|
294
|
+
|
295
|
+
haccess_c(thandle,&item,keyword,"write",&iostat); check(iostat);
|
296
|
+
hwriteb_c(item,cmplx_item,0,ITEM_HDR_SIZE,&iostat); check(iostat);
|
297
|
+
offset = mroundup(ITEM_HDR_SIZE,H_CMPLX_SIZE);
|
298
|
+
hwritec_c(item,value,offset,H_CMPLX_SIZE,&iostat); check(iostat);
|
299
|
+
hdaccess_c(item,&iostat); check(iostat);
|
300
|
+
}
|
301
|
+
/************************************************************************/
|
302
|
+
void wrhda_c(int thandle,Const char *keyword,Const char *value)
|
303
|
+
/** wrhda -- Write a string-valued header variable. */
|
304
|
+
/*& mjs */
|
305
|
+
/*: header-i/o */
|
306
|
+
/*+ FORTRAN call sequence:
|
307
|
+
|
308
|
+
subroutine wrhda(tno,keyword,value)
|
309
|
+
integer tno
|
310
|
+
character keyword*(*)
|
311
|
+
character value*(*)
|
312
|
+
|
313
|
+
Write a string valued header variable.
|
314
|
+
|
315
|
+
Input:
|
316
|
+
tno The file handle of the data set.
|
317
|
+
keyword The name of the header variable.
|
318
|
+
value The value of the header variable. */
|
319
|
+
/*-- */
|
320
|
+
/*----------------------------------------------------------------------*/
|
321
|
+
{
|
322
|
+
int item;
|
323
|
+
int iostat;
|
324
|
+
|
325
|
+
haccess_c(thandle,&item,keyword,"write",&iostat); check(iostat);
|
326
|
+
hwriteb_c(item,char_item,0,ITEM_HDR_SIZE,&iostat); check(iostat);
|
327
|
+
hwriteb_c(item,(char *)value,ITEM_HDR_SIZE,
|
328
|
+
strlen(value),&iostat); check(iostat);
|
329
|
+
hdaccess_c(item,&iostat); check(iostat);
|
330
|
+
}
|
331
|
+
/************************************************************************/
|
332
|
+
void rdhdr_c(int thandle,Const char *keyword,float *value,double defval)
|
333
|
+
/** rdhdr -- Read a real-valued header variable. */
|
334
|
+
/*& mjs */
|
335
|
+
/*: header-i/o */
|
336
|
+
/*+ FORTRAN call sequence:
|
337
|
+
|
338
|
+
subroutine rdhdr(tno,keyword,value,default)
|
339
|
+
integer tno
|
340
|
+
character keyword*(*)
|
341
|
+
real value,default
|
342
|
+
|
343
|
+
Read a real valued header variable.
|
344
|
+
|
345
|
+
Input:
|
346
|
+
tno The file handle of the data set.
|
347
|
+
keyword The name of the header variable.
|
348
|
+
default The default value to return, if the header variable
|
349
|
+
is not found.
|
350
|
+
Output:
|
351
|
+
value The value of the header variable. This will be the default
|
352
|
+
value, if the variable is missing from the header. */
|
353
|
+
/*-- */
|
354
|
+
/*----------------------------------------------------------------------*/
|
355
|
+
{
|
356
|
+
double dvalue,ddefval;
|
357
|
+
ddefval = defval;
|
358
|
+
rdhdd_c(thandle,keyword,&dvalue,ddefval);
|
359
|
+
*value = dvalue;
|
360
|
+
}
|
361
|
+
/************************************************************************/
|
362
|
+
void rdhdi_c(int thandle,Const char *keyword,int *value,int defval)
|
363
|
+
/** rdhdi -- Read an integer-valued header variable. */
|
364
|
+
/*& mjs */
|
365
|
+
/*: header-i/o */
|
366
|
+
/*+ FORTRAN call sequence:
|
367
|
+
|
368
|
+
subroutine rdhdi(tno,keyword,value,default)
|
369
|
+
integer tno
|
370
|
+
character keyword*(*)
|
371
|
+
integer value,default
|
372
|
+
|
373
|
+
Read an integer valued header variable.
|
374
|
+
|
375
|
+
Input:
|
376
|
+
tno The file handle of the data set.
|
377
|
+
keyword The name of the header variable.
|
378
|
+
default The default value to return, if the header variable
|
379
|
+
is not found.
|
380
|
+
Output:
|
381
|
+
value The value of the header variable. This will be the default
|
382
|
+
value, if the variable is missing from the header. */
|
383
|
+
/*-- */
|
384
|
+
/*----------------------------------------------------------------------*/
|
385
|
+
{
|
386
|
+
int8 lvalue,ldefval;
|
387
|
+
ldefval = defval;
|
388
|
+
rdhdl_c(thandle,keyword,&lvalue,ldefval);
|
389
|
+
|
390
|
+
if(lvalue > 0x7FFFFFFF)
|
391
|
+
bugv_c('f',"Item %s too large for rdhdi: %ld",keyword,lvalue);
|
392
|
+
*value = lvalue;
|
393
|
+
}
|
394
|
+
/************************************************************************/
|
395
|
+
void rdhdl_c(int thandle,Const char *keyword,int8 *value,int8 defval)
|
396
|
+
/** rdhdl -- Read an integer*8-valued header variable. */
|
397
|
+
/*& mjs */
|
398
|
+
/*: header-i/o */
|
399
|
+
/*+ FORTRAN call sequence:
|
400
|
+
|
401
|
+
subroutine rdhdl(tno,keyword,value,default)
|
402
|
+
integer tno
|
403
|
+
character keyword*(*)
|
404
|
+
integer*8 value,default
|
405
|
+
|
406
|
+
Read an integer*8 valued header variable. Only supported on some
|
407
|
+
compilers. See comments in wrhdl
|
408
|
+
|
409
|
+
Input:
|
410
|
+
tno The file handle of the data set.
|
411
|
+
keyword The name of the header variable.
|
412
|
+
default The default value to return, if the header variable
|
413
|
+
is not found.
|
414
|
+
Output:
|
415
|
+
value The value of the header variable. This will be the default
|
416
|
+
value, if the variable is missing from the header. */
|
417
|
+
/*-- */
|
418
|
+
/*----------------------------------------------------------------------*/
|
419
|
+
{
|
420
|
+
int item;
|
421
|
+
char s[ITEM_HDR_SIZE];
|
422
|
+
int iostat,length,offset,itemp;
|
423
|
+
|
424
|
+
/* Firstly assume the variable is missing. Try to get it. If successful
|
425
|
+
read it. */
|
426
|
+
|
427
|
+
*value = defval;
|
428
|
+
haccess_c(thandle,&item,keyword,"read",&iostat); if(iostat)return;
|
429
|
+
length = hsize_c(item);
|
430
|
+
if(length >= 0){
|
431
|
+
|
432
|
+
/* Determine the type of the value, and convert it to double precision. */
|
433
|
+
|
434
|
+
hreadb_c(item,s,0,ITEM_HDR_SIZE,&iostat); check(iostat);
|
435
|
+
iostat = 0;
|
436
|
+
if( !memcmp(s,int8_item, ITEM_HDR_SIZE)){
|
437
|
+
offset = mroundup(ITEM_HDR_SIZE, H_INT8_SIZE);
|
438
|
+
if(offset + H_INT8_SIZE == length)
|
439
|
+
hreadl_c(item,value,offset,H_INT8_SIZE,&iostat);
|
440
|
+
} else if ( !memcmp(s,int_item, ITEM_HDR_SIZE)){
|
441
|
+
/* this is to cover old style MIR3 files that were using int4's */
|
442
|
+
offset = mroundup(ITEM_HDR_SIZE, H_INT_SIZE);
|
443
|
+
if(offset + H_INT_SIZE == length) {
|
444
|
+
hreadi_c(item,&itemp,offset,H_INT_SIZE,&iostat);
|
445
|
+
*value = itemp;
|
446
|
+
}
|
447
|
+
} else
|
448
|
+
bugv_c('f',"rdhdl_c: item %s not an int8 or small enough int4",keyword);
|
449
|
+
|
450
|
+
check(iostat);
|
451
|
+
}
|
452
|
+
hdaccess_c(item,&iostat); check(iostat);
|
453
|
+
|
454
|
+
}
|
455
|
+
/************************************************************************/
|
456
|
+
void rdhdd_c(int thandle,Const char *keyword,double *value,double defval)
|
457
|
+
/** rdhdd -- Read a double precision-valued header variable. */
|
458
|
+
/*& mjs */
|
459
|
+
/*: header-i/o */
|
460
|
+
/*+ FORTRAN call sequence:
|
461
|
+
|
462
|
+
subroutine rdhdd(tno,keyword,value,default)
|
463
|
+
integer tno
|
464
|
+
character keyword*(*)
|
465
|
+
double precision value,default
|
466
|
+
|
467
|
+
Read a double precision valued header variable.
|
468
|
+
|
469
|
+
Input:
|
470
|
+
tno The file handle of the data set.
|
471
|
+
keyword The name of the header variable.
|
472
|
+
default The default value to return, if the header variable
|
473
|
+
is not found.
|
474
|
+
Output:
|
475
|
+
value The value of the header variable. This will be the default
|
476
|
+
value, if the variable is missing from the header. */
|
477
|
+
/*-- */
|
478
|
+
/*----------------------------------------------------------------------*/
|
479
|
+
{
|
480
|
+
int item;
|
481
|
+
char s[ITEM_HDR_SIZE];
|
482
|
+
int iostat,length,itemp,offset;
|
483
|
+
float rtemp;
|
484
|
+
|
485
|
+
/* Firstly assume the variable is missing. Try to get it. If successful
|
486
|
+
read it. */
|
487
|
+
|
488
|
+
*value = defval;
|
489
|
+
haccess_c(thandle,&item,keyword,"read",&iostat); if(iostat)return;
|
490
|
+
length = hsize_c(item);
|
491
|
+
if(length >= 0){
|
492
|
+
|
493
|
+
/* Determine the type of the value, and convert it to double precision. */
|
494
|
+
|
495
|
+
hreadb_c(item,s,0,ITEM_HDR_SIZE,&iostat); check(iostat);
|
496
|
+
iostat = 0;
|
497
|
+
if( !memcmp(s,int_item, ITEM_HDR_SIZE)){
|
498
|
+
offset = mroundup(ITEM_HDR_SIZE,H_INT_SIZE);
|
499
|
+
if(offset + H_INT_SIZE == length){
|
500
|
+
hreadi_c(item,&itemp,offset,H_INT_SIZE,&iostat);
|
501
|
+
*value = itemp;
|
502
|
+
}
|
503
|
+
} else if(!memcmp(s,real_item,ITEM_HDR_SIZE)){
|
504
|
+
offset = mroundup(ITEM_HDR_SIZE,H_REAL_SIZE);
|
505
|
+
if(offset + H_REAL_SIZE == length){
|
506
|
+
hreadr_c(item,&rtemp,offset,H_REAL_SIZE,&iostat);
|
507
|
+
*value = rtemp;
|
508
|
+
}
|
509
|
+
} else if(!memcmp(s,dble_item,ITEM_HDR_SIZE)){
|
510
|
+
offset = mroundup(ITEM_HDR_SIZE,H_DBLE_SIZE);
|
511
|
+
if(offset + H_DBLE_SIZE == length){
|
512
|
+
hreadd_c(item,value, offset,H_DBLE_SIZE,&iostat);
|
513
|
+
}
|
514
|
+
}
|
515
|
+
#if 0
|
516
|
+
/* can't do this: some routines, e.g. imhead, actually depend
|
517
|
+
* on it falling through. Sick, but true
|
518
|
+
*/
|
519
|
+
else
|
520
|
+
bugv_c('f',"rdhdd_c: keyword %s not covered here",keyword);
|
521
|
+
#endif
|
522
|
+
|
523
|
+
check(iostat);
|
524
|
+
}
|
525
|
+
hdaccess_c(item,&iostat); check(iostat);
|
526
|
+
}
|
527
|
+
/************************************************************************/
|
528
|
+
void rdhdc_c(int thandle,Const char *keyword,float *value,Const float *defval)
|
529
|
+
/** rdhdc -- Read a complex-valued header variable. */
|
530
|
+
/*& mjs */
|
531
|
+
/*: header-i/o */
|
532
|
+
/*+ FORTRAN call sequence:
|
533
|
+
|
534
|
+
subroutine rdhdc(tno,keyword,value,default)
|
535
|
+
integer tno
|
536
|
+
character keyword*(*)
|
537
|
+
complex value,default
|
538
|
+
|
539
|
+
Read a complex valued header variable.
|
540
|
+
|
541
|
+
Input:
|
542
|
+
tno The file handle of the data set.
|
543
|
+
keyword The name of the header variable.
|
544
|
+
default The default value to return, if the header variable
|
545
|
+
is not found.
|
546
|
+
Output:
|
547
|
+
value The value of the header variable. This will be the default
|
548
|
+
value, if the variable is missing from the header. */
|
549
|
+
/*-- */
|
550
|
+
/*----------------------------------------------------------------------*/
|
551
|
+
{
|
552
|
+
int item;
|
553
|
+
char s[ITEM_HDR_SIZE];
|
554
|
+
int iostat,length,offset;
|
555
|
+
|
556
|
+
/* Firstly assume the variable is missing. Try to get it. If successful
|
557
|
+
read it. */
|
558
|
+
|
559
|
+
*value = *defval;
|
560
|
+
*(value+1) = *(defval+1);
|
561
|
+
haccess_c(thandle,&item,keyword,"read",&iostat); if(iostat)return;
|
562
|
+
offset = mroundup(ITEM_HDR_SIZE,H_CMPLX_SIZE);
|
563
|
+
length = hsize_c(item) - offset;
|
564
|
+
if(length == H_CMPLX_SIZE){
|
565
|
+
hreadb_c(item,s,0,ITEM_HDR_SIZE,&iostat); check(iostat);
|
566
|
+
iostat = 0;
|
567
|
+
if(!memcmp(s,cmplx_item, ITEM_HDR_SIZE)){
|
568
|
+
hreadc_c(item,value,offset,H_CMPLX_SIZE,&iostat);
|
569
|
+
}
|
570
|
+
check(iostat);
|
571
|
+
}
|
572
|
+
hdaccess_c(item,&iostat); check(iostat);
|
573
|
+
}
|
574
|
+
/************************************************************************/
|
575
|
+
void rdhda_c(int thandle,Const char *keyword,char *value,Const char *defval,int len)
|
576
|
+
/** rdhda -- Read a string-valued header variable. */
|
577
|
+
/*& mjs */
|
578
|
+
/*: header-i/o */
|
579
|
+
/*+ FORTRAN call sequence:
|
580
|
+
|
581
|
+
subroutine rdhda(tno,keyword,value,default)
|
582
|
+
integer tno
|
583
|
+
character keyword*(*)
|
584
|
+
character value*(*),default*(*)
|
585
|
+
|
586
|
+
Read a string valued header variable.
|
587
|
+
|
588
|
+
Input:
|
589
|
+
tno The file handle of the data set.
|
590
|
+
keyword The name of the header variable.
|
591
|
+
default The default value to return, if the header variable
|
592
|
+
is not found.
|
593
|
+
Output:
|
594
|
+
value The value of the header variable. This will be the default
|
595
|
+
value, if the variable is missing from the header. */
|
596
|
+
/*-- */
|
597
|
+
/*----------------------------------------------------------------------*/
|
598
|
+
{
|
599
|
+
int item;
|
600
|
+
char s[ITEM_HDR_SIZE];
|
601
|
+
int iostat,dodef,length=0;
|
602
|
+
|
603
|
+
/* Firstly assume the variable is missing. Try to get it. If successful
|
604
|
+
read it. */
|
605
|
+
|
606
|
+
dodef = TRUE;
|
607
|
+
haccess_c(thandle,&item,keyword,"read",&iostat);
|
608
|
+
if(! iostat) {
|
609
|
+
length = min( hsize_c(item) - ITEM_HDR_SIZE, len - 1);
|
610
|
+
if(length > 0) {
|
611
|
+
hreadb_c(item,s,0,ITEM_HDR_SIZE,&iostat); check(iostat);
|
612
|
+
if(!memcmp(s,char_item,ITEM_HDR_SIZE)){
|
613
|
+
hreadb_c(item,value,ITEM_HDR_SIZE,length,&iostat); check(iostat);
|
614
|
+
dodef = FALSE;
|
615
|
+
}
|
616
|
+
}
|
617
|
+
hdaccess_c(item,&iostat); check(iostat);
|
618
|
+
}
|
619
|
+
if( dodef ) {
|
620
|
+
length = min(strlen(defval),len-1);
|
621
|
+
memcpy(value,defval,length);
|
622
|
+
}
|
623
|
+
*(value+length) = 0;
|
624
|
+
}
|
625
|
+
/************************************************************************/
|
626
|
+
void hdcopy_c(int tin,int tout,Const char *keyword)
|
627
|
+
/** hdcopy -- Copy a headfer variable from one data set to another. */
|
628
|
+
/*& mjs */
|
629
|
+
/*: header-i/o */
|
630
|
+
/*+ FORTRAN call sequence:
|
631
|
+
|
632
|
+
subroutine hdcopy(tin,tout,keyword)
|
633
|
+
integer tin,tout
|
634
|
+
character keyword*(*)
|
635
|
+
|
636
|
+
Copy a header item from one data set to another.
|
637
|
+
|
638
|
+
Input:
|
639
|
+
tin File handle of the input data set.
|
640
|
+
tout File handle of the output data set.
|
641
|
+
keyword Name of the header variable to be copied. */
|
642
|
+
/*-- */
|
643
|
+
/*----------------------------------------------------------------------*/
|
644
|
+
{
|
645
|
+
char buf[MAXSIZE];
|
646
|
+
int item_in,item_out;
|
647
|
+
int length,offset,iostat,size;
|
648
|
+
|
649
|
+
haccess_c(tin,&item_in,keyword,"read",&iostat); if(iostat)return;
|
650
|
+
haccess_c(tout,&item_out,keyword,"write",&iostat); check(iostat);
|
651
|
+
|
652
|
+
size = hsize_c(item_in);
|
653
|
+
offset = 0;
|
654
|
+
while(offset < size){
|
655
|
+
length = min(size - offset, sizeof(buf));
|
656
|
+
hreadb_c(item_in,buf,offset,length,&iostat); check(iostat);
|
657
|
+
hwriteb_c(item_out,buf,offset,length,&iostat); check(iostat);
|
658
|
+
offset += length;
|
659
|
+
}
|
660
|
+
hdaccess_c(item_in,&iostat); check(iostat);
|
661
|
+
hdaccess_c(item_out,&iostat); check(iostat);
|
662
|
+
}
|
663
|
+
/************************************************************************/
|
664
|
+
int hdprsnt_c(int tno,Const char *keyword)
|
665
|
+
/** hdprsnt -- Determine if a header variable is present. */
|
666
|
+
/*& mjs */
|
667
|
+
/*: header-i/o */
|
668
|
+
/*+ FORTRAN call sequence:
|
669
|
+
|
670
|
+
logical function hdprsnt(tno,keyword)
|
671
|
+
integer tno
|
672
|
+
character keyword*(*)
|
673
|
+
|
674
|
+
Check if a particular header variable is present in a data set.
|
675
|
+
|
676
|
+
Input:
|
677
|
+
tno File handle of the data set to check.
|
678
|
+
keyword Name of the header variable to check for. */
|
679
|
+
/*-- */
|
680
|
+
/*----------------------------------------------------------------------*/
|
681
|
+
{
|
682
|
+
if(hexists_c(tno,keyword))return(FORT_TRUE);
|
683
|
+
else return(FORT_FALSE);
|
684
|
+
}
|
685
|
+
/************************************************************************/
|
686
|
+
void hdprobe_c(int tno,Const char *keyword,char *descr,size_t length,char *type,int *n)
|
687
|
+
/** hdprobe -- Determine characteristics of a header variable. */
|
688
|
+
/*& mjs */
|
689
|
+
/*: header-i/o */
|
690
|
+
/*+ FORTRAN call sequence:
|
691
|
+
|
692
|
+
subroutine hdprobe(tno,keyword,descr,type,n)
|
693
|
+
integer tno
|
694
|
+
character keyword*(*),descr*(*),type*(*)
|
695
|
+
integer n
|
696
|
+
|
697
|
+
Determine characteristics of a particular header variable.
|
698
|
+
Inputs:
|
699
|
+
tno Handle of the data set.
|
700
|
+
keyword Name of the header variable to probe.
|
701
|
+
|
702
|
+
Outputs:
|
703
|
+
descr A formatted version of the item. For single numerics or
|
704
|
+
short strings, this is the ascii encoding of the value. For
|
705
|
+
large items, this is some message describing the item.
|
706
|
+
type One of:
|
707
|
+
'nonexistent'
|
708
|
+
'integer*2'
|
709
|
+
'integer*8'
|
710
|
+
'integer'
|
711
|
+
'real'
|
712
|
+
'double'
|
713
|
+
'complex'
|
714
|
+
'character'
|
715
|
+
'text'
|
716
|
+
'binary'
|
717
|
+
n Number of elements in the item. Zero implies an error. One
|
718
|
+
implies that "descr" is the ascii encoding of the value. */
|
719
|
+
/*-- */
|
720
|
+
/*----------------------------------------------------------------------*/
|
721
|
+
{
|
722
|
+
int item;
|
723
|
+
char s[ITEM_HDR_SIZE],buf[MAXSIZE];
|
724
|
+
float rtemp,ctemp[2];
|
725
|
+
int iostat,unknown,size,i,itemp,offset,bufit;
|
726
|
+
double dtemp;
|
727
|
+
int2 jtemp;
|
728
|
+
int8 ltemp;
|
729
|
+
|
730
|
+
haccess_c(tno,&item,keyword,"read",&iostat);
|
731
|
+
*n = 0;
|
732
|
+
bufit = 0;
|
733
|
+
Strcpy(type,"nonexistent"); if(iostat)return;
|
734
|
+
size = hsize_c(item);
|
735
|
+
unknown = FALSE;
|
736
|
+
if(size <= ITEM_HDR_SIZE){
|
737
|
+
unknown = TRUE;
|
738
|
+
size -= ITEM_HDR_SIZE;
|
739
|
+
} else {
|
740
|
+
hreadb_c(item,s,0,ITEM_HDR_SIZE,&iostat); check(iostat);
|
741
|
+
if(!memcmp(s,real_item,ITEM_HDR_SIZE)){
|
742
|
+
offset = mroundup(ITEM_HDR_SIZE,H_REAL_SIZE);
|
743
|
+
size -= offset;
|
744
|
+
Strcpy(type,"real");
|
745
|
+
*n = size / H_REAL_SIZE;
|
746
|
+
if(size % H_REAL_SIZE) unknown = TRUE;
|
747
|
+
else if(size == H_REAL_SIZE){
|
748
|
+
hreadr_c(item,&rtemp,offset,H_REAL_SIZE,&iostat); check(iostat);
|
749
|
+
Sprintf(buf,"%-14.7g",rtemp);
|
750
|
+
bufit = 1;
|
751
|
+
}
|
752
|
+
} else if(!memcmp(s,int_item,ITEM_HDR_SIZE)){
|
753
|
+
offset = mroundup(ITEM_HDR_SIZE,H_INT_SIZE);
|
754
|
+
size -= offset;
|
755
|
+
Strcpy(type,"integer");
|
756
|
+
*n = size / H_INT_SIZE;
|
757
|
+
if(size % H_INT_SIZE) unknown = TRUE;
|
758
|
+
else if(size == H_INT_SIZE){
|
759
|
+
hreadi_c(item,&itemp,offset,H_INT_SIZE,&iostat); check(iostat);
|
760
|
+
Sprintf(buf,"%d",itemp);
|
761
|
+
bufit = 1;
|
762
|
+
}
|
763
|
+
} else if(!memcmp(s,int2_item,ITEM_HDR_SIZE)){
|
764
|
+
offset = mroundup(ITEM_HDR_SIZE,H_INT2_SIZE);
|
765
|
+
size -= offset;
|
766
|
+
Strcpy(type,"integer*2");
|
767
|
+
*n = size / H_INT2_SIZE;
|
768
|
+
if(size % H_INT2_SIZE) unknown = TRUE;
|
769
|
+
else if(size == H_INT2_SIZE){
|
770
|
+
hreadj_c(item,&jtemp,offset,H_INT2_SIZE,&iostat); check(iostat);
|
771
|
+
Sprintf(buf,"%d",jtemp);
|
772
|
+
bufit = 1;
|
773
|
+
}
|
774
|
+
} else if(!memcmp(s,int8_item,ITEM_HDR_SIZE)){
|
775
|
+
offset = mroundup(ITEM_HDR_SIZE,H_INT8_SIZE);
|
776
|
+
size -= offset;
|
777
|
+
Strcpy(type,"integer*8");
|
778
|
+
*n = size / H_INT8_SIZE;
|
779
|
+
if(size % H_INT8_SIZE) unknown = TRUE;
|
780
|
+
else if(size == H_INT8_SIZE){
|
781
|
+
hreadl_c(item,<emp,offset,H_INT8_SIZE,&iostat); check(iostat);
|
782
|
+
Sprintf(buf,"%lld",ltemp);
|
783
|
+
bufit = 1;
|
784
|
+
}
|
785
|
+
} else if(!memcmp(s,dble_item,ITEM_HDR_SIZE)){
|
786
|
+
offset = mroundup(ITEM_HDR_SIZE,H_DBLE_SIZE);
|
787
|
+
size -= offset;
|
788
|
+
Strcpy(type,"double");
|
789
|
+
*n = size / H_DBLE_SIZE;
|
790
|
+
if(size % H_DBLE_SIZE) unknown = TRUE;
|
791
|
+
else if(size == H_DBLE_SIZE){
|
792
|
+
hreadd_c(item,&dtemp,offset,H_DBLE_SIZE,&iostat); check(iostat);
|
793
|
+
Sprintf(buf,"%-20.10g",dtemp);
|
794
|
+
bufit = 1;
|
795
|
+
}
|
796
|
+
} else if(!memcmp(s,cmplx_item,ITEM_HDR_SIZE)){
|
797
|
+
offset = mroundup(ITEM_HDR_SIZE,H_CMPLX_SIZE);
|
798
|
+
size -= offset;
|
799
|
+
Strcpy(type,"complex");
|
800
|
+
*n = size / H_CMPLX_SIZE;
|
801
|
+
if(size % H_CMPLX_SIZE) unknown = TRUE;
|
802
|
+
else if(size == H_CMPLX_SIZE){
|
803
|
+
hreadr_c(item,ctemp,offset,H_CMPLX_SIZE,&iostat); check(iostat);
|
804
|
+
Sprintf(buf,"(%-14.7g,%-14.7g)",ctemp[0],ctemp[1]);
|
805
|
+
bufit = 1;
|
806
|
+
}
|
807
|
+
} else if(!memcmp(s,char_item,ITEM_HDR_SIZE)){
|
808
|
+
offset = ITEM_HDR_SIZE;
|
809
|
+
size -= offset;
|
810
|
+
size = min(size,MAXSIZE-1);
|
811
|
+
*n = 1;
|
812
|
+
Strcpy(type,"character");
|
813
|
+
hreadb_c(item,buf,ITEM_HDR_SIZE,size,&iostat); check(iostat);
|
814
|
+
*(buf+size) = 0;
|
815
|
+
bufit = 1;
|
816
|
+
} else if(!memcmp(s,binary_item,ITEM_HDR_SIZE)){
|
817
|
+
*n = size;
|
818
|
+
Strcpy(type,"binary");
|
819
|
+
} else{
|
820
|
+
Strcpy(type,"text");
|
821
|
+
*n = size + ITEM_HDR_SIZE;
|
822
|
+
for(i=0; i < ITEM_HDR_SIZE; i++)
|
823
|
+
if(!isspace(*(s+i)) && !isprint(*(s+i)))unknown = TRUE;
|
824
|
+
}
|
825
|
+
}
|
826
|
+
hdaccess_c(item,&iostat); check(iostat);
|
827
|
+
if(unknown){
|
828
|
+
Strcpy(type,"unknown");
|
829
|
+
*n = size + ITEM_HDR_SIZE;
|
830
|
+
} else if(bufit){
|
831
|
+
if(strlen(buf) > length - 1)
|
832
|
+
bugv_c('f',"Descr buffer overflow in hdprobe for %s",keyword);
|
833
|
+
strcpy(descr,buf);
|
834
|
+
}
|
835
|
+
}
|