[2c47b73] | 1 | /** |
---|
| 2 | * @file rw.c |
---|
| 3 | * @author Sheng Di |
---|
| 4 | * @date April, 2015 |
---|
| 5 | * @brief io interface for fortrance |
---|
| 6 | * (C) 2015 by Mathematics and Computer Science (MCS), Argonne National Laboratory. |
---|
| 7 | * See COPYRIGHT in top-level directory. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include <stdio.h> |
---|
| 11 | #include <stdlib.h> |
---|
| 12 | #include <string.h> |
---|
| 13 | #include "rw.h" |
---|
| 14 | |
---|
| 15 | void checkfilesizec_(char *srcFilePath, int *len, size_t *filesize) |
---|
| 16 | { |
---|
| 17 | int i; |
---|
| 18 | int status; |
---|
| 19 | char s[*len+1]; |
---|
| 20 | for(i=0;i<*len;i++) |
---|
| 21 | s[i]=srcFilePath[i]; |
---|
| 22 | s[*len]='\0'; |
---|
| 23 | *filesize = checkFileSize(s, &status); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | void readbytefile_(char *srcFilePath, int *len, unsigned char *bytes, size_t *byteLength) |
---|
| 27 | { |
---|
| 28 | size_t i; |
---|
| 29 | int ierr; |
---|
| 30 | char s[*len+1]; |
---|
| 31 | for(i=0;i<*len;i++) |
---|
| 32 | s[i]=srcFilePath[i]; |
---|
| 33 | s[*len]='\0'; |
---|
| 34 | unsigned char *tmp_bytes = readByteData(s, byteLength, &ierr); |
---|
| 35 | memcpy(bytes, tmp_bytes, *byteLength); |
---|
| 36 | free(tmp_bytes); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | void readdoublefile_(char *srcFilePath, int *len, double *data, size_t *nbEle) |
---|
| 40 | { |
---|
| 41 | size_t i; |
---|
| 42 | int ierr; |
---|
| 43 | char s[*len+1]; |
---|
| 44 | for(i=0;i<*len;i++) |
---|
| 45 | s[i]=srcFilePath[i]; |
---|
| 46 | s[*len]='\0'; |
---|
| 47 | double *tmp_data = readDoubleData(s, nbEle, &ierr); |
---|
| 48 | memcpy(data, tmp_data, *nbEle); |
---|
| 49 | free(tmp_data); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | void readfloatfile_(char *srcFilePath, int *len, float *data, size_t *nbEle) |
---|
| 53 | { |
---|
| 54 | size_t i; |
---|
| 55 | int ierr; |
---|
| 56 | char s[*len+1]; |
---|
| 57 | for(i=0;i<*len;i++) |
---|
| 58 | s[i]=srcFilePath[i]; |
---|
| 59 | s[*len]='\0'; |
---|
| 60 | float *tmp_data = readFloatData(s, nbEle, &ierr); |
---|
| 61 | memcpy(data, tmp_data, *nbEle); |
---|
| 62 | free(tmp_data); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | void writebytefile_(unsigned char *bytes, size_t *byteLength, char *tgtFilePath, int *len) |
---|
| 66 | { |
---|
| 67 | size_t i; |
---|
| 68 | int ierr; |
---|
| 69 | char s[*len+1]; |
---|
| 70 | for(i=0;i<*len;i++) |
---|
| 71 | s[i]=tgtFilePath[i]; |
---|
| 72 | s[*len]='\0'; |
---|
| 73 | writeByteData(bytes, *byteLength, s, &ierr); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | void writedoublefile_(double *data, size_t *nbEle, char *tgtFilePath, int *len) |
---|
| 77 | { |
---|
| 78 | size_t i; |
---|
| 79 | int ierr; |
---|
| 80 | char s[*len+1]; |
---|
| 81 | for(i=0;i<*len;i++) |
---|
| 82 | s[i]=tgtFilePath[i]; |
---|
| 83 | s[*len]='\0'; |
---|
| 84 | writeDoubleData(data, *nbEle, s, &ierr); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void writefloatfile_(float *data, size_t *nbEle, char *tgtFilePath, int *len) |
---|
| 88 | { |
---|
| 89 | size_t i; |
---|
| 90 | int ierr; |
---|
| 91 | char s[*len+1]; |
---|
| 92 | for(i=0;i<*len;i++) |
---|
| 93 | s[i]=tgtFilePath[i]; |
---|
| 94 | s[*len]='\0'; |
---|
| 95 | writeFloatData(data, *nbEle, s, &ierr); |
---|
| 96 | } |
---|