- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi folks,
I'm trying to port a code from HP-UX over to Linux/ifort. Each binary file that this code writes is prefixed by a ~100 character string that contains some critical information (the date of execution, the version of the code that created it, and a traceable certification that the file was created by a controlled, V&V'd executable). Unfortunately, my predecesor saw fit to write the part that deals with this ~100 character string in C. These strings need to be read by other Fortran codes.
Where I'm getting hung up (I think) is on these 4-byte leading/trailing length fields (discussed in the "Record Types" manual page). The C code that works on the HP-UX machines looks something like this (cfgstrg is the desired string to be written - these strings are the same length every time):
strConv[0]=(char)('');
strConv[1]=(char)('');
strConv[2]=(char)('');
strConv[3]=(char)('u');
fwrite(strConv, sizeof(char)*4, 1, wFile);
fwrite(cfgstrg, sizeof(char)*cfglen, 1, wFile);
fwrite(strConv, sizeof(char)*4, 1, wFile);
Our ifort/Linux system doesn't seem to dig that. I've poked around online a fair amount, but I'm having trouble finding exactly what's supposed to go in those leading/trailing length fields. Could someone point me in the right direction? I've pulled a fair amount of my own hair out diagnosing and trying to solve this one. Any help is much appreciated.
Thanks,
Greg
I'm trying to port a code from HP-UX over to Linux/ifort. Each binary file that this code writes is prefixed by a ~100 character string that contains some critical information (the date of execution, the version of the code that created it, and a traceable certification that the file was created by a controlled, V&V'd executable). Unfortunately, my predecesor saw fit to write the part that deals with this ~100 character string in C. These strings need to be read by other Fortran codes.
Where I'm getting hung up (I think) is on these 4-byte leading/trailing length fields (discussed in the "Record Types" manual page). The C code that works on the HP-UX machines looks something like this (cfgstrg is the desired string to be written - these strings are the same length every time):
strConv[0]=(char)('');
strConv[1]=(char)('');
strConv[2]=(char)('');
strConv[3]=(char)('u');
fwrite(strConv, sizeof(char)*4, 1, wFile);
fwrite(cfgstrg, sizeof(char)*cfglen, 1, wFile);
fwrite(strConv, sizeof(char)*4, 1, wFile);
Our ifort/Linux system doesn't seem to dig that. I've poked around online a fair amount, but I'm having trouble finding exactly what's supposed to go in those leading/trailing length fields. Could someone point me in the right direction? I've pulled a fair amount of my own hair out diagnosing and trying to solve this one. Any help is much appreciated.
Thanks,
Greg
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looks like big-endian 32-bit record lengths. If you open the file with CONVERT='BIG_ENDIAN' and FORM='UNFORMATTED', it should read fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
Excellent! Yes, it works.
But ideally, I'd rather have the code generate leading/trailing fields in the new native format, rather than carry over the old, BIG_ENDIAN formatting. The new system is going to be x86_64 linux. Using the existing C code, what would be the appropriate 4-byte fields for that? Also, this particular code only seems to work when compiled in 32-bit mode. Would that affect the leading/trailing fields?
Thanks, you're a lifesaver.
Greg
Excellent! Yes, it works.
But ideally, I'd rather have the code generate leading/trailing fields in the new native format, rather than carry over the old, BIG_ENDIAN formatting. The new system is going to be x86_64 linux. Using the existing C code, what would be the appropriate 4-byte fields for that? Also, this particular code only seems to work when compiled in 32-bit mode. Would that affect the leading/trailing fields?
Thanks, you're a lifesaver.
Greg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's no difference in the record structure on x64. Both 32- and 64-bit compilers support record lengths larger than 2GB using a "segment" strategy that is described in the documentation. The layout is compatible with 32-bit lengths for normal size records.
If you want to write these headers in C, just write the length as an "int".
If you want to write these headers in C, just write the length as an "int".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Writing the length as an "int" did the trick. Thanks, again!

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page