Mercurial > octave-nkf
comparison src/file-io.cc @ 2318:31e7eb125d89
[project @ 1996-07-14 22:44:50 by jwe]
author | jwe |
---|---|
date | Sun, 14 Jul 1996 22:46:29 +0000 |
parents | 1351500ed277 |
children | fdc6e2f81333 |
comparison
equal
deleted
inserted
replaced
2317:8c09c04f7747 | 2318:31e7eb125d89 |
---|---|
256 | 256 |
257 int md = fopen_mode_to_ios_mode (mode); | 257 int md = fopen_mode_to_ios_mode (mode); |
258 | 258 |
259 if (! error_state) | 259 if (! error_state) |
260 { | 260 { |
261 octave_base_stream::arch_type at | 261 oct_mach_info::float_format flt_fmt = |
262 = octave_stream::string_to_arch_type (arch); | 262 oct_mach_info::string_to_float_format (arch); |
263 | 263 |
264 if (! error_state) | 264 if (! error_state) |
265 retval = new octave_fstream (name, md, at); | 265 retval = new octave_fstream (name, md, flt_fmt); |
266 } | 266 } |
267 | 267 |
268 return retval; | 268 return retval; |
269 } | 269 } |
270 | 270 |
299 | 299 |
300 return retval; | 300 return retval; |
301 } | 301 } |
302 | 302 |
303 DEFUN (fopen, args, , | 303 DEFUN (fopen, args, , |
304 "FILENUM = fopen (FILENAME, MODE [, ARCH]): open a file\n\ | 304 "[FILENUM, ERRMSG] = fopen (FILENAME, MODE [, ARCH]): open a file\n\ |
305 \n\ | 305 \n\ |
306 Valid values for mode include:\n\ | 306 FILENAME is a string specifying the name of the file.\n\ |
307 \n\ | |
308 MODE is a string specifying whether the file should be opened for\n\ | |
309 reading, writing, or both. Valid values for MODE include:\n\ | |
307 \n\ | 310 \n\ |
308 r : open text file for reading\n\ | 311 r : open text file for reading\n\ |
309 w : open text file for writing; discard previous contents if any\n\ | 312 w : open text file for writing; discard previous contents if any\n\ |
310 a : append; open or create text file for writing at end of file\n\ | 313 a : append; open or create text file for writing at end of file\n\ |
311 r+ : open text file for update (i.e., reading and writing)\n\ | 314 r+ : open text file for update (i.e., reading and writing)\n\ |
312 w+ : create text file for update; discard previous contents if any\n\ | 315 w+ : create text file for update; discard previous contents if any\n\ |
313 a+ : append; open or create text file for update, writing at end\n\ | 316 a+ : append; open or create text file for update, writing at end\n\ |
314 \n\ | 317 \n\ |
315 Update mode permits reading from and writing to the same file.") | 318 Update mode permits reading from and writing to the same file.\n\ |
319 \n\ | |
320 ARCH is a string specifying the default data format for the file.\n\ | |
321 Valid values for ARCH are:\n\ | |
322 \n\ | |
323 native -- the format of the current machine (this is the default)\n\ | |
324 ieee-le -- IEEE big endian\n\ | |
325 ieee-be -- IEEE little endian\n\ | |
326 vaxd -- VAX D floating format\n\ | |
327 vaxg -- VAX G floating format\n\ | |
328 cray -- Cray floating format\n | |
329 \n\ | |
330 however, conversions are currently only supported for ieee-be, and\n\ | |
331 ieee-le formats.\n\ | |
332 \n\ | |
333 \n\ | |
334 FILENUM is a number that can be used to refer to the open file.\n\ | |
335 If fopen fails, FILENUM is set to -1 and ERRMSG contains a\n\ | |
336 system-dependent error message") | |
316 { | 337 { |
317 octave_value_list retval = -1.0; | 338 octave_value_list retval = -1.0; |
318 | 339 |
319 int nargin = args.length (); | 340 int nargin = args.length (); |
320 | 341 |
805 { | 826 { |
806 string prec = prec_arg.string_value (); | 827 string prec = prec_arg.string_value (); |
807 | 828 |
808 if (! error_state) | 829 if (! error_state) |
809 { | 830 { |
810 octave_base_stream::data_type dt | 831 oct_data_conv::data_type dt |
811 = octave_stream::string_to_data_type (prec); | 832 = oct_data_conv::string_to_data_type (prec); |
812 | 833 |
813 if (! error_state) | 834 if (! error_state) |
814 { | 835 { |
815 double dskip = skip_arg.double_value (); | 836 double dskip = skip_arg.double_value (); |
816 | 837 |
822 | 843 |
823 string arch = arch_arg.string_value (); | 844 string arch = arch_arg.string_value (); |
824 | 845 |
825 if (! error_state) | 846 if (! error_state) |
826 { | 847 { |
827 octave_base_stream::arch_type at | 848 oct_mach_info::float_format flt_fmt |
828 = octave_stream::string_to_arch_type (arch); | 849 = oct_mach_info::string_to_float_format (arch); |
829 | 850 |
830 if (! error_state) | 851 if (! error_state) |
831 retval = os.read (size, dt, skip, at, count); | 852 retval = os.read (size, dt, skip, flt_fmt, count); |
832 } | 853 } |
833 else | 854 else |
834 ::error ("fread: architecture type must be a string"); | 855 ::error ("fread: architecture type must be a string"); |
835 } | 856 } |
836 else | 857 else |
852 } | 873 } |
853 | 874 |
854 DEFUN (fread, args, , | 875 DEFUN (fread, args, , |
855 "[DATA, COUNT] = fread (FILENUM [, SIZE] [, PRECISION] [, SKIP] [, ARCH])\n\ | 876 "[DATA, COUNT] = fread (FILENUM [, SIZE] [, PRECISION] [, SKIP] [, ARCH])\n\ |
856 \n\ | 877 \n\ |
857 Reads data in binary form of type PRECISION from a file.\n\ | 878 Reads data in binary form of type PRECISION from a file.\n\ |
858 \n\ | 879 \n\ |
859 FILENUM : file number from fopen\n\ | 880 FILENUM : file number from fopen\n\ |
860 SIZE : size specification for the Data matrix\n\ | 881 \n\ |
861 PRECISION : type of data to read, valid types are\n\ | 882 SIZE : size specification for the data matrix\n\ |
862 \n\ | 883 \n\ |
863 \"char\" \"schar\" \"short\" \"int\" \"long\" \"float\"\n\ | 884 PRECISION : string specifying type of data to read, valid types are\n\ |
864 \"double\" \"uchar\" \"ushort\" \"uint\" \"ulong\"\n\ | 885 \n\ |
865 \n\ | 886 char, char*1, integer*1, int8 -- character\n\ |
866 DATA : matrix in which the data is stored\n\ | 887 schar, signed char -- signed character\n\ |
867 COUNT : number of elements read") | 888 uchar, unsigned char -- unsigned character (default)\n\ |
889 short -- short integer\n\ | |
890 ushort, unsigned short -- unsigned short integer\n\ | |
891 int -- integer\n\ | |
892 uint, unsigned int -- unsigned integer\n\ | |
893 long -- long integer\n\ | |
894 ulong, unsigned long -- unsigned long integer\n\ | |
895 float, float32, real*4 -- single precision float\n\ | |
896 double, float64, real*8 -- double precision float\n\ | |
897 int16, integer*2 -- two byte integer\n\ | |
898 int32, integer*4 -- four byte integer\n\ | |
899 \n\ | |
900 SKIP : number of bytes to skip before each element is read\n\ | |
901 (default is 0)\n\ | |
902 \n\ | |
903 ARCH : string specifying the data format for the file. Valid | |
904 values are\n\ | |
905 \n\ | |
906 native -- the format of the current machine (default)\n\ | |
907 ieee-le -- IEEE big endian\n\ | |
908 ieee-be -- IEEE little endian\n\ | |
909 vaxd -- VAX D floating format\n\ | |
910 vaxg -- VAX G floating format\n\ | |
911 cray -- Cray floating format\n | |
912 \n\ | |
913 however, conversions are currently only supported for ieee-be, and\n\ | |
914 ieee-le formats.\n\ | |
915 \n\ | |
916 \n\ | |
917 DATA : matrix in which the data is stored\n\ | |
918 \n\ | |
919 COUNT : number of elements read") | |
868 { | 920 { |
869 octave_value_list retval; | 921 octave_value_list retval; |
870 | 922 |
871 int nargin = args.length (); | 923 int nargin = args.length (); |
872 | 924 |
873 if (nargin > 1 && nargin < 6) | 925 if (nargin > 0 && nargin < 6) |
874 { | 926 { |
875 retval(1) = -1.0; | 927 retval(1) = -1.0; |
876 retval(0) = Matrix (); | 928 retval(0) = Matrix (); |
877 | 929 |
878 octave_stream *os = octave_stream_list::lookup (args(0)); | 930 octave_stream *os = octave_stream_list::lookup (args(0)); |
887 | 939 |
888 octave_value skip = (nargin > 3) | 940 octave_value skip = (nargin > 3) |
889 ? args(3) : octave_value (0.0); | 941 ? args(3) : octave_value (0.0); |
890 | 942 |
891 octave_value arch = (nargin > 4) | 943 octave_value arch = (nargin > 4) |
892 ? args(4) : octave_value ("native"); | 944 ? args(4) : octave_value ("unknown"); |
893 | 945 |
894 int count = -1; | 946 int count = -1; |
895 | 947 |
896 octave_value tmp = do_fread (*os, size, prec, skip, arch, count); | 948 octave_value tmp = do_fread (*os, size, prec, skip, arch, count); |
897 | 949 |
916 | 968 |
917 string prec = prec_arg.string_value (); | 969 string prec = prec_arg.string_value (); |
918 | 970 |
919 if (! error_state) | 971 if (! error_state) |
920 { | 972 { |
921 octave_base_stream::data_type dt | 973 oct_data_conv::data_type dt |
922 = octave_stream::string_to_data_type (prec); | 974 = oct_data_conv::string_to_data_type (prec); |
923 | 975 |
924 if (! error_state) | 976 if (! error_state) |
925 { | 977 { |
926 double dskip = skip_arg.double_value (); | 978 double dskip = skip_arg.double_value (); |
927 | 979 |
933 | 985 |
934 string arch = arch_arg.string_value (); | 986 string arch = arch_arg.string_value (); |
935 | 987 |
936 if (! error_state) | 988 if (! error_state) |
937 { | 989 { |
938 octave_base_stream::arch_type at | 990 oct_mach_info::float_format flt_fmt |
939 = octave_stream::string_to_arch_type (arch); | 991 = oct_mach_info::string_to_float_format (arch); |
940 | 992 |
941 if (! error_state) | 993 if (! error_state) |
942 retval = os.write (data, dt, skip, at); | 994 retval = os.write (data, dt, skip, flt_fmt); |
943 } | 995 } |
944 else | 996 else |
945 ::error ("fwrite: architecture type must be a string"); | 997 ::error ("fwrite: architecture type must be a string"); |
946 } | 998 } |
947 else | 999 else |
958 } | 1010 } |
959 | 1011 |
960 DEFUN (fwrite, args, , | 1012 DEFUN (fwrite, args, , |
961 "COUNT = fwrite (FILENUM, DATA [, PRECISION] [, SKIP] [, ARCH])\n\ | 1013 "COUNT = fwrite (FILENUM, DATA [, PRECISION] [, SKIP] [, ARCH])\n\ |
962 \n\ | 1014 \n\ |
963 Writes data to a file in binary form of size PRECISION\n\ | 1015 Writes data to a file in binary form of size PRECISION\n\ |
964 \n\ | 1016 \n\ |
965 FILENUM : file number from fopen\n\ | 1017 FILENUM : file number from fopen\n\ |
966 DATA : matrix of elements to be written\n\ | 1018 \n\ |
967 PRECISION : type of data to read, valid types are\n\ | 1019 DATA : matrix of elements to be written\n\ |
968 \n\ | 1020 \n\ |
969 \"char\" \"schar\" \"short\" \"int\" \"long\" \"float\"\n\ | 1021 PRECISION : string specifying type of data to read, valid types are\n\ |
970 \"double\" \"uchar\" \"ushort\" \"uint\" \"ulong\"\n\ | 1022 \n\ |
971 \n\ | 1023 char, char*1, integer*1, int8 -- character\n\ |
972 COUNT : number of elements written") | 1024 schar, signed char -- signed character\n\ |
1025 uchar, unsigned char -- unsigned character (default)\n\ | |
1026 short -- short integer\n\ | |
1027 ushort, unsigned short -- unsigned short integer\n\ | |
1028 int -- integer\n\ | |
1029 uint, unsigned int -- unsigned integer\n\ | |
1030 long -- long integer\n\ | |
1031 ulong, unsigned long -- unsigned long integer\n\ | |
1032 float, float32, real*4 -- single precision float\n\ | |
1033 double, float64, real*8 -- double precision float\n\ | |
1034 int16, integer*2 -- two byte integer\n\ | |
1035 int32, integer*4 -- four byte integer\n\ | |
1036 \n\ | |
1037 SKIP : number of bytes to skip before each element is read\n\ | |
1038 (the default is 0)\n\ | |
1039 \n\ | |
1040 ARCH : string specifying the data format for the file. Valid | |
1041 values are\n\ | |
1042 \n\ | |
1043 native -- the format of the current machine (default)\n\ | |
1044 ieee-le -- IEEE big endian\n\ | |
1045 ieee-be -- IEEE little endian\n\ | |
1046 vaxd -- VAX D floating format\n\ | |
1047 vaxg -- VAX G floating format\n\ | |
1048 cray -- Cray floating format\n | |
1049 \n\ | |
1050 however, conversions are currently only supported for ieee-be, and\n\ | |
1051 ieee-le formats.\n\ | |
1052 \n\ | |
1053 \n\ | |
1054 COUNT : number of elements written") | |
973 { | 1055 { |
974 octave_value retval = -1.0; | 1056 octave_value retval = -1.0; |
975 | 1057 |
976 int nargin = args.length (); | 1058 int nargin = args.length (); |
977 | 1059 |
980 octave_stream *os = octave_stream_list::lookup (args(0)); | 1062 octave_stream *os = octave_stream_list::lookup (args(0)); |
981 | 1063 |
982 if (os) | 1064 if (os) |
983 { | 1065 { |
984 octave_value data = args(1); | 1066 octave_value data = args(1); |
985 octave_value prec = (nargin > 2) ? args(2) : octave_value ("uchar"); | 1067 |
986 octave_value skip = (nargin > 3) ? args(3) : octave_value (0.0); | 1068 octave_value prec = (nargin > 2) |
987 octave_value arch = (nargin > 4) ? args(4) : octave_value ("native"); | 1069 ? args(2) : octave_value ("uchar"); |
1070 | |
1071 octave_value skip = (nargin > 3) | |
1072 ? args(3) : octave_value (0.0); | |
1073 | |
1074 octave_value arch = (nargin > 4) | |
1075 ? args(4) : octave_value ("unknown"); | |
988 | 1076 |
989 retval = do_fwrite (*os, data, prec, skip, arch); | 1077 retval = do_fwrite (*os, data, prec, skip, arch); |
990 } | 1078 } |
991 else | 1079 else |
992 gripe_invalid_file_id ("fwrite"); | 1080 gripe_invalid_file_id ("fwrite"); |