[TRNSYS-users] TR: File handling

Hermann Schranzhofer hermann.schranzhofer at tugraz.at
Fri Oct 7 04:57:17 PDT 2011


Dear Marcello and David,

I made some tests with your examples and unfortunately I am really surprised because I cannot find what is wrong. 

As David told us the file could be already open so I checked this with function LogicalUnitIsOpen(LU) you really get a .TRUE. Nevertheless reading from the file is not possible. Maybe the mistake is somewhere else but I did not find it until now. Maybe David has an idea.

 

@David : I found a lot of TESS Types using something like the following (this is from Type516):
    lu = jfix(getParameterValue(1)+0.1)
    imonday = jfix(getParameterValue(2)+0.1)
    If ((imonday < 1).or.(imonday > 7)) Call FoundBadParameter(2,'Fatal','The first Monday must be between 1 and 7.')

    filename = getLUFilename(lu)
    Open (unit=lu,file=filename,status='UNKNOWN',err=402)
    Rewind(lu)
! Read in the values for the step function
    Read(lu,*,err=400,end=401) adum !version number
    Read(lu,*,err=400,end=401) adum !minimum value of function

So it seems to work in a way. But it is not working in the small example by Marcello


A possibility I found in some new Types done by my colleagues is to use a label in the proforma (so the filename has to be given in Special Cards).
In the code you can get the name of the file with getLabel(I,j) and the next free Unit number with getNextAvailableLogicalUnit( ). So the part would look something like this:

filename = getLabel(IUNIT,1)
fid = getNextAvailableLogicalUnit()
open(fid,file=filename)
read(fid,*) par1
close(fid)

This is how we do it because we found that in TRNSYS17 it is no longer working like in TRNSYS16.1 (or actually we did not find a way to use it in the old way).

So again, hopefully David has a better solution. But in the meantime you can try our workaround.
 

Best regards,

Hermann.

_______________________________________________________________

DI Dr. mont. Hermann Schranzhofer
Institut fuer Waermetechnik / Institute of Thermal Engineering
TU Graz / Graz University of Technology
Inffeldgasse 25 / B, A-8010 Graz

Tel.: +43 316 873 7314
mobil: +43 664 60 873 7314
Fax : +43 316 873 7305
http://www.iwt.tugraz.at/
_______________________________________________________________



 

________________________________

Von: marcello.caciolo at aximaseitha-gdfsuez.com [mailto:marcello.caciolo at aximaseitha-gdfsuez.com] 
Gesendet: Donnerstag, 06. Oktober 2011 10:17
An: trnsys-users at cae.wisc.edu
Cc: d.bradley at tess-inc.com; hermann.schranzhofer at tugraz.at
Betreff: RE: [TRNSYS-users] TR: File handling



Dear David and Hermann,

 

As David says, I run into trouble when opening the file. I send you enclosed two tests in order to better explain my problem.

 

I created a test component (the proforma is in the corresponding directory) whit two dlls, one with the command "open" and the other without it (directories dll 1 and dll2, the corresponding codes are in the code 1 and code 2 directories).

 

If you copy the first dll and run the project "test temp" (in the TRNSYS project directory), the result file contains two lines at the end: one indicates the error code which FORTRAN generates when I try to open the file (code 30, which indicates, according to the Compaq visual FORTRAN manual, that is impossible to open the file), the second line gives the values of the three parameters read. This values correspond to the one specified in the file "fort.30", in the project directory, and not the ones contained in the "temp.in" file, which is specified for the component. However, the "filename" string returned by getLUfileName is correct, as you can see if you debug the code!!!

 

In the case of the second dll, I do not use the open command but the result is exactly the same: my component reads its parameters in the file "fort.30".

 

I really do not understand what I miss.could you help me please?

 

Best,

 

Marcello

 

 

De : trnsys-users-bounces at cae.wisc.edu [mailto:trnsys-users-bounces at cae.wisc.edu] De la part de David BRADLEY
Envoyé : mercredi 5 octobre 2011 19:20
À : Hermann Schranzhofer
Cc : trnsys-users at cae.wisc.edu
Objet : Re: [TRNSYS-users] TR: File handling

 

Marcello and Hermann,
  If you use the method below, you can sometimes run into trouble because TRNSYS already opens all of the files that are ASSIGNed to logical unit numbers. You may be able to just skip the line:

Open(unit=Fid,file=Filename) 

or, you can use the access function:

closeFileIVF(Fid)

then reopen it with 

Open(unit=Fid,file=Filename) 

Best,
 David



On 10/5/2011 08:10, Hermann Schranzhofer wrote: 

 
Dear Marcello,
 
It should work something like this:
 
Fid = getParameterValue(1)
Filename = getLUFilename(Fid)
Open(unit=Fid,file=Filename)
Read(Fid,*) value
Close(Fid)
 
Best regards,
Hermann.
 
_______________________________________________________________
 
DI Dr. mont. Hermann Schranzhofer
Institut fuer Waermetechnik / Institute of Thermal Engineering
TU Graz / Graz University of Technology 
Inffeldgasse 25 / B, A-8010 Graz 
 
Tel.: +43 316 873 7314
mobil: +43 664 60 873 7314
Fax : +43 316 873 7305
http://www.iwt.tugraz.at/
_______________________________________________________________
 
 
-----Ursprüngliche Nachricht-----
Von: trnsys-users-bounces at cae.wisc.edu [mailto:trnsys-users-bounces at cae.wisc.edu] Im Auftrag von marcello.caciolo at aximaseitha-gdfsuez.com
Gesendet: Mittwoch, 05. Oktober 2011 13:46
An: trnsys-users at cae.wisc.edu
Betreff: [TRNSYS-users] TR: File handling
 
Dear Hermann,
 
Thank you for your answer. However, the getLUfileName function gives me the name of the file as a string (which is, by the way, the correct one). But how can I use it to access this file?
 
Is there a form of the "read" instruction taking as parameter the file name instead of the unit number? If yes, could you give me an example of its use?
 
Thank you,
 
Marcello
 
-----Message d'origine-----
De : trnsys-users-bounces at cae.wisc.edu [mailto:trnsys-users-bounces at cae.wisc.edu] De la part de Hermann Schranzhofer Envoyé : mercredi 5 octobre 2011 13:38 À : trnsys-users at cae.wisc.edu Objet : Re: [TRNSYS-users] File handling
 
Dear Marcello,
 
I think you have to use the getLUfileName function. See Programmers Guide page 7-46.
 
Best regards,
Hermann Schranzhofer.
 
 
_______________________________________________________________
 
DI Dr. mont. Hermann Schranzhofer
Institut fuer Waermetechnik / Institute of Thermal Engineering TU Graz / Graz University of Technology Inffeldgasse 25 / B, A-8010 Graz
 
Tel.: +43 316 873 7314
mobil: +43 664 60 873 7314
Fax : +43 316 873 7305
http://www.iwt.tugraz.at/
_______________________________________________________________
 
 
 
 
 
________________________________
 
Von: trnsys-users-bounces at cae.wisc.edu [mailto:trnsys-users-bounces at cae.wisc.edu] Im Auftrag von marcello.caciolo at aximaseitha-gdfsuez.com
Gesendet: Mittwoch, 05. Oktober 2011 11:19
An: trnsys-users at cae.wisc.edu
Betreff: [TRNSYS-users] File handling
 
 
 
Dear TRNSYS users,
 
 
 
I would like to write a component for TRNSYS 17 which reads its parameters from an external file. In the proforma of my type, I specified a parameter "Logical unit", linked to the name of the file in the "File" tab.
 
 
 
In the FORTRAN code, at the iteration zero, my type simply use the read instruction as it follows:
 
 
 
unit_fichier_sortie = jfix(getParameterValue(4) + 0.1)
 
 
 
! Lecture de la version du fichier
 
read(unit_fichier_descriptif,*, iostat = erreur_lecture) par_1
 
 
 
However, instead of reading in the correct file, this instruction reads in a file called "fort.30" (where 30 is the logical unit number assigned by TRNSYS).
 
 
 
If I write my parameters in "fort.30", the type reads its parameters correctly. However, I would really like that it reads in the file I specify in the proforma ("exemple.in")!
 
 
 
If I debug the code, the function getLUfileName(unit_fichier_descriptif) returns the correct name of the file (example.in). 
 
 
 
Has someone experienced the same kind of problem? For information, I use Compaq Visual Fortran.
 
 
 
Thank you for your help!
 
 
 
Marcello CACIOLO
Responsable Outils et Méthodes d'Analyse Energétique ___________________________________________________ 
 
logo AximaSeitha
 
Cellule Efficacité Energétique
 
Direction Commerciale
46 Boulevard de la Prairie au Duc BP 40119 44000 Nantes Cédex 2 Tel. 02 40 41 06 57
 
 
mail: marcello.caciolo at aximaseitha-gdfsuez.com
 
 
www.aximaseitha-gdfsuez.com
 
 
 
P Pensez à l'environnement avant d'imprimer ce message
 
 
 
 
 
 
GDF SUEZ Mail Disclaimer: http://www.gdfsuez.com/disclaimer/disclaimer-fr.html
 
 
 
 
GDF SUEZ Mail Disclaimer: http://www.gdfsuez.com/disclaimer/disclaimer-fr.html
 
 
 
_______________________________________________
TRNSYS-users mailing list
TRNSYS-users at cae.wisc.edu
https://mailman.cae.wisc.edu/listinfo/trnsys-users






_______________________________________________
TRNSYS-users mailing list
TRNSYS-users at cae.wisc.edu
https://mailman.cae.wisc.edu/listinfo/trnsys-users





-- 
***************************
David BRADLEY
Principal
Thermal Energy Systems Specialists, LLC
22 North Carroll Street - suite 370
Madison, WI  53703 USA
 
P:+1.608.274.2577
F:+1.608.278.1475
d.bradley at tess-inc.com
 
http://www.tess-inc.com
http://www.trnsys.com



GDF SUEZ Mail Disclaimer: http://www.gdfsuez.com/disclaimer/disclaimer-fr.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Hermann Schranzhofer.vcf
Type: application/octet-stream
Size: 245 bytes
Desc: not available
URL: <http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/attachments/20111007/63c61109/attachment-0001.obj>


More information about the TRNSYS-users mailing list