Task 205: .F18 File Format
Task 205: .F18 File Format
File Format Specifications for the .F18 File Format
The .F18 file extension is associated with Fortran language source code files in free form, as defined by Fortran compilers supporting the Fortran 2018 standard (ISO/IEC 1539:2018). This standard specifies the syntax, semantics, and structure of Fortran programs, including features introduced in Fortran 2018 such as enhanced interoperability with C, improved parallel execution capabilities, and additional mathematical functions. The file itself is a plain text file containing Fortran source code, with no binary encoding or structured header beyond the language's syntactic rules. Public sources like Wikipedia confirm this usage, while some file extension databases classify it as an uncommon binary type due to limited adoption, but the Fortran association is the most substantiated.
- List of all the properties of this file format intrinsic to its file system.
Since the .F18 file format is a plain text source code file, it does not define unique internal properties like binary headers or fields. Instead, the properties intrinsic to its representation in the file system are the standard metadata attributes managed by the operating system. These include:
- File name (including the .F18 extension)
- File path (absolute or relative location in the file system)
- File size (in bytes)
- Creation time (timestamp when the file was created)
- Modification time (timestamp of the last content change)
- Access time (timestamp of the last read access)
- Permissions (read, write, execute rights for owner, group, and others, often represented in octal notation or symbolic form)
- Owner user ID (UID of the file owner)
- Group ID (GID of the file group)
- Inode number (unique identifier on Unix-like systems)
- File type (typically "regular file")
- Number of hard links (references to the file in the file system)
These properties are not specific to the .F18 format but are common to all files in most file systems (e.g., NTFS, ext4). They can be accessed via system calls or APIs without parsing the file content.
- Two direct download links for files of format .F18.
The .F18 extension is rarely used in practice, as Fortran source code is more commonly saved with .f90 or .f08 extensions for free-form code. No publicly indexed .F18 files were found in searches. However, the following direct links provide Fortran 2018-compatible source code files (with .f90 extension) that can be downloaded and renamed to .F18 for compatibility with supporting compilers:
- https://raw.githubusercontent.com/scivision/fortran2018-examples/master/test/coarray/co_sum.f90
- https://raw.githubusercontent.com/scivision/fortran2018-examples/master/test/iso_c_binding/c_f_string.f90
These examples demonstrate Fortran 2018 features and can be treated as .F18 files.
- Write a ghost blog embedded html javascript that allows a user to drag n drop a file of format .F18 and it will dump to screen all these properties.
Below is an HTML snippet with embedded JavaScript suitable for embedding in a Ghost blog (or any HTML-compatible platform). It creates a drag-and-drop area where a user can drop a .F18 file. The script uses the browser's File API to extract and display available file system properties (limited to what browsers expose: name, size, type, last modified time). It does not access OS-specific properties like permissions or owner for security reasons. If the file is text-based, it also reads and displays the content as an additional "property."
- Write a python class that can open any file of format .F18 and decode read and write and print to console all the properties from the above list.
Below is a Python class using the os
and stat
modules to open a .F18 file, read its content (decoding as UTF-8 text), write new content if needed, and print the file system properties. Permissions are shown in octal format.
import os
import stat
import time
class F18FileHandler:
def __init__(self, filepath):
self.filepath = filepath
self.content = None
def open_and_read(self):
"""Open and read the file content, decoding as text."""
with open(self.filepath, 'r', encoding='utf-8') as f:
self.content = f.read()
return self.content
def write(self, new_content):
"""Write new content to the file."""
with open(self.filepath, 'w', encoding='utf-8') as f:
f.write(new_content)
self.content = new_content
def get_properties(self):
"""Retrieve and return file system properties as a dictionary."""
st = os.stat(self.filepath)
properties = {
'File name': os.path.basename(self.filepath),
'File path': os.path.abspath(self.filepath),
'File size': st.st_size,
'Creation time': time.ctime(st.st_ctime),
'Modification time': time.ctime(st.st_mtime),
'Access time': time.ctime(st.st_atime),
'Permissions': oct(stat.S_IMODE(st.st_mode)),
'Owner user ID': st.st_uid,
'Group ID': st.st_gid,
'Inode number': st.st_ino,
'File type': 'regular file' if stat.S_ISREG(st.st_mode) else 'other',
}
return properties
def print_properties(self):
"""Print all properties to console."""
props = self.get_properties()
for key, value in props.items():
print(f"{key}: {value}")
# Example usage:
# handler = F18FileHandler('example.f18')
# handler.open_and_read()
# handler.print_properties()
# handler.write('New Fortran code')
- Write a java class that can open any file of format .F18 and decode read and write and print to console all the properties from the above list.
Below is a Java class using java.nio.file
to handle the file, read content as text, write new content, and retrieve/print file system properties. Some properties like inode are platform-specific and may require additional attributes on Unix systems.
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.time.Instant;
public class F18FileHandler {
private final Path filepath;
private String content;
public F18FileHandler(String filepath) {
this.filepath = Paths.get(filepath);
}
public String openAndRead() throws IOException {
content = new String(Files.readAllBytes(filepath), StandardCharsets.UTF_8);
return content;
}
public void write(String newContent) throws IOException {
Files.write(filepath, newContent.getBytes(StandardCharsets.UTF_8));
content = newContent;
}
public void printProperties() throws IOException {
BasicFileAttributes attrs = Files.readAttributes(filepath, BasicFileAttributes.class);
PosixFileAttributes posixAttrs = null;
try {
posixAttrs = Files.readAttributes(filepath, PosixFileAttributes.class);
} catch (UnsupportedOperationException e) {
// Posix not supported on this platform
}
System.out.println("File name: " + filepath.getFileName());
System.out.println("File path: " + filepath.toAbsolutePath());
System.out.println("File size: " + attrs.size());
System.out.println("Creation time: " + Instant.ofEpochMilli(attrs.creationTime().toMillis()));
System.out.println("Modification time: " + Instant.ofEpochMilli(attrs.lastModifiedTime().toMillis()));
System.out.println("Access time: " + Instant.ofEpochMilli(attrs.lastAccessTime().toMillis()));
if (posixAttrs != null) {
System.out.println("Permissions: " + PosixFilePermissions.toString(posixAttrs.permissions()));
System.out.println("Owner user ID: " + posixAttrs.owner().getName()); // Name instead of UID
System.out.println("Group ID: " + posixAttrs.group().getName()); // Name instead of GID
}
System.out.println("Inode number: " + (attrs.isOther() ? "N/A" : attrs.fileKey())); // Approximate
System.out.println("File type: " + (attrs.isRegularFile() ? "regular file" : "other"));
}
// Example usage:
// public static void main(String[] args) throws IOException {
// F18FileHandler handler = new F18FileHandler("example.f18");
// handler.openAndRead();
// handler.printProperties();
// handler.write("New Fortran code");
// }
}
- Write a javascript class that can open any file of format .F18 and decode read and write and print to console all the properties from the above list.
Below is a JavaScript class for Node.js (using fs
module) to handle the file, read as text, write new content, and print properties. Browser environments have limited access to file system properties, so this assumes Node.js.
const fs = require('fs');
const path = require('path');
const os = require('os');
class F18FileHandler {
constructor(filepath) {
this.filepath = filepath;
this.content = null;
}
openAndRead() {
this.content = fs.readFileSync(this.filepath, 'utf-8');
return this.content;
}
write(newContent) {
fs.writeFileSync(this.filepath, newContent, 'utf-8');
this.content = newContent;
}
getProperties() {
const stats = fs.statSync(this.filepath);
return {
'File name': path.basename(this.filepath),
'File path': path.resolve(this.filepath),
'File size': stats.size,
'Creation time': stats.birthtime.toISOString(),
'Modification time': stats.mtime.toISOString(),
'Access time': stats.atime.toISOString(),
'Permissions': (stats.mode & 0o777).toString(8), // Octal permissions
'Owner user ID': stats.uid,
'Group ID': stats.gid,
'Inode number': stats.ino,
'File type': stats.isFile() ? 'regular file' : 'other',
};
}
printProperties() {
const props = this.getProperties();
for (const [key, value] of Object.entries(props)) {
console.log(`${key}: ${value}`);
}
}
}
// Example usage:
// const handler = new F18FileHandler('example.f18');
// handler.openAndRead();
// handler.printProperties();
// handler.write('New Fortran code');
- Write a c class that can open any file of format .F18 and decode read and write and print to console all the properties from the above list.
C does not have built-in classes, so below is a struct with associated functions to open the file, read content as text, write new content, and print file system properties using stat
.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
typedef struct {
char *filepath;
char *content;
} F18FileHandler;
F18FileHandler* create_handler(const char *filepath) {
F18FileHandler *handler = malloc(sizeof(F18FileHandler));
handler->filepath = strdup(filepath);
handler->content = NULL;
return handler;
}
void destroy_handler(F18FileHandler *handler) {
free(handler->filepath);
free(handler->content);
free(handler);
}
char* open_and_read(F18FileHandler *handler) {
FILE *f = fopen(handler->filepath, "r");
if (!f) return NULL;
fseek(f, 0, SEEK_END);
long size = ftell(f);
fseek(f, 0, SEEK_SET);
handler->content = malloc(size + 1);
fread(handler->content, 1, size, f);
handler->content[size] = '\0';
fclose(f);
return handler->content;
}
void write_file(F18FileHandler *handler, const char *new_content) {
FILE *f = fopen(handler->filepath, "w");
if (f) {
fprintf(f, "%s", new_content);
fclose(f);
free(handler->content);
handler->content = strdup(new_content);
}
}
void print_properties(const F18FileHandler *handler) {
struct stat st;
if (stat(handler->filepath, &st) == 0) {
printf("File name: %s\n", strrchr(handler->filepath, '/') ? strrchr(handler->filepath, '/') + 1 : handler->filepath);
printf("File path: %s\n", handler->filepath);
printf("File size: %ld\n", st.st_size);
printf("Creation time: %s", ctime(&st.st_ctime));
printf("Modification time: %s", ctime(&st.st_mtime));
printf("Access time: %s", ctime(&st.st_atime));
printf("Permissions: %o\n", st.st_mode & 0777);
printf("Owner user ID: %d\n", st.st_uid);
printf("Group ID: %d\n", st.st_gid);
printf("Inode number: %ld\n", st.st_ino);
printf("File type: %s\n", S_ISREG(st.st_mode) ? "regular file" : "other");
}
}
// Example usage:
// int main() {
// F18FileHandler *handler = create_handler("example.f18");
// open_and_read(handler);
// print_properties(handler);
// write_file(handler, "New Fortran code");
// destroy_handler(handler);
// return 0;
// }