I am trying to read a binary file consisting of signed 16 bit integers and there are exactly 51840000 of them. The code in C that accomplishes this looks like this:
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
int main()
{
int16_t *arr = malloc(51840000*sizeof(int16_t));
FILE *fp;
fp = fopen("LDEM_45N_400M.IMG", "rb");
if(fp == NULL)
{
printf("Error opening file\n");
exit(1);
}
printf("Testing fread() function: \n\n");
fread(arr, sizeof(*arr), 51840000, fp);
fclose(fp);
printf("%d \n", arr[51840000-2]);
free(arr);
return 0;
}
How would i read such a file in Fortran? IO in Fortran has always been very mysterious to me.