Dear Madam or Mister,

My name is Manuel Montesino and I am a PhD student at the University of 
Copenhagen. I am not a programmer myself, but my thesis requires the combined 
use of R and a model. I would be very grateful if you help me with the 
following issue;

I am trying to combine a small piece of code written in Fortran 77 with R. The 
F77 code aims to select data from a library and write it into a new file (1) 
The F77 code has being compiled using gFortran and the statements declared at 
(2). Once everything is done, the dynamic library is loaded and run in R using 
the piece of code showed at (3).Then, a runtime error appears when R is asked 
to run the subroutine ("weathersel"), R closes down and the selected weather 
data file is created. Exploring the error a bit further shows that the loop 
stops at the line 1917. The subroutine works for lower number of lines and the 
subroutine works if only the last lines of the weather library are explored. 
This seems to me that there is a limit in the number of iterations that R can 
handle depending on the memory available at the computer. However, I am not 
sure. Why appears the runtime error? Is it true that there is a limitation in 
the loops that R can handle? Is it because a piece of F77!
  code?

Thank you very much in advance for your help and I hope to hear from you soon.

Best wishes,

Manuel.
________________________________

(1)    F77 code
subroutine weathersel(GRD,YR,SWJD,HRVJD)
C    ==========================================
C ----------------------------------------------------------
C ----------------------------------------------------------
C
      INTEGER :: GRID,YEAR,JDAY,A,B,C,D
      REAL :: LAT,LONG,MINT,MAXT,TEMP
      REAL :: PREC,WIND,RAD,RH,DELTA,ET
C-----------------------------------------------------------
C ** Identifying the variables
C
      A=GRD
      B=YR
      C=SWJD
      D=HRVJD
C
C-------------------------------------------------------------
C  ** Opening the files
C
      open(unit=16,file='Weather library\weather.dat',status='old')             
                Open the file with the weather data.
      open(unit=18,file='weathersel.dat')                                       
                                           Create a new file.
C
C-------------------------------------------------------------
C  ** Crating the library
C
        DO I=1,12922                                                            
                                                                 From the first 
to the last row in the weather data...
          READ(16,*)GRID,LAT,LONG,YEAR,JDAY,MINT,MAXT,                          
                  ...read the weather variables in the row...
     &             TEMP,PREC,WIND,RAD,RH,DELTA,ET
          IF(GRID.EQ.A)THEN                                                     
                                                         ...if the read 
location equals to the solicited location...
            IF(YEAR.EQ.B.AND.JDAY.GT.C.AND.JDAY.LT.D)THEN                       
                     (and other options)
             WRITE(18,*)JDAY,MAXT,MINT,TEMP,RH,PREC,WIND,RAD                    
           ...then write the data in the new file in that order...
           END IF
         END IF
        ENDDO
C
       END                                                                      
                                                                          
...end the program
________________________________

(2)    gFortran compilation:


gfortran -c -fdefault-real-8 -Wall weathrsel.for
gfortran -shared -o WEATHRSEL.DLL weathrsel.o
del *.o
pause

________________________________

(3)    R code calling the dynamic library


#Load the library
dyn.load("WEATHRSEL.DLL")

# Define the parameters
GRD<-23     # Grid
YR<-1992   # Year
SWJD<-210  # Showing julian day
HRVJD<-260 # Harvesting julian day

# Run the code
.Fortran('weathersel',GRD,YR,SWJD,HRVJD)

# Stop using the library
dyn.unload("WEATHRSEL.DLL")


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to