简体   繁体   English

如何在fortran77中解压缩文件?

[英]How to decompress a file in fortran77?

I have a compressed file. 我有一个压缩文件。 Let's ignore the tar command because I'm not sure it is compressed with that. 让我们忽略tar命令,因为我不确定它是否已被压缩。 All I know is that it is compressed in fortran77 and that is what I should use to decompress it. 我所知道的是,它在fortran77中已压缩,这就是我应使用的解压缩方式。 How can I do it? 我该怎么做? Is decompression a one way road or do I need a certain header file that will lead (direct) the decompression? 减压是单向的,还是我需要某个特定的头文件来引导(直接)减压?

It's not a .Z file. 这不是.Z文件。 It ends at something else. 它以其他方式结束。 What do I need to decompress it? 我需要解压缩什么? I know the format of the final decompressed archive. 我知道最终解压缩的存档的格式。

Is it possible that the file is compressed thru a simple way but it appears with a different extension? 是否有可能通过一种简单的方法压缩文件,但其扩展名却有所不同?

First, let's get the "fortran" part out of the equation. 首先,让我们摆脱方程式中的“ fortran”部分。 There is no standard (and by that, I mean the fortran standard) way to either compress or decompress files, since fortran doesn't have a compression utility as part of the language. 没有任何一种标准的方法来压缩或解压缩文件(因此,我的意思是fortran标准),因为fortran并没有压缩实用程序作为语言的一部分。 Maybe someone written some of their own, but that's entirely up to him. 也许有人写了一些自己的东西,但这完全取决于他。

So, you're stuck with publicly available compression utilities, and such. 因此,您将不得不使用公用的压缩实用程序等。 On systems which have those available, and on compilers which support it (it varies), you can use the SYSTEM function, which executes the system command by passing a command string to the operating system's command interpreter (I know it exists in cvf, probably ivf ... you should probably look it up in help of your compiler). 在具有可用功能的系统上以及在支持该功能的编译器上(它会有所不同),您可以使用SYSTEM函数,该函数通过将命令字符串传递给操作系统的命令解释器来执行系统命令(我知道它可能存在于cvf中) ivf ...您可能应该在编译器的帮助下进行查找。

Since you asked a similar question already I assume you're still having problem with this. 既然您已经问过类似的问题,我想您仍然对此有疑问。 You mentioned that "it was compressed with fortran77". 您提到“它被fortran77压缩了”。 What do you mean by that ? 你是什​​么意思 ? That someone builded a compression utility in f77 and used it ? 有人在f77中构建了压缩实用程序并使用了它? So that would make it a custom solution ? 这样就可以使其成为自定义解决方案?

If it's some kind of a custom solution, then it can practically be anything, since a lot of algorithms can serve as "compression algorithms" (writing file as binary compared to plain text will save a few bytes; voila, "compression") 如果是某种自定义解决方案,那么实际上可以是任何东西,因为许多算法都可以用作“压缩算法”(与纯文本相比,将文件写入二进制格式将节省一些字节;瞧,“压缩”)

Or have I misunderstood something ? 还是我误会了什么? Please, elaborate this a little. 请稍微详细说明一下。

My guess is that you have a binary file , which is output by a Fortran program. 我的猜测是您有一个二进制文件 ,该文件由Fortran程序输出。 These can look like compressed files because they are not readable in a text editor. 这些文件看起来像压缩文件,因为它们在文本编辑器中不可读。

Fortran allows you to write the in-memory data out to a file without formatting it, so that you can reload it later without having to parse it. Fortran允许您将内存中的数据写到文件中而无需格式化,因此您以后可以重新加载它而不必解析它。 The problem, however, is that you need that original source code in order to see what types of variables are written in the file. 但是,问题在于您需要该原始源代码才能查看文件中写入了哪些类型的变量。

If you have no access to the fortran source code, but a lot of time to spare, you could write some simple fortran program and guess what types of variables are being used. 如果您无法访问fortran源代码,但是有很多时间可以使用,则可以编写一些简单的fortran程序,然后猜测正在使用什么类型的变量。 I wouldn't advise it, though, as Fortran is not very forgiving. 但是,我不建议这样做,因为Fortran不太宽容。

If you want some simple source code to try, look at this page which details binary read and write in Fortran, and includes a code sample. 如果您想尝试一些简单的源代码,请查看此页面该页面详细介绍了在Fortran中进行二进制读写的过程,并包括一个代码示例。 Just start by replacing reclength=reclength*4 with reclength=reclength*2 for a double precision real. 只需将reclength=reclength*4替换为reclength=reclength*2 ,即可获得双精度实数。

There is no standard decompression method, there are tons. 没有标准的减压方法,有很多吨。 You will need to know the method used to compress it in order to decompress it. 您将需要知道用于压缩它的方法以对其进行解压缩。

You said that the file extension was not .Z, but something else. 您说文件扩展名不是.Z,而是其他。 What was that something else? 那还有什么?

If it's .gz (which is very common on Unix systems), "gunzip" is the proper command. 如果它是.gz(在Unix系统上很常见),则“ gunzip”是正确的命令。 If it's .tgz, you can gunzip and untar it. 如果是.tgz,则可以将其压缩并解压缩。 (Or you can read the man page for tar(1), since it probably has the ability to gunzip and extract together.) (或者,您可以阅读tar(1)的手册页,因为它可能具有一起压缩和解压的能力。)

If it's on Windows, see if Windows can read it directly, as the file system itself appears to support the ZIP format. 如果在Windows上,请查看Windows是否可以直接读取它,因为文件系统本身似乎支持ZIP格式。

If something else, please just list the file name (or, if there are security implications, the file name beginning with the first period), and we might be able to figure it out. 如果有其他问题,请仅列出文件名(或者,如果涉及安全性,则以第一个句点开头),我们也许可以找出来。

You can check to see if it's a known compressed file type with the file command. 您可以使用file命令检查它是否是已知的压缩文件类型。 Assuming file returns something like "binary file" then you're almost certainly looking at plain binary data. 假设文件返回的内容类似于“二进制文件”,那么几乎可以肯定您正在查看纯二进制数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM