Thread: Read a table just once

  1. #1
    Registered User
    Join Date
    Jul 2019
    Posts
    2

    Read a table just once

    Hello!

    I'm not really good at C and I struggle for quite a long time to do something. Hope someone can help.

    I am writing a user subroutine in C for a finite element (FE) solver. I would like to open a file which contains data needed in this routine. But I would like to open it just once, because the routine is called for each time step and each integration point of the meshed part of the FE problem. I though about using some kind of flag but it can't work since it is initialized at each new call of the routine.

    Does anyone have an idea on how to do that?

    Many thanks in advance,

    ManonB

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    By "user subroutine" do you mean "function"? That would be the standard term in C.

    If so, it sounds like you should open the file in the calling function. If you cannot do that, then you might need to read the data from file once and store it in say, a static local structure or even a global structure, depending on your requirements.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2019
    Posts
    2
    Thank you for answering !

    By "user subroutine" do you mean "function"?
    Yes I guess we can call it a function, it is called UMAT. The main "Programm" which solves the mechanical equations call this function at each integration point to have access to other equations to describe material behavior (these are in UMAT).
    And to define all these equations in the function UMAT, I need data from the file I want to open, but just once at the beginning of the analysis and not each time the function UMAT is called.

    currently I'm doing it like that:
    FILE* file;
    file=fopen("fort.12","r");

    but as I said, it opens then several times...




    If you cannot do that, then you might need to read the data from file once and store it in say, a static local structure or even a global structure, depending on your requirements
    I don't understand what you mean by that. Are you talking about like "static int name" or something like that ? Could you please point me to an example ?

    many thanks,

    ManonB

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Can't you change the main program to open the file, read and store the data, and then pass it to UMAT on each call?

    Quote Originally Posted by manonB
    Are you talking about like "static int name" or something like that ? Could you please point me to an example ?
    Yes, that is what I mean, assuming you only need an int rather than some collection of values to be stored in a struct.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 08-23-2017, 11:51 AM
  2. Replies: 1
    Last Post: 08-23-2017, 06:54 AM
  3. How do I read a CSV into a HTML Table?
    By Dragoon_42 in forum C# Programming
    Replies: 4
    Last Post: 01-30-2008, 06:15 AM
  4. Read a Dataset/Table into a container
    By anf in forum C++ Programming
    Replies: 3
    Last Post: 11-09-2006, 09:57 PM
  5. REad partition table?
    By Nutshell in forum C Programming
    Replies: 0
    Last Post: 03-29-2002, 07:57 AM

Tags for this Thread