将未格式化(二进制数据)写入标准输出

编程入门 行业动态 更新时间:2024-10-23 03:17:21
本文介绍了将未格式化(二进制数据)写入标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在Fortran 90程序中将未格式化(二进制)数据写入STDOUT。我正在使用AIX Unix,不幸的是,它不会让我将单元6打开为未格式化。我想我会尝试打开 / dev / stdout ,而不是使用不同的单元号,但是 / dev / stdout 会不存在于AIX中(尽管这种方法在Linux下工作)。 基本上,我想将我的程序直接输出到另一个程序中,这样就避免了一个中间文件,一个有点像 gzip -c 。考虑到上面遇到的两个问题,是否还有其他一些方法可以实现这一目标?解决方案

我会尝试将数据由 TRANSFER()转换为一个长字符,并用非递归I / O打印。问题将是您的处理器对记录长度的限制。如果太短,最终会在某处出现意外的记录结束。你的处理器也许不会按照你喜欢的方式写出不可打印的字符。

即类似于 <$ p $ (*,'(a)')(b,b $ b缓冲区=传输(数据,缓冲区) ,advance ='no')trim(缓冲区)

我在不可打印字符中看到的最大问题。另请参阅带有非前进I / O的惊喜

---编辑--- 另一种可能性是尝试使用文件 / proc / self / fd / 1 或 / dev / fd / 1

测试:

open(11,file ='/ proc / self / fd / 1',access ='stream',action ='write') write(11)11 write(11)1.1 close(11) end

I want to write unformatted (binary) data to STDOUT in a Fortran 90 program. I am using AIX Unix and unfortunately it won't let me open unit 6 as "unformatted". I thought I would try and open /dev/stdout instead under a different unit number, but /dev/stdout does not exist in AIX (although this method worked under Linux).

Basically, I want to pipe my programs output directly into another program, thus avoiding having an intermediate file, a bit like gzip -c does. Is there some other way I can achieve this, considering the two problems I have encountered above?

解决方案

I would try to convert the data by TRANSFER() to a long character and print it with nonadvancing i/o. The problem will be your processors' limit for the record length. If it is too short you will end up having an unexpected end of record sign somewhere. Also your processor may not write the unprintable characters the way you would like.

i.e., something like

character(len=max_length) :: buffer buffer = transfer(data,buffer) write(*,'(a)',advance='no') trim(buffer)

The largest problem I see in the unprintable characters. See also A suprise with non-advancing I/O

---EDIT--- Another possibility, try to use file /proc/self/fd/1 or /dev/fd/1

test:

open(11,file='/proc/self/fd/1',access='stream',action='write') write(11) 11 write(11) 1.1 close(11) end

更多推荐

将未格式化(二进制数据)写入标准输出

本文发布于:2023-11-08 15:54:40,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:二进制数   标准

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!