Create Subroutine in Universe - universe

I have problems in identifying the error of UniObject during execute UniCommands. I saw the answer in UniObjects for Java: How to get response String when error occurred in UniCommand.exec()
But I don't know how to create subroutine in Universe?
I saw this method CreateUniSubroutine but it only has name and # of parameters.
UniSubroutine sub = us1.CreateUniSubroutine("RUN.COMMAND", 2);
Thanks.

In UniVerse you can use a subroutine inside and outside the program.
Let me show you how you can make a simple example.
Primary File:
0001 *EXAMPLE SUBROUTINE
0002 CRT 'ENTER A NUMBER OR Q TO QUIT:'
0003 INPUT NUM
0004 BEGIN CASE
0005 CASE NUM = "Q"
0006 GOSUB ENDPRG
0007 CASE NUM > 0
0008 CALL ADD5(NUM)
0009 END CASE
0010 ENDPRG:
0011 CRT 'END OF PROGRAM'
0012 CRT
0013 END
Subroutine file:
0001 SUBROUTINE ADD5(NUMBER)
0002 NUMBER+=5
0003 CRT NUMBER
0004 RETURN
0005 END
In the primary file on the line 6 and 8 you can see the subroutines.
I hope to help ;)

I generally only do Universe from inside native Universe, but what it looks like here is that the command "CreateUniSubroutine" creates a reflection of a Universe subroutine, not a subroutine itself.
I am not sure what you are trying to do, but this appears to allow you to leverage existing Universe code and not add new logic.

To create a Subroutine in Universe.
You need to have a subroutine source file folder in your UniVerse account with file type 19. It can be local or qpoint from other UniVerse account.
Use any text editor (like notepad) to edit your subroutine source code and save into the source folder above.
TELNET to your UniVerse account and type the following to basic the subroutine.
BASIC source.folder subroutine.name
Example: If the source folder name is SOURCE and Subroutine file name is RUN.COMMAND. the command will be
BASIC SOURCE RUN.COMMAND
You may need to CATALOG the subroutine in your data account before it can call from UniObject.

Related

moving the file position back by one single character to over-write it, in fortran [duplicate]

I want to display the progress of a calculation done with a DO-loop, on the console screen. I can print out the progress variable to the terminal like this:
PROGRAM TextOverWrite_WithLoop
IMPLICIT NONE
INTEGER :: Number, Maximum = 10
DO Number = 1, MAXIMUM
WRITE(*, 100, ADVANCE='NO') REAL(Number)/REAL(Maximum)*100
100 FORMAT(TL10, F10.2)
! Calcultations on Number
END DO
END PROGRAM TextOverWrite_WithLoop
The output of the above code on the console screen is:
10.00 20.00 30.00 40.00 50.00 60.00 70.00 80.00
90.00 100.00
All on the same line, wrapped only by the console window.
The ADVANCE='No' argument and the TL10 (tab left so many spaces) edit descriptor works well to overwrite text on the same line, e.g. the output of the following code:
WRITE(*, 100, ADVANCE='NO') 100, 500
100 FORMAT(I3, 1X, TL4, I3)
Is:
500
Instead of:
100 500
Because of the TL4 edit descriptor.
From these two instances one can conclude that the WRITE statement cannot overwrite what has been written by another WRITE statement or by a previous execution of the same WRITE satement (as in a DO-loop).
Can this be overcome somehow?
I am using the FTN95 compiler on Windows 7 RC1. (The setup program of the G95 compiler bluescreens Windows 7 RC1, even thought it works fine on Vista.)
I know about the question Supressing line breaks in Fortran 95 write statements, but it does not work for me, because the answer to that question means new ouput is added to the previous output on the same line; instead of new output overwriting the previous output.
Thanks in advance.
The following should be portable across systems by use of ACHAR(13) to encode the carriage return.
character*1 creturn
! CODE::
creturn = achar(13) ! generate carriage return
! other code ...
WRITE( * , 101 , ADVANCE='NO' ) creturn , i , npoint
101 FORMAT( a , 'Point number : ',i7,' out of a total of ',i7)
There is no solution to this question within the scope of the Fortran standards. However, if your compiler understand backslash in Fortran strings (GNU Fortran does if you use the option -fbackslash), you can write
write (*,"(A)",advance="no") "foo"
call sleep(1)
write (*,"(A)",advance="no") "\b\b\bbar"
call sleep(1)
write (*,"(A)",advance="no") "\b\b\bgee"
call sleep(1)
write (*,*)
end
This uses the backslash character (\b) to erase previously written characters on that line.
NB: if your compiler does not understand advance="no", you can use related non-standard tricks, such as using the $ specifier in the format string.
The following worked perfectly using g95 fortran:
NF = NF + 1
IF(MOD(NF,5).EQ.0) WRITE(6,42,ADVANCE='NO') NF, ' PDFs'//CHAR(13)
42 FORMAT(I6,A)
gave:
5 PDFs
leaving the cursor at the #1 position on the same line. On the next update,
the 5 turned into a 10. ASCII 13 (decimal) is a carriage return.
OPEN(6,CARRIAGECONTROL ='FORTRAN')
DO I=1,5
WRITE(6,'(1H+" ",I)') I
ENDDO

reading hexadecimal data from file in fortran

In Fortran, I'm trying to read a file with data in 8-bit (hexadecimal) bytes, on Linux.
In 'hexedit' the first line looks as it should, for the tiff-file it is.
49 49 2A 00 08 00 20 00 00 00 0B 02 00 00 00 00 II*... .........
I declare a two-byte character variable (character(len=2) :: tifhead(8))
and read like this:
open(1,file=filename,access='stream')
read(1) tifhead,greyvalue
I get the first two (49 49), which print out as II in a formatted write
(format (2Z2), but not the other ones.
How can I get all these hex values out? I should see 49 49 2A 00 08 .......
.
Your read statement will simply read 2 characters for tifhead(1), the next 2 characters for tifhead(2), etc, including spaces. Therefore you end up with tifhead(1)="49", tifhead(2)=" 4", tifhead(3)="9 ", and so on. You think you read the first 2 bytes correctly only because you print the strings "49", " 4", "9 ",... one after the other, so it looks like "49 49 " in the output. The compiler has no way to know there is a single blank space separating strings and 2 spaces every four data.
To read your data properly you must use formatted reading which implies you must also declare your stream as 'formatted' in the open statement. The following example shows how this can be done:
program example
implicit none
character(len=2) :: tifhead(8), greyscale(8)
open(1, file="example.txt", access='stream', form='formatted')
read(1, "(4(a2,tr1),tr1,3(a2,tr1),a2)", advance='no') tifhead
read(1, "(tr2,4(a2,tr1),tr1,3(a2,tr1),a2)", advance='no') greyscale
close(1)
print "(a,7(a2,tr1),a2,a)", " tifhead = (", tifhead, ")"
print "(a,7(a2,tr1),a2,a)", "greyscale = (", greyscale, ")"
end program example
Perhaps some explanation is needed: a2,tr1 means read a string of 2 characters, then advance the reading pointer once (this skips the space between your hexadecimal "numbers" - actually, they are treated as just strings). 4(a2,tr1) means do that 4 times. This reads the first 4 bytes plus one space. Now, there is one more space before the next data to be read so we add tr1 to skip it, and our format is 4(a2,tr1),tr1 so far; then we read 3 more bytes with 3(a2,tr1), then the last byte alone with just a2 (not skipping the space after it). So the format string is (4(a2,tr1),tr1,3(a2,tr1),a2), which will read the first 8 bytes correctly, leaving the reading pointer right after the 8th byte. Note that advance='no' is necessary, otherwise Fortran will assume carriage return and will skip the rest of the data in the same record (line).
Now, to read the next 8 bytes we use the same format, except we add tr2 in the beginning to skip the two blank spaces. I added formatted printing in the program to check if data were read correctly. Running the program gives:
tifhead = (49 49 2A 00 08 00 20 00)
greyscale = (00 00 0B 02 00 00 00 00)
which verifies data were read correctly.
Last but not least, I would recommend to avoid old-fashion Fortran used in your code and the example above. This means use newunit to let the program find the first free unit instead of explicitly giving a unit number, have some way to check if the file you are trying to open actually exists or if you reached end of file, avoid unnamed arguments, use the dimension attribute to declare arrays, etc. None of those is strictly necessary, and it might look like unnecessary verbosity at first. But in the long run being strict (as modern Fortran encourages) will save you a lot of time while debugging larger programs. So the above example could (arguably should) be written as follows.
program example2
implicit none
integer :: unt, status
character(len=2), dimension(8) :: tifhead, greyscale
open(newunit=unt, file="example.txt", access='stream', form='formatted',&
action='read', status='old', iostat=status)
if (status /= 0) then
print "(a)","Error reading file."; stop
end if
! More sophisticated reading is probably needed to check for end of file.
read(unit=unt, fmt="(4(a2,tr1),tr1,3(a2,tr1),a2)", advance='no') tifhead
read(unit=unt, fmt="(tr2,4(a2,tr1),tr1,3(a2,tr1),a2)") greyscale
close(unit=unt)
print "(a,7(a2,tr1),a2,a)", " tifhead = (", tifhead, ")"
print "(a,7(a2,tr1),a2,a)", "greyscale = (", greyscale, ")"
end program example2
I wasn't sure if I had to massively modify my previous answers (since I believe they still serve a purpose), so I decided to just add yet another answer, hopefully the last one. I apologize for the verbosity.
The following Fortran 90 module provides a subroutine named tiff_reader_16bit which reads any TIFF data file and returns its 16-bit content in an array of integers:
module tiff_reader
implicit none
private
public :: tiff_reader_16bit
contains
subroutine tiff_reader_16bit(filename, tifdata, ndata)
character(len=*), intent(in) :: filename
integer, allocatable, intent(out) :: tifdata(:)
integer, intent(out) :: ndata
integer, parameter :: max_integers=10000000
integer :: unt, status, record_length, i, records, lsb, msb
character ch;
integer, dimension(max_integers) :: temp
ndata=0
inquire(iolength=record_length) ch
open(newunit=unt, file=filename, access='direct', form='unformatted',&
action='read', status='old', iostat=status, recl=record_length)
if (status /= 0) then
print "(3a)","Error reading file """,filename,""": File not found."; return
end if
records=1
do i=1,max_integers
read(unit=unt, rec=records, iostat=status) ch; msb=ichar(ch)
if (status /= 0) then; records=records-1; ndata=i-1; exit; end if
read(unit=unt, rec=records+1, iostat=status) ch; lsb=ichar(ch)
if (status /= 0) then; ndata=i; temp(ndata)=msb; exit; end if
temp(i)=lsb+256*msb; records=records+2
end do
close(unit=unt)
if (ndata==0) then
print "(a)","File partially read."; records=records-1; ndata=max_integers
end if
allocate(tifdata(ndata), stat=status); tifdata=temp(:ndata)
print "(2(i0,a),/)",records," records read, ",ndata," 16-bit integers returned."
end subroutine tiff_reader_16bit
end module tiff_reader
The subroutine gets the TIFF file name and returns an array of integers, together with the the total number of integers read. Internally, the subroutine uses a fixed-size array temp to temporarily store the data. To save memory, the subroutine returns an allocatable array tifdata which is part of temp, containing the data that was read only. The maximum number of data read is set in the parameter max_integers to 10 million, but can go up to huge(0) if necessary and if memory allows (in my system that's about 2.14 billion integers); it can go even further if you use "higher" kind of integers. Now, there are other ways to do that, avoiding the use of a temporary fixed-size array, but this usually comes at the cost of additional computation time, and I wouldn't go that way. More sophisticated implementations can also be done, but that would add more complexity to the code, and I don't think it fits here.
Since you need the results in the form of 16-bit data, two consecutive bytes from the file must be read, then you treat them as most significant byte first, less significant byte next. This is why the first byte read in each iteration is multiplied by 256. Note that this is NOT always the case in binary files (but it is in TIFF). Some binary files come with less significant byte first.
The subroutine is lengthier than the previous examples I posted, but that's because I added error checking, which is actually necessary. You should always check if the file exists and if end of file has been reached while reading it. Special care must also be taken for TIFF images with an "orphan" last byte (this is indeed the case for the sample file "FLAG_T24.TIF" which I found here - but not the case for the sample image "MARBLES.TIF" found at the same webpage).
An example driver program using the module above would be:
program tiff_reader_example
use tiff_reader
implicit none
integer :: n
integer, allocatable :: tifdata(:)
call tiff_reader_16bit("FLAG_T24.TIF", tifdata, n);
if (n > 0) then
print "(a,7(z4.4,tr1),z4.4,a)", "First 8 integers read: (", tifdata(:8), ")"
print "(a,7(z4.4,tr1),z4.4,a)", " Last 8 integers read: (", tifdata(n-7:), ")"
deallocate(tifdata)
end if
end program tiff_reader_example
Running the program gives:
46371 records read, 23186 16-bit integers returned.
First 8 integers read: (4949 2A00 0800 0000 0E00 FE00 0400 0100)
Last 8 integers read: (F800 F8F8 00F8 F800 F8F8 00F8 F800 00F8)
which is correct. Note that in this case the number of records (= bytes, since the file is opened as unformatted) is not double the number of integers returned. That's because this particular sample image has that "orphaned" last byte I mentioned earlier. Also note that I used another format to print 16-bit hexadecimals, including leading zeroes if needed.
There are more detailed explanations that can be given but this thread is already quite long. Feel free to ask in the comments if something is not clear.
EDIT: By default intel Fortran treats direct access records as 4-byte words, which doesn't seem quite right to me. This unusual behavior can be fixed with a compiler flag, but to avoid the lack of portability in case someone uses that specific compiler without such a flag, I slightly modified the module tiff_reader to take care of this.
Assuming your data are actually stored in binary format (in fact it seems to be a tiff image data file), my first answer is valid only if you convert data to plain text. If you prefer to read the binary file directly, the simplest way I can think of is to open the file with access='direct', and read data byte-by-byte. Each byte is read as a character, then it is converted to an integer, which I guess is more useful than a string supposed to represent a hexadecimal number.
As an example, the following program will read the header (first 8 bytes) from a tiff data file. The example reads data from a sample tiff image I found here, but it works for any binary file.
program read_tiff_data
implicit none
integer :: unt, status, i
character :: ch
integer, dimension(8) :: tifhead
open(newunit=unt, file="flag_t24.tif", access='direct', form='unformatted',
action='read', status='old', iostat=status, recl=1)
if (status /= 0) then
print "(a)","Error reading file."; stop
end if
do i=1,8
read(unit=unt, rec=i) ch; tifhead(i)=ichar(ch)
end do
close(unit=unt)
print "(a,7(i0,tr1),i0,a)", "tifhead = (", tifhead, ")"
end program read_tiff_data
The program gives this output:
tifhead = (73 73 42 0 8 0 0 0)
which is correct. You can easily expand the program to read more data from the file.
If you still need the hexadecimal representation, just replace i0 with z0 in the print statement so that it reads
print "(a,7(z0,tr1),z0,a)", "tifhead = (", tifhead, ")"
This will print the result in hexadecimals, in this case:
tifhead = (49 49 2A 0 8 0 0 0)
Here is the code that works for me. Most of this is comments. Any remarks you may have on the fortran style are most welcome. Please note that I've been familiar with fortran 77 in the past, and learned a little more modern fortran in the process of writing this piece of code
program putiff
c This program is solely intended to read the data from the .tif files made by the CCD camera
c PIXIS 1024F at beamline 1-BM at the Advanced Photon Source, so that they can be manipulated
c in fortran. It is not a general .tif reader.
c A little bit extra work may make this a reader for baseline .tif files,: some of the
c information below may help with such an implementation.
c
c The PIXIS .tif file is written in hex with the little-endian convention.
c The hex numbers have two 8-bit bytes. They are read with an integer(kind=2) declaration.
c When describing an unsigned integer these cover numbers from 0 to 65535 (or 2**16-1).
c For the PIXIS files the first two bytes are the decimal number 18761. The TIFF6 specification
c gives them as a hexadecimal number (0x4949 for a little-endian convention, 4D4D for the
c big-endian convention. The PIXIS files are little-endian.
c
c The next two bytes should be 42 decimal, and 0x2A.
c
c The next 4 bytes give the byte offset for the first image file directory (IFD) that contains
c all the other information needed to understand how the .tif files are put together.
c This number should be read together as a 4 byte integer (kind=4). These (unsigned) integers
c go from 0 to 2**32-1, or 4294967295: this is the maximum file length for a .tif file.
c For the PIXIS this number is 2097160, or 0x200008: in between are the image date for the
c PIXIS's 1024x1024 pixels, each with a two-byte gray range from 0 to 2**16-1 (or 65535 decimal).
c Therefore the PIXIS image can be read without understanding the IFD.
c
c The line right below the hex representation gives the byte order, for the
c little-endian convention indicated by two first bytes. It's 4949 for little-endian,
c in both the first and in the second byte separately. The byte order is then least importan
c part first; with two bytes together, it is byte by byte. For big-endian it is 4D4D.
c
c One way to confirm all this information is to look at the files
c with a binary editor (linux has xxd) or a binary editor (linux has hexedit).
c For the PIXIS image .tif file, the first 8 bytes in hexedit are indeed:
c 49 49 2A 00 08 00 20 00
c For a little-endian file, the bytes are read from the least important to the
c most important within the two-byte number, like this:
c 49 49 2A 00 08 00 20 00
c (34 12) (34 12) (78 56 34 12)
c Here the byte order is indicated below the numbers. The second two-byte number is
c therefore 2+2*16+0*256+0*4096, or 42. Likewise, the last 4-byte number is 0x00200008.
c
c (When the individual byte are read in binary (with 'xxd -b -l 100') this gives
c for the hexadecimals 49 49 2A 00 08 00 20 00
c binary 01001001 01001001 00101010 00000000 00001000 00000000 00100000 00000000
c in ASCII I I * . . . . . )
c After the PIXIS data comes the so-called IFD (Image File Directory).
c These contain 209 bytes. They mean something, but what I do not know. I printed them
c out one by one at the end of the program. Perhaps they are better read in two-byte units
c (right now they are read as 'integer(kind=1); integer(kind=2) may be better). But, then
c there's an odd number so you have to read one separately.
c I want to know these only because I want to use the same .tif format to
c write the results of rctopo (the max, the COM, the FWHM, and the spread).
c I know what's in the first 8 bytes, and what the data are, so I can just
c copy the ifd at the end and count on getting a good .tif file back.
c It's sort of stupid, but it should work.
use iso_fortran_env
implicit logical (A-Z)
integer :: j,jmin,jmax
integer :: k,kmin,kmax
integer :: ifdlength
data jmin,kmin/1,1,/
parameter(jmax=1024,kmax=1024)
parameter(ifdlength=209)
c 8-byte header that starts the PIXIS data file
integer (kind=2) :: tifh12,tifh34 ! each two (8-bit) bytes
integer (kind=4) :: tifh5678 ! 4 bytes
c open and read the file now that you have the correct file name in the sequence
open(newunit=unt,file='tiff_file,access='stream',iostat=ios)
if (ios /= 0) then ; call problem(ios,'read_in_samples'); end if
read (unt) tifh12,tifh34,tifh5678,greyread,ifd
close (unt)
stop
end

unclassifiable statement at (1) Fortran Error

at line 64 confirmed as the errors began
I was asked to modify a legacy code. I have found these errors when compiling error compiling picture . Does anybody know how to solve these errors? I use gfortran as my compiler.
The source code:
* Spectral analysis of measured data *
PARAMETER (ND=86400,NSP=43200,NND=86400)
COMMON /WDATA/ WD(NND),WD2(NND)
COMMON /SPEC/ WSP(NSP)
COMMON /TSDATA/ TS(ND*2),CTTS(ND*2)
COMMON /SPDATA/ P(NSP),DF
REAL MEAN
DATA DT/1.0/
DATA COTL/14400.0/
DATA COTS/600.0/
PI=3.141593
OPEN(32,FILE="Pw.txt",STATUS="OLD")
OPEN(12,FILE="output1",STATUS="UNKNOWN")
OPEN(13,FILE="output2",STATUS="UNKNOWN")
DO J=1,NND
READ(32,*)WD(J)
END DO
TOTAL=0.0
MEAN=0.0
DO J=1,NND
TOTAL=TOTAL+WD(J)
END DO
MEAN=TOTAL/FLOAT(NND)
DO J=1,NND
WD(J)=WD(J)-MEAN
END DO
Numerical filtering and Spectral analysis
M=ND/2
KF=1
TD=DT*FLOAT(ND)
DF=1./TD
DO J=1,ND
TS(J)=WD(J)
TS(J+ND)=0.
END DO
COFL=1./COTL
COFH=1./COTS
NCUTL=IFIX((COFL+DF/2.)/DF)+1
NCUTH=IFIX((COFH-DF/2.)/DF)+1
=========================
CALL CUTOFF(M,NCUTL,NCUTH)
=========================
DO J=1,ND
WD2(J)=CTTS(J)
END DO
=================================
SUBROUTINE CUTOFF(M,NCUTL,NCUTH)
=================================
PARAMETER(ND=86400,NSP=43200)
COMMON /TSDATA/ TS(ND*2),CTTS(ND*2)
COMMON /FFTDATA/ W1(ND*2)
MM=M+M
M4=MM+MM
DO J=1,MM
W1(2*J-1)=TS(J)
W1(2*J)=TS(J+MM)
END DO
===============
CALL FOUR1(MM,1)
===============
DO J=1,M
IF(J.EQ.1.AND.NCUTL.GT.0)THEN
W1(1)=0.
W1(2)=0.
ELSE IF(J.LT.NCUTL)THEN
W1(2*J-1)=0.
W1(2*J)=0.
W1(M4-2*J+3)=0.
W1(M4-2*J+4)=0.
END IF
IF(J.GT.NCUTH)THEN
W1(2*J-1)=0.
W1(2*J)=0.
W1(M4-2*J+3)=0.
W1(M4-2*J+4)=0.
END IF
IF(NCUTH.GT.M) THEN
W1(MM+1)=0.
W1(MM+2)=0.
END IF
END DO
-----------------
CALL FOUR1(MM,-1)
-----------------
DO I=1,MM
CTTS(I)=W1(2*I-1)/FLOAT(MM)
CTTS(I+MM)=W1(2*I)/FLOAT(MM)
END DO
RETURN
END
==========================
SUBROUTINE FOUR1(NN,ISIGN)
==========================
PARAMETER(ND=86400)
REAL*8 WR,WI,WPR,WPI,WTEMP,THETA
COMMON /FFTDATA/ DATA(ND*2)C
N=2*NN
J=1
DO 11 I=1,N,2
IF(J.GT.I) THEN
TEMPR=DATA(J)
TEMPI=DATA(J+1)
DATA(J)=DATA(I)
DATA(J+1)=DATA(I+1)
DATA(I)=TEMPR
DATA(I+1)=TEMPI
ENDIF
M=N/2
1 IF ((M.GE.2).AND.(J.GT.M)) THEN
J=J-M
M=M/2
GO TO 1
ENDIF
J=J+M
11 CONTINUE
MMAX=2
2 IF (N.GT.MMAX) THEN
ISTEP=2*MMAX
THETA=6.28318530717959D0/(ISIGN*MMAX)
WPR=-2.D0*DSIN(0.5D0*THETA)**2
WPI=DSIN(THETA)
WR=1.D0
WI=0.D0
DO 13 M=1,MMAX,2
DO 12 I=M,N,ISTEP
J=I+MMAX
TEMPR=SNGL(WR)*DATA(J)-SNGL(WI)*DATA(J+1)
TEMPI=SNGL(WR)*DATA(J+1)+SNGL(WI)*DATA(J)
DATA(J)=DATA(I)-TEMPR
DATA(J+1)=DATA(I+1)-TEMPI
DATA(I)=DATA(I)+TEMPR
DATA(I+1)=DATA(I+1)+TEMPI
12 CONTINUE
WTEMP=WR
WR=WR*WPR-WI*WPI+WR
WI=WI*WPR+WTEMP*WPI+WI
13 CONTINUE
MMAX=ISTEP
GO TO 2
ENDIF
RETURN
END
You haven't closed the main program with an end statement before the subroutine cutoff statement
DO J=1,ND
WD2(J)=CTTS(J)
END DO
=================================
SUBROUTINE CUTOFF(M,NCUTL,NCUTH)
=================================
This should read something like
DO J=1,ND
WD2(J)=CTTS(J)
END DO
END
SUBROUTINE CUTOFF(M,NCUTL,NCUTH)
however that doesn't really make sense. I'm sure there are more missing lines. There are also many illegal statements in the code presented mostly due to bad formatting as Vladimir F has noted.
Muhajjir,
If gfortran is anything like fortran used to be, this code will generate a
plethora of errors. One thing is for sure, there does HAVE to be and END statment at the end of the main. Otherwise, the compiler gets VERY confused. In
addition, some of your statments appear to have code to the left of column 7.
Remember, fortran dates from the days of IBM punch cards, which were HIGHLY
column oriented. A capital 'c' was typically used, in column 1, to indicate a
comment. Column 6 was reserved for continuation character, which eventually
became any character you wanted, as long as column 6 was not empty. Numbers used as labels HAD to start in column 1 and could not go past column 5 into 6, or beyond. This code looks like many of these basic rules have been violated. Check everything, straighten it all out, and everythng should be fine. If not, we can go from there.
Blake Mitchell
Retired free lance programmer
P.S. To whom it may concern,
I have read through the how to answer link and this answer appears to fit the
requirements perfectly. Why do you think it doesn't?

Retrieve all records from universe database using universe basic subroutine

I just want to know that how to retrieve all the record from universe database table using universe basic subroutine.I am new in universe.
Perhaps something like this in the unibasic
OPEN "filename" to FIL ELSE STOP 201,"cannot open filename"
EXECUTE "SELECT filename"
LOOP WHILE READNEXT ID
READ REC FROM FIL,ID ELSE REC = ""
* you now have the entire row in REC
REPEAT
Can you provide more information on what you are trying to do?
Having a subroutine call return the entire contents of a UniVerse file could return a large amount of data. I would expect you would be better off only returning a subset of the items so the calling routine can process a bit at a time.
New content based on comment:
Ok, since you mentioned a type 19 file, I assume you want to read one file from the directory/folder the file points to.
In your subroutine, you can use OPEN on the type 19 file, and use the READ command to read the file. ( Note that you can also use READU, READL, MATREAD, MATREADU, or MATREADL to get the entire file in the directory/folder, depending on if/how you want to lock the item and if you want the data in a dynamic or dimensioned array. If you only need a specific attribute you can then use READV, READVL or READVU commands.
Or, since this is a type 19 file, you can use sequential reads. Open the file with OPENSEQ and read with the READSEQ or READBLK command.
There is an article and sample code on GitHub on how to execute U2 UniVerse Subroutine.
Execute Rocket MV U2 Subroutine Asynchronously using C# (async\await) and U2 Toolkit for .NET. Convert Subroutine Multi-Value Output to Json/Objects/DataTable
These sample code are based on C# (async\await), but you can use for synchronous programming as well with little code tweak.
For article:
Go to this link :
https://github.com/RocketSoftware/multivalue-lab/tree/master/U2/Demos/U2-Toolkit/AsyncAwait/Execute_Subroutine_Async
Read ‘Subroutine-Async.docx’ file.
Sample Code for this article on GitHub
Go to this link :
https://github.com/RocketSoftware/multivalue-lab/tree/master/U2/Demos/U2-Toolkit/AsyncAwait/Execute_Subroutine_Async
OPEN '',FILENAME TO F.FILE ELSE STOP
SELECT F.FILE
LOOP
READNEXT K.FILE ELSE EXIT
READ R.FILE FROM F.FILE, K.FILE ELSE NULL
PRINT R.FILE
REPEAT
PRINT "All over Red Rover"
Filename should be in quotes, i.e "MYFILE" or 'MYFILE'
The loop will repeat till all records have been read and will then exit.

Markov C++ read from file performance

I have my 2nd assignment for C++ class which includes Markov chains. The assignment is simple but I'm not able to figure out what is the best implementation when reading chars from files.
I have a file around 300k. One of the rules for the assignment is to use Map and Vector classes. In Map (key is only string) and values will be the Vectors. When I'm reading from the file, I need to start collecting key pairs.
Example:
File1.txt
1234567890
1234567890
If Select Markov k=3, I should have in my Map:
key vector
123 -> 4
456 -> 7
789 -> 0
0/n1 -> 2
234 -> 5
567 -> 8
890 -> /n
/n -> NULL
The professor's suggestion is to read char by char, so my algorithm is the following
while (readchar != EOF){
tempstring += readchar
increment index
if index == Markovlevel {
get nextchar if =!EOF
insert nextchar value in vector
insert tempstring to Map and assign vector
unget char
}
}
I omit some other details. My main question is that if I have 318,000 characters, I will be doing the conditional every time which slows down my computer a lot (brand new MAC pro). A sample program from the professor executes this file in around 5 seconds.
I'm not able to figure out what's the best method to read fixed length words from a text file in C++.
Thanks!
Repeated file reading will slow down the program.
Read the file in blocks, of say size 1024, put into a buffer. Then process this buffer as you require for the assignment. Repeat for the next block till you are done with the file.
Have you actually timed the program? 318,000 conditionals should be a piece of cake for your brand new MAC pro. That should take only microseconds.
Premature optimization is the root of all evil. Make your program work first, optimization comes second.